@@ -18,7 +18,7 @@ use i_slint_core::item_rendering::{
1818} ;
1919use i_slint_core:: items:: {
2020 self , Clip , FillRule , ImageRendering , ImageTiling , ItemRc , Layer , Opacity , RenderingResult ,
21- TextHorizontalAlignment , TextStrokeStyle , TextVerticalAlignment ,
21+ TextStrokeStyle ,
2222} ;
2323use i_slint_core:: lengths:: {
2424 LogicalBorderRadius , LogicalLength , LogicalPoint , LogicalRect , LogicalSize , LogicalVector ,
@@ -264,18 +264,6 @@ fn draw_glyphs<R: femtovg::Renderer + TextureImporter>(
264264 }
265265}
266266
267- fn get_offset (
268- vertical_align : TextVerticalAlignment ,
269- max_height : PhysicalLength ,
270- layout : & parley:: Layout < sharedfontique:: Brush > ,
271- ) -> f32 {
272- match vertical_align {
273- TextVerticalAlignment :: Top => 0.0 ,
274- TextVerticalAlignment :: Center => ( max_height. get ( ) - layout. height ( ) ) / 2.0 ,
275- TextVerticalAlignment :: Bottom => max_height. get ( ) - layout. height ( ) ,
276- }
277- }
278-
279267impl < ' a , R : femtovg:: Renderer + TextureImporter > ItemRenderer for GLItemRenderer < ' a , R > {
280268 fn draw_rectangle (
281269 & mut self ,
@@ -407,7 +395,7 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
407395 fn draw_text (
408396 & mut self ,
409397 text : Pin < & dyn RenderText > ,
410- _self_rc : & ItemRc ,
398+ self_rc : & ItemRc ,
411399 size : LogicalSize ,
412400 _cache : & CachedRenderingData ,
413401 ) {
@@ -425,12 +413,12 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
425413 let ( horizontal_align, vertical_align) = text. alignment ( ) ;
426414 let color = text. color ( ) ;
427415 // TODO
428- let _wrap = text. wrap ( ) ;
429- // TODO
430416 let _overflow = text. overflow ( ) ;
431417 // TODO
432418 let _letter_spacing = text. letter_spacing ( ) ;
433419
420+ let font_request = text. font_request ( self_rc) ;
421+
434422 let text_path = rect_to_path ( ( size * self . scale_factor ) . into ( ) ) ;
435423 let paint = match self . brush_to_paint ( color, & text_path) {
436424 Some ( paint) => paint,
@@ -462,25 +450,29 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
462450
463451 let layout = fonts:: layout (
464452 text. text ( ) . as_str ( ) ,
465- Some ( max_width) ,
466- horizontal_align,
467- stroke_paint. is_some ( ) . then_some ( stroke_style) . map ( |style| match style {
468- TextStrokeStyle :: Outside => sharedfontique:: BrushTextStrokeStyle :: Outside ,
469- TextStrokeStyle :: Center => sharedfontique:: BrushTextStrokeStyle :: Center ,
470- } ) ,
471- None ,
453+ fonts:: LayoutOptions {
454+ horizontal_align,
455+ max_width : Some ( max_width) ,
456+ stroke : stroke_paint. is_some ( ) . then_some ( stroke_style) . map ( |style| match style {
457+ TextStrokeStyle :: Outside => sharedfontique:: BrushTextStrokeStyle :: Outside ,
458+ TextStrokeStyle :: Center => sharedfontique:: BrushTextStrokeStyle :: Center ,
459+ } ) ,
460+ font_request : Some ( font_request) ,
461+ text_wrap : text. wrap ( ) ,
462+ ..Default :: default ( )
463+ } ,
472464 ) ;
473465
474466 let mut canvas = self . canvas . borrow_mut ( ) ;
475- let offset = get_offset ( vertical_align, max_height, & layout) ;
467+ let offset = fonts :: get_offset ( vertical_align, max_height, & layout) ;
476468
477469 draw_glyphs ( & layout, & mut canvas, & paint, offset, Color :: default ( ) , Color :: default ( ) ) ;
478470 }
479471
480472 fn draw_text_input (
481473 & mut self ,
482474 text_input : Pin < & items:: TextInput > ,
483- _self_rc : & ItemRc ,
475+ self_rc : & ItemRc ,
484476 size : LogicalSize ,
485477 ) {
486478 let width = size. width_length ( ) * self . scale_factor ;
@@ -493,6 +485,8 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
493485 return ;
494486 }
495487
488+ let font_request = text_input. font_request ( self_rc) ;
489+
496490 let visual_representation = text_input. visual_representation ( None ) ;
497491
498492 let paint = match self . brush_to_paint (
@@ -521,12 +515,14 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
521515
522516 let layout = fonts:: layout (
523517 & text,
524- Some ( width) ,
525- TextHorizontalAlignment :: Left ,
526- None ,
527- Some ( min_select..max_select) ,
518+ fonts:: LayoutOptions {
519+ max_width : Some ( width) ,
520+ selection : Some ( min_select..max_select) ,
521+ font_request : Some ( font_request) ,
522+ ..Default :: default ( )
523+ } ,
528524 ) ;
529- let offset = get_offset ( text_input. vertical_alignment ( ) , height, & layout) ;
525+ let offset = fonts :: get_offset ( text_input. vertical_alignment ( ) , height, & layout) ;
530526 draw_glyphs (
531527 & layout,
532528 & mut canvas,
@@ -979,7 +975,7 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
979975 }
980976
981977 fn draw_string ( & mut self , string : & str , color : Color ) {
982- let layout = fonts:: layout ( string, None , TextHorizontalAlignment :: Left , None , None ) ;
978+ let layout = fonts:: layout ( string, Default :: default ( ) ) ;
983979 let paint = femtovg:: Paint :: color ( to_femtovg_color ( & color) ) ;
984980 let mut canvas = self . canvas . borrow_mut ( ) ;
985981 draw_glyphs ( & layout, & mut canvas, & paint, 0.0 , color, color) ;
0 commit comments