1
1
// Copyright © SixtyFPS GmbH <[email protected] >
2
2
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
3
4
+ use euclid:: num:: Zero ;
4
5
pub use parley;
5
6
6
7
use core:: pin:: Pin ;
@@ -11,7 +12,8 @@ use crate::{
11
12
graphics:: FontRequest ,
12
13
items:: TextStrokeStyle ,
13
14
lengths:: {
14
- LogicalLength , LogicalPoint , LogicalRect , LogicalSize , PhysicalPx , ScaleFactor , SizeLengths ,
15
+ LogicalBorderRadius , LogicalLength , LogicalPoint , LogicalRect , LogicalSize , PhysicalPx ,
16
+ ScaleFactor , SizeLengths ,
15
17
} ,
16
18
textlayout:: { TextHorizontalAlignment , TextOverflow , TextVerticalAlignment , TextWrap } ,
17
19
SharedString ,
@@ -458,6 +460,8 @@ pub fn draw_text(
458
460
459
461
let ( horizontal_align, vertical_align) = text. alignment ( ) ;
460
462
463
+ let text_overflow = text. overflow ( ) ;
464
+
461
465
let layout = layout (
462
466
text. text ( ) . as_str ( ) ,
463
467
scale_factor,
@@ -469,19 +473,37 @@ pub fn draw_text(
469
473
stroke : platform_stroke_brush. is_some ( ) . then_some ( stroke_style) ,
470
474
font_request,
471
475
text_wrap : text. wrap ( ) ,
472
- text_overflow : text . overflow ( ) ,
476
+ text_overflow,
473
477
..Default :: default ( )
474
478
} ,
475
479
) ;
476
480
477
- layout. draw (
478
- item_renderer,
479
- platform_fill_brush,
480
- platform_stroke_brush,
481
- & mut |item_renderer, font, font_size, brush, glyphs_it| {
482
- item_renderer. draw_glyph_run ( font, font_size, brush, layout. y_offset , glyphs_it) ;
483
- } ,
484
- ) ;
481
+ let render = if text_overflow == TextOverflow :: Clip {
482
+ item_renderer. save_state ( ) ;
483
+
484
+ item_renderer. combine_clip (
485
+ LogicalRect :: new ( LogicalPoint :: default ( ) , size) ,
486
+ LogicalBorderRadius :: zero ( ) ,
487
+ LogicalLength :: zero ( ) ,
488
+ )
489
+ } else {
490
+ true
491
+ } ;
492
+
493
+ if render {
494
+ layout. draw (
495
+ item_renderer,
496
+ platform_fill_brush,
497
+ platform_stroke_brush,
498
+ & mut |item_renderer, font, font_size, brush, glyphs_it| {
499
+ item_renderer. draw_glyph_run ( font, font_size, brush, layout. y_offset , glyphs_it) ;
500
+ } ,
501
+ ) ;
502
+ }
503
+
504
+ if text_overflow == TextOverflow :: Clip {
505
+ item_renderer. restore_state ( ) ;
506
+ }
485
507
}
486
508
487
509
pub fn draw_text_input (
0 commit comments