Move the text_input_byte_offset_for_position from the FontMetrics to the Window

In preparation of having mutiple-lines TextInput, we will need to give more
data to this function so it no longer belong in FontMetrics

Also remove the unused FontMetric::line_height()
This commit is contained in:
Olivier Goffart 2021-08-31 11:55:32 +02:00 committed by Olivier Goffart
parent e1be599bc0
commit c1fc242a9a
7 changed files with 77 additions and 64 deletions

View file

@ -302,16 +302,9 @@ impl Item for TextInput {
if !self.enabled() {
return InputEventResult::EventIgnored;
}
let text = self.text();
let font_metrics = window.font_metrics(
&self.cached_rendering_data,
&|| self.unresolved_font_request(),
Self::FIELD_OFFSETS.text.apply_pin(self),
);
match event {
MouseEvent::MousePressed { pos } => {
let clicked_offset = font_metrics.text_offset_for_x_position(&text, pos.x) as i32;
let clicked_offset = window.text_input_byte_offset_for_position(self, pos) as i32;
self.as_ref().pressed.set(true);
self.as_ref().anchor_position.set(clicked_offset);
self.as_ref().cursor_position.set(clicked_offset);
@ -325,7 +318,7 @@ impl Item for TextInput {
MouseEvent::MouseMoved { pos } => {
if self.as_ref().pressed.get() {
let clicked_offset =
font_metrics.text_offset_for_x_position(&text, pos.x) as i32;
window.text_input_byte_offset_for_position(self, pos) as i32;
self.as_ref().cursor_position.set(clicked_offset);
}
}