@@ -199,8 +199,6 @@ fn draw_glyphs<R: femtovg::Renderer + TextureImporter>(
199199 layout : & sharedparley:: Layout ,
200200 canvas : & mut Canvas < R > ,
201201 paint : & femtovg:: Paint ,
202- selection_foreground_color : Color ,
203- selection_background_color : Color ,
204202) {
205203 for line in layout. lines ( ) {
206204 for item in line. items ( ) {
@@ -213,30 +211,6 @@ fn draw_glyphs<R: femtovg::Renderer + TextureImporter>(
213211
214212 let brush = glyph_run. style ( ) . brush ;
215213
216- let mut paint = paint. clone ( ) ;
217- if brush. is_selected {
218- if let Some ( start) = glyph_run. positioned_glyphs ( ) . next ( ) {
219- let selection_rect = PhysicalRect :: new (
220- PhysicalPoint :: new (
221- start. x ,
222- start. y + layout. y_offset - run. font_size ( ) ,
223- ) ,
224- PhysicalSize :: new (
225- glyph_run. advance ( ) ,
226- run. font_size ( ) + run. metrics ( ) . descent ,
227- ) ,
228- ) ;
229- canvas. fill_path (
230- & rect_to_path ( selection_rect) ,
231- & femtovg:: Paint :: color ( to_femtovg_color (
232- & selection_background_color,
233- ) ) ,
234- ) ;
235- }
236-
237- paint. set_color ( to_femtovg_color ( & selection_foreground_color) ) ;
238- }
239-
240214 let glyphs = glyph_run. positioned_glyphs ( ) . map ( |glyph : parley:: Glyph | {
241215 femtovg:: PositionedGlyph {
242216 x : glyph. x ,
@@ -248,15 +222,15 @@ fn draw_glyphs<R: femtovg::Renderer + TextureImporter>(
248222
249223 match brush. stroke {
250224 Some ( i_slint_core:: items:: TextStrokeStyle :: Outside ) => {
251- canvas. stroke_glyphs ( glyphs. clone ( ) , & paint) . unwrap ( ) ;
252- canvas. fill_glyphs ( glyphs, & paint) . unwrap ( ) ;
225+ canvas. stroke_glyphs ( glyphs. clone ( ) , paint) . unwrap ( ) ;
226+ canvas. fill_glyphs ( glyphs, paint) . unwrap ( ) ;
253227 }
254228 Some ( i_slint_core:: items:: TextStrokeStyle :: Center ) => {
255- canvas. fill_glyphs ( glyphs. clone ( ) , & paint) . unwrap ( ) ;
256- canvas. stroke_glyphs ( glyphs, & paint) . unwrap ( ) ;
229+ canvas. fill_glyphs ( glyphs. clone ( ) , paint) . unwrap ( ) ;
230+ canvas. stroke_glyphs ( glyphs, paint) . unwrap ( ) ;
257231 }
258232 None => {
259- canvas. fill_glyphs ( glyphs, & paint) . unwrap ( ) ;
233+ canvas. fill_glyphs ( glyphs, paint) . unwrap ( ) ;
260234 }
261235 }
262236 }
@@ -463,7 +437,7 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
463437
464438 let mut canvas = self . canvas . borrow_mut ( ) ;
465439
466- draw_glyphs ( & layout, & mut canvas, & paint, Color :: default ( ) , Color :: default ( ) ) ;
440+ draw_glyphs ( & layout, & mut canvas, & paint) ;
467441 }
468442
469443 fn draw_text_input (
@@ -517,19 +491,40 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
517491 max_physical_width : Some ( width * self . scale_factor ) ,
518492 max_height : Some ( height) ,
519493 vertical_align : text_input. vertical_alignment ( ) ,
520- selection : Some ( min_select..max_select) ,
521494 font_request : Some ( font_request) ,
522495 ..Default :: default ( )
523496 } ,
524497 ) ;
525- draw_glyphs (
526- & layout,
527- & mut canvas,
528- & paint,
529- text_input. selection_foreground_color ( ) ,
530- text_input. selection_background_color ( ) ,
498+
499+ let selection = parley:: layout:: cursor:: Selection :: new (
500+ parley:: layout:: cursor:: Cursor :: from_byte_index (
501+ & layout,
502+ min_select,
503+ Default :: default ( ) ,
504+ ) ,
505+ parley:: layout:: cursor:: Cursor :: from_byte_index (
506+ & layout,
507+ max_select,
508+ Default :: default ( ) ,
509+ ) ,
531510 ) ;
532511
512+ selection. geometry_with ( & layout, |rect, _| {
513+ let mut cursor_rect = femtovg:: Path :: new ( ) ;
514+ cursor_rect. rect (
515+ rect. min_x ( ) as _ ,
516+ rect. min_y ( ) as f32 + layout. y_offset ,
517+ rect. width ( ) as _ ,
518+ rect. height ( ) as _ ,
519+ ) ;
520+ canvas. fill_path (
521+ & cursor_rect,
522+ & femtovg:: Paint :: color ( to_femtovg_color ( & text_input. selection_background_color ( ) ) ) ,
523+ ) ;
524+ } ) ;
525+
526+ draw_glyphs ( & layout, & mut canvas, & paint) ;
527+
533528 if cursor_visible {
534529 let cursor = parley:: layout:: cursor:: Cursor :: from_byte_index (
535530 & layout,
@@ -980,7 +975,7 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
980975 let layout = sharedparley:: layout ( string, self . scale_factor . get ( ) , Default :: default ( ) ) ;
981976 let paint = femtovg:: Paint :: color ( to_femtovg_color ( & color) ) ;
982977 let mut canvas = self . canvas . borrow_mut ( ) ;
983- draw_glyphs ( & layout, & mut canvas, & paint, color , color ) ;
978+ draw_glyphs ( & layout, & mut canvas, & paint) ;
984979 }
985980
986981 fn draw_image_direct ( & mut self , image : i_slint_core:: graphics:: Image ) {
0 commit comments