diff options
author | 2023-02-02 02:02:41 +0100 | |
---|---|---|
committer | 2023-02-24 13:22:58 +0100 | |
commit | 0a324f0aebdee06c9cce8ef107b44b847dace05b (patch) | |
tree | 58f06cb5294793bb8ef779f97ebea9e2fcd07326 /wgpu/src/text.rs | |
parent | c8e8b1a7ba47ab13cef2dc7f300fbfcefe1e8a48 (diff) | |
download | iced-0a324f0aebdee06c9cce8ef107b44b847dace05b.tar.gz iced-0a324f0aebdee06c9cce8ef107b44b847dace05b.tar.bz2 iced-0a324f0aebdee06c9cce8ef107b44b847dace05b.zip |
Implement `hit_test` for `text::Pipeline` in `iced_wgpu`
Diffstat (limited to 'wgpu/src/text.rs')
-rw-r--r-- | wgpu/src/text.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 026a6d27..41787136 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -286,14 +286,26 @@ impl Pipeline { pub fn hit_test( &self, - _content: &str, - _size: f32, - _font: iced_native::Font, - _bounds: iced_native::Size, - _point: iced_native::Point, + content: &str, + size: f32, + font: iced_native::Font, + bounds: iced_native::Size, + point: iced_native::Point, _nearest_only: bool, ) -> Option<Hit> { - None + let mut measurement_cache = self.measurement_cache.borrow_mut(); + + let (_, paragraph) = measurement_cache.allocate(Key { + content, + size: size, + font, + bounds, + color: Color::BLACK, + }); + + let cursor = paragraph.hit(point.x as i32, point.y as i32)?; + + Some(Hit::CharOffset(cursor.index)) } pub fn trim_measurement_cache(&mut self) { |