move layout update into InputState
This commit is contained in:
@@ -89,9 +89,6 @@ impl Element for Input {
|
||||
};
|
||||
|
||||
self.input.update(cx, |input, _cx| {
|
||||
let dirty = input.layout_data.dirty
|
||||
|| input.layout_data.wrap_width != wrap_width
|
||||
|| input.layout_data.text_style != layout_state.text_style;
|
||||
let layout_data = InputLayoutData {
|
||||
text_style: layout_state.text_style.clone(),
|
||||
line_height,
|
||||
@@ -99,12 +96,7 @@ impl Element for Input {
|
||||
available_size: bounds.size,
|
||||
dirty: false,
|
||||
};
|
||||
input.layout_data = layout_data;
|
||||
if dirty {
|
||||
input.logical_lines =
|
||||
InputState::build_logical_lines(input.content(), window, &input.layout_data);
|
||||
input.scroll_to_cursor();
|
||||
}
|
||||
input.apply_layout_update(layout_data, window);
|
||||
});
|
||||
|
||||
let hitbox = self.interactivity.prepaint(
|
||||
|
||||
@@ -1047,10 +1047,22 @@ impl InputState {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn apply_layout_update(&mut self, layout_data: InputLayoutData, window: &Window) {
|
||||
let dirty = self.layout_data.dirty
|
||||
|| self.layout_data.wrap_width != layout_data.wrap_width
|
||||
|| self.layout_data.text_style != layout_data.text_style;
|
||||
self.layout_data = layout_data;
|
||||
if dirty {
|
||||
self.logical_lines =
|
||||
InputState::build_logical_lines(&self.content, window, &self.layout_data);
|
||||
self.scroll_to_cursor();
|
||||
}
|
||||
}
|
||||
|
||||
/// Called internally during window prepaint to layout the content into logical lines based on viewport bounds wrapping.
|
||||
pub(super) fn build_logical_lines(
|
||||
content: &str,
|
||||
window: &mut Window,
|
||||
window: &Window,
|
||||
layout_data: &InputLayoutData,
|
||||
) -> Vec<InputLogicalLine> {
|
||||
let text_style = &layout_data.text_style;
|
||||
|
||||
Reference in New Issue
Block a user