diff options
| author | 2020-02-22 21:33:45 +0100 | |
|---|---|---|
| committer | 2020-02-22 21:33:45 +0100 | |
| commit | b2344a852e98af734e9d8f7fe3d493f9e82ca80c (patch) | |
| tree | 3a585c0684c088049eacc2817dcad8d16b55cca6 /wgpu/src/renderer/widget | |
| parent | d6c2b1121c9592826e1cc25eeecbf3fa8d982ee8 (diff) | |
| download | iced-b2344a852e98af734e9d8f7fe3d493f9e82ca80c.tar.gz iced-b2344a852e98af734e9d8f7fe3d493f9e82ca80c.tar.bz2 iced-b2344a852e98af734e9d8f7fe3d493f9e82ca80c.zip  | |
 inital patch by Finnerale
Diffstat (limited to '')
| -rw-r--r-- | wgpu/src/renderer/widget/text_input.rs | 46 | 
1 files changed, 43 insertions, 3 deletions
diff --git a/wgpu/src/renderer/widget/text_input.rs b/wgpu/src/renderer/widget/text_input.rs index e2a1b3a9..72da85f4 100644 --- a/wgpu/src/renderer/widget/text_input.rs +++ b/wgpu/src/renderer/widget/text_input.rs @@ -46,7 +46,7 @@ impl text_input::Renderer for Renderer {                  text_bounds,                  value,                  size, -                state.cursor_position(value), +                state.cursor_position(value).position(),                  font,              ); @@ -111,15 +111,55 @@ impl text_input::Renderer for Renderer {          };          let (contents_primitive, offset) = if state.is_focused() { +            let cursor = state.cursor_position(value);              let (text_value_width, offset) = measure_cursor_and_scroll_offset(                  self,                  text_bounds,                  value,                  size, -                state.cursor_position(value), +                cursor.position(),                  font,              ); +            let selection = match cursor { +                text_input::Cursor::Index(_) => Primitive::None, +                text_input::Cursor::Selection { .. } => { +                    let (cursor_left_offset, _) = +                        measure_cursor_and_scroll_offset( +                            self, +                            text_bounds, +                            value, +                            size, +                            cursor.left(), +                            font, +                        ); +                    let (cursor_right_offset, _) = +                        measure_cursor_and_scroll_offset( +                            self, +                            text_bounds, +                            value, +                            size, +                            cursor.right(), +                            font, +                        ); +                    let width = cursor_right_offset - cursor_left_offset; +                    Primitive::Quad { +                        bounds: Rectangle { +                            x: text_bounds.x + cursor_left_offset, +                            y: text_bounds.y, +                            width, +                            height: text_bounds.height, +                        }, +                        background: Background::Color( +                            style_sheet.selection_color(), +                        ), +                        border_radius: 0, +                        border_width: 0, +                        border_color: Color::TRANSPARENT, +                    } +                } +            }; +              let cursor = Primitive::Quad {                  bounds: Rectangle {                      x: text_bounds.x + text_value_width, @@ -135,7 +175,7 @@ impl text_input::Renderer for Renderer {              (                  Primitive::Group { -                    primitives: vec![text_value, cursor], +                    primitives: vec![selection, text_value, cursor],                  },                  Vector::new(offset as u32, 0),              )  | 
