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

@ -18,7 +18,7 @@ You should use the `sixtyfps` crate instead.
use image::GenericImageView;
use sixtyfps_corelib::component::ComponentRc;
use sixtyfps_corelib::graphics::{FontMetrics, Image, Size};
use sixtyfps_corelib::graphics::{FontMetrics, Image, Point, Size};
use sixtyfps_corelib::slice::Slice;
use sixtyfps_corelib::window::{PlatformWindow, Window};
use sixtyfps_corelib::{ImageInner, Property};
@ -149,6 +149,14 @@ impl PlatformWindow for TestingWindow {
Box::new(TestingFontMetrics::default())
}
fn text_input_byte_offset_for_position(
&self,
_text_input: Pin<&sixtyfps_corelib::items::TextInput>,
_pos: Point,
) -> usize {
0
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
@ -161,14 +169,6 @@ impl FontMetrics for TestingFontMetrics {
fn text_size(&self, text: &str, _max_width: Option<f32>) -> Size {
Size::new(text.len() as f32 * 10., 10.)
}
fn line_height(&self) -> f32 {
10.
}
fn text_offset_for_x_position(&self, _text: &str, _x: f32) -> usize {
0
}
}
/// Initialize the testing backend.