@@ -9,7 +9,7 @@ use std::num::NonZeroU32;
99use std:: pin:: Pin ;
1010use std:: rc:: { Rc , Weak } ;
1111
12- use i_slint_common:: sharedfontique;
12+ use i_slint_common:: sharedfontique:: { self , parley } ;
1313use i_slint_core:: api:: { RenderingNotifier , RenderingState , SetRenderingNotifierError } ;
1414use i_slint_core:: graphics:: { euclid, rendering_metrics_collector:: RenderingMetricsCollector } ;
1515use i_slint_core:: graphics:: { BorderRadius , Rgba8Pixel } ;
@@ -332,14 +332,11 @@ impl<B: GraphicsBackend> RendererSealed for FemtoVGRenderer<B> {
332332 ..Default :: default ( )
333333 } ,
334334 ) ;
335- let _offset = fonts:: get_offset ( text_input. vertical_alignment ( ) , height, & layout) ;
336-
337- // TODO
338- let result = text. len ( ) ;
335+ let offset = fonts:: get_offset ( text_input. vertical_alignment ( ) , height, & layout) ;
336+ let cursor = parley:: layout:: cursor:: Cursor :: from_point ( & layout, pos. x , pos. y - offset) ;
339337
340338 let visual_representation = text_input. visual_representation ( None ) ;
341-
342- visual_representation. map_byte_offset_from_byte_offset_in_visual_text ( result)
339+ visual_representation. map_byte_offset_from_byte_offset_in_visual_text ( cursor. index ( ) )
343340 }
344341
345342 fn text_input_cursor_rect_for_byte_offset (
@@ -366,12 +363,15 @@ impl<B: GraphicsBackend> RendererSealed for FemtoVGRenderer<B> {
366363 & text,
367364 fonts:: LayoutOptions { max_width : Some ( width) , ..Default :: default ( ) } ,
368365 ) ;
369- let cursor_position = fonts:: get_cursor_location_and_size ( & layout, byte_offset, 0.0 )
370- . map ( |location| location. 0 ) ;
371-
366+ let cursor = parley:: layout:: cursor:: Cursor :: from_byte_index (
367+ & layout,
368+ byte_offset,
369+ Default :: default ( ) ,
370+ ) ;
371+ let rect = cursor. geometry ( & layout, ( text_input. text_cursor_width ( ) * scale_factor) . get ( ) ) ;
372372 LogicalRect :: new (
373- cursor_position . unwrap_or_default ( ) / scale_factor ,
374- LogicalSize :: from_lengths ( LogicalLength :: new ( 1.0 ) , font_size ) ,
373+ LogicalPoint :: new ( rect . min_x ( ) as _ , rect . min_y ( ) as _ ) ,
374+ LogicalSize :: new ( rect . width ( ) as _ , rect . height ( ) as _ ) ,
375375 )
376376 }
377377
0 commit comments