Skip to content

Commit 1085982

Browse files
committed
Be more explit about the width passed to layout being physical
1 parent 4a48609 commit 1085982

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

internal/core/textlayout/sharedparley.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use parley;
66
use crate::{
77
graphics::FontRequest,
88
items::TextStrokeStyle,
9-
lengths::LogicalLength,
9+
lengths::{LogicalLength, PhysicalPx},
1010
textlayout::{TextHorizontalAlignment, TextOverflow, TextVerticalAlignment, TextWrap},
1111
};
1212
use i_slint_common::sharedfontique;
@@ -30,7 +30,7 @@ pub struct Brush {
3030
}
3131

3232
pub struct LayoutOptions {
33-
pub max_width: Option<LogicalLength>,
33+
pub max_physical_width: Option<euclid::Length<crate::Coord, PhysicalPx>>,
3434
pub max_height: Option<LogicalLength>,
3535
pub horizontal_align: TextHorizontalAlignment,
3636
pub vertical_align: TextVerticalAlignment,
@@ -44,7 +44,7 @@ pub struct LayoutOptions {
4444
impl Default for LayoutOptions {
4545
fn default() -> Self {
4646
Self {
47-
max_width: None,
47+
max_physical_width: None,
4848
max_height: None,
4949
horizontal_align: TextHorizontalAlignment::Left,
5050
vertical_align: TextVerticalAlignment::Top,
@@ -109,10 +109,12 @@ pub fn layout(text: &str, scale_factor: f32, options: LayoutOptions) -> Layout {
109109
);
110110
}
111111

112+
let max_physical_width = options.max_physical_width.map(|max_width| max_width.get());
113+
112114
let mut layout: parley::Layout<Brush> = builder.build(text);
113-
layout.break_all_lines(options.max_width.map(|max_width| max_width.get() * scale_factor));
115+
layout.break_all_lines(max_physical_width);
114116
layout.align(
115-
options.max_width.map(|max_width| max_width.get() * scale_factor),
117+
max_physical_width,
116118
match options.horizontal_align {
117119
TextHorizontalAlignment::Left => parley::Alignment::Left,
118120
TextHorizontalAlignment::Center => parley::Alignment::Middle,

internal/renderers/femtovg/itemrenderer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
452452
horizontal_align,
453453
vertical_align,
454454
max_height: Some(max_height),
455-
max_width: Some(max_width),
455+
max_physical_width: Some(max_width * self.scale_factor),
456456
stroke: stroke_paint.is_some().then_some(stroke_style),
457457
font_request: Some(font_request),
458458
text_wrap: text.wrap(),
@@ -514,7 +514,7 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
514514
&text,
515515
self.scale_factor.get(),
516516
sharedparley::LayoutOptions {
517-
max_width: Some(width),
517+
max_physical_width: Some(width * self.scale_factor),
518518
max_height: Some(height),
519519
vertical_align: text_input.vertical_alignment(),
520520
selection: Some(min_select..max_select),

internal/renderers/femtovg/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl<B: GraphicsBackend> RendererSealed for FemtoVGRenderer<B> {
292292
text,
293293
scale_factor.get(),
294294
sharedparley::LayoutOptions {
295-
max_width,
295+
max_physical_width: max_width.map(|max_width| max_width * scale_factor),
296296
text_wrap,
297297
font_request: Some(font_request),
298298
..Default::default()
@@ -338,7 +338,7 @@ impl<B: GraphicsBackend> RendererSealed for FemtoVGRenderer<B> {
338338
scale_factor.get(),
339339
sharedparley::LayoutOptions {
340340
font_request: Some(font_request),
341-
max_width: Some(width),
341+
max_physical_width: Some(width * scale_factor),
342342
max_height: Some(height),
343343
vertical_align: text_input.vertical_alignment(),
344344

@@ -379,7 +379,7 @@ impl<B: GraphicsBackend> RendererSealed for FemtoVGRenderer<B> {
379379
&text,
380380
scale_factor.get(),
381381
sharedparley::LayoutOptions {
382-
max_width: Some(width),
382+
max_physical_width: Some(width * scale_factor),
383383
max_height: Some(height),
384384
..Default::default()
385385
},

0 commit comments

Comments
 (0)