Text Selection completely rewritten
This commit is contained in:
parent
e8bf0fc099
commit
190dcef155
2 changed files with 321 additions and 307 deletions
|
|
@ -46,7 +46,7 @@ impl text_input::Renderer for Renderer {
|
|||
text_bounds,
|
||||
value,
|
||||
size,
|
||||
state.cursor_position(value).position(),
|
||||
state.cursor.draw_position(value),
|
||||
font,
|
||||
);
|
||||
|
||||
|
|
@ -111,17 +111,16 @@ 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,
|
||||
cursor.position(),
|
||||
state.cursor.draw_position(value),
|
||||
font,
|
||||
);
|
||||
|
||||
let selection = match cursor {
|
||||
/*let selection = match cursor {
|
||||
text_input::Cursor::Index(_) => Primitive::None,
|
||||
text_input::Cursor::Selection { .. } => {
|
||||
let (cursor_left_offset, _) =
|
||||
|
|
@ -130,7 +129,7 @@ impl text_input::Renderer for Renderer {
|
|||
text_bounds,
|
||||
value,
|
||||
size,
|
||||
cursor.left(),
|
||||
state.cursor.left(),
|
||||
font,
|
||||
);
|
||||
let (cursor_right_offset, _) =
|
||||
|
|
@ -139,7 +138,7 @@ impl text_input::Renderer for Renderer {
|
|||
text_bounds,
|
||||
value,
|
||||
size,
|
||||
cursor.right(),
|
||||
state.cursor.right(),
|
||||
font,
|
||||
);
|
||||
let width = cursor_right_offset - cursor_left_offset;
|
||||
|
|
@ -158,6 +157,42 @@ impl text_input::Renderer for Renderer {
|
|||
border_color: Color::TRANSPARENT,
|
||||
}
|
||||
}
|
||||
};*/
|
||||
|
||||
let selection = if !state.cursor.is_selection() {
|
||||
Primitive::None
|
||||
} else {
|
||||
let (cursor_left_offset, _) = measure_cursor_and_scroll_offset(
|
||||
self,
|
||||
text_bounds,
|
||||
value,
|
||||
size,
|
||||
state.cursor.left(),
|
||||
font,
|
||||
);
|
||||
let (cursor_right_offset, _) = measure_cursor_and_scroll_offset(
|
||||
self,
|
||||
text_bounds,
|
||||
value,
|
||||
size,
|
||||
state.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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue