Implement state-less scrolling in TextInput

This commit is contained in:
Héctor Ramón Jiménez 2019-11-05 03:33:24 +01:00
parent 470266f540
commit a2161586da

View file

@ -87,10 +87,7 @@ impl text_input::Renderer for Renderer {
vertical_alignment: VerticalAlignment::Center,
};
let content = Primitive::Clip {
bounds: text_bounds,
offset: Vector::new(0, 0),
content: Box::new(if text_input.state.is_focused {
let (contents_primitive, offset) = if text_input.state.is_focused {
use wgpu_glyph::{GlyphCruncher, Scale, Section};
let text_before_cursor = &text_input
@ -110,8 +107,8 @@ impl text_input::Renderer for Renderer {
.map(|bounds| bounds.width().round())
.unwrap_or(0.0);
let spaces_at_the_end = text_before_cursor.len()
- text_before_cursor.trim_end().len();
let spaces_at_the_end =
text_before_cursor.len() - text_before_cursor.trim_end().len();
if spaces_at_the_end > 0 {
let space_width = {
@ -140,17 +137,29 @@ impl text_input::Renderer for Renderer {
border_radius: 0,
};
(
Primitive::Group {
primitives: vec![value, cursor],
}
},
Vector::new(
((text_value_width + 5.0) - text_bounds.width).max(0.0)
as u32,
0,
),
)
} else {
value
}),
(value, Vector::new(0, 0))
};
let contents = Primitive::Clip {
bounds: text_bounds,
offset,
content: Box::new(contents_primitive),
};
(
Primitive::Group {
primitives: vec![border, input, content],
primitives: vec![border, input, contents],
},
if is_mouse_over {
MouseCursor::Text