Skip to content

Commit 3acc16d

Browse files
committed
parley: Implement support for TextOverflow::Clip
cc #8998
1 parent df47f0b commit 3acc16d

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

internal/core/textlayout/sharedparley.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright © SixtyFPS GmbH <[email protected]>
22
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
33

4+
use euclid::num::Zero;
45
pub use parley;
56

67
use core::pin::Pin;
@@ -11,7 +12,8 @@ use crate::{
1112
graphics::FontRequest,
1213
items::TextStrokeStyle,
1314
lengths::{
14-
LogicalLength, LogicalPoint, LogicalRect, LogicalSize, PhysicalPx, ScaleFactor, SizeLengths,
15+
LogicalBorderRadius, LogicalLength, LogicalPoint, LogicalRect, LogicalSize, PhysicalPx,
16+
ScaleFactor, SizeLengths,
1517
},
1618
textlayout::{TextHorizontalAlignment, TextOverflow, TextVerticalAlignment, TextWrap},
1719
SharedString,
@@ -458,6 +460,8 @@ pub fn draw_text(
458460

459461
let (horizontal_align, vertical_align) = text.alignment();
460462

463+
let text_overflow = text.overflow();
464+
461465
let layout = layout(
462466
text.text().as_str(),
463467
scale_factor,
@@ -469,19 +473,37 @@ pub fn draw_text(
469473
stroke: platform_stroke_brush.is_some().then_some(stroke_style),
470474
font_request,
471475
text_wrap: text.wrap(),
472-
text_overflow: text.overflow(),
476+
text_overflow,
473477
..Default::default()
474478
},
475479
);
476480

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+
}
485507
}
486508

487509
pub fn draw_text_input(

0 commit comments

Comments
 (0)