Skip to content

Commit 5c61b06

Browse files
committed
max_physical_width -> max_width
1 parent af8d9b4 commit 5c61b06

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

internal/core/textlayout/sharedparley.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::cell::RefCell;
88
use crate::{
99
graphics::FontRequest,
1010
items::TextStrokeStyle,
11-
lengths::{LogicalLength, PhysicalPx},
11+
lengths::{LogicalLength, ScaleFactor},
1212
textlayout::{TextHorizontalAlignment, TextOverflow, TextVerticalAlignment, TextWrap},
1313
};
1414
use i_slint_common::sharedfontique;
@@ -32,7 +32,7 @@ pub struct Brush {
3232
}
3333

3434
pub struct LayoutOptions {
35-
pub max_physical_width: Option<euclid::Length<crate::Coord, PhysicalPx>>,
35+
pub max_width: Option<LogicalLength>,
3636
pub max_height: Option<LogicalLength>,
3737
pub horizontal_align: TextHorizontalAlignment,
3838
pub vertical_align: TextVerticalAlignment,
@@ -45,7 +45,7 @@ pub struct LayoutOptions {
4545
impl Default for LayoutOptions {
4646
fn default() -> Self {
4747
Self {
48-
max_physical_width: None,
48+
max_width: None,
4949
max_height: None,
5050
horizontal_align: TextHorizontalAlignment::Left,
5151
vertical_align: TextVerticalAlignment::Top,
@@ -57,8 +57,8 @@ impl Default for LayoutOptions {
5757
}
5858
}
5959

60-
pub fn layout(text: &str, scale_factor: f32, options: LayoutOptions) -> Layout {
61-
let max_physical_width = options.max_physical_width.map(|max_width| max_width.get());
60+
pub fn layout(text: &str, scale_factor: ScaleFactor, options: LayoutOptions) -> Layout {
61+
let max_physical_width = options.max_width.map(|max_width| (max_width * scale_factor).get());
6262
let pixel_size = options
6363
.font_request
6464
.as_ref()
@@ -68,7 +68,7 @@ pub fn layout(text: &str, scale_factor: f32, options: LayoutOptions) -> Layout {
6868
let mut layout = LAYOUT_CONTEXT.with_borrow_mut(move |layout_context| {
6969
let mut font_context = font_context();
7070
let mut builder =
71-
layout_context.ranged_builder(&mut font_context, text, scale_factor, true);
71+
layout_context.ranged_builder(&mut font_context, text, scale_factor.get(), true);
7272
if let Some(ref font_request) = options.font_request {
7373
if let Some(family) = &font_request.family {
7474
builder.push_default(parley::StyleProperty::FontStack(

internal/renderers/femtovg/itemrenderer.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,12 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
420420

421421
let layout = sharedparley::layout(
422422
text.text().as_str(),
423-
self.scale_factor.get(),
423+
self.scale_factor,
424424
sharedparley::LayoutOptions {
425425
horizontal_align,
426426
vertical_align,
427427
max_height: Some(max_height),
428-
max_physical_width: Some(max_width * self.scale_factor),
428+
max_width: Some(max_width),
429429
stroke: stroke_paint.is_some().then_some(stroke_style),
430430
font_request: Some(font_request),
431431
text_wrap: text.wrap(),
@@ -485,9 +485,9 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
485485

486486
let layout = sharedparley::layout(
487487
&text,
488-
self.scale_factor.get(),
488+
self.scale_factor,
489489
sharedparley::LayoutOptions {
490-
max_physical_width: Some(width * self.scale_factor),
490+
max_width: Some(width),
491491
max_height: Some(height),
492492
vertical_align: text_input.vertical_alignment(),
493493
font_request: Some(font_request),
@@ -509,15 +509,15 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
509509
);
510510

511511
selection.geometry_with(&layout, |rect, _| {
512-
let mut cursor_rect = femtovg::Path::new();
513-
cursor_rect.rect(
512+
let mut selection_path = femtovg::Path::new();
513+
selection_path.rect(
514514
rect.min_x() as _,
515515
rect.min_y() as f32 + layout.y_offset,
516516
rect.width() as _,
517517
rect.height() as _,
518518
);
519519
canvas.fill_path(
520-
&cursor_rect,
520+
&selection_path,
521521
&femtovg::Paint::color(to_femtovg_color(&text_input.selection_background_color())),
522522
);
523523
});
@@ -532,15 +532,15 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
532532
);
533533
let rect = cursor.geometry(&layout, (text_input.text_cursor_width()).get());
534534

535-
let mut cursor_rect = femtovg::Path::new();
536-
cursor_rect.rect(
535+
let mut cursor_path = femtovg::Path::new();
536+
cursor_path.rect(
537537
rect.min_x() as _,
538538
rect.min_y() as f32 + layout.y_offset,
539539
rect.width() as _,
540540
rect.height() as _,
541541
);
542542
canvas.fill_path(
543-
&cursor_rect,
543+
&cursor_path,
544544
&femtovg::Paint::color(to_femtovg_color(&visual_representation.cursor_color)),
545545
);
546546
}
@@ -971,7 +971,7 @@ impl<'a, R: femtovg::Renderer + TextureImporter> ItemRenderer for GLItemRenderer
971971
}
972972

973973
fn draw_string(&mut self, string: &str, color: Color) {
974-
let layout = sharedparley::layout(string, self.scale_factor.get(), Default::default());
974+
let layout = sharedparley::layout(string, self.scale_factor, Default::default());
975975
let paint = femtovg::Paint::color(to_femtovg_color(&color));
976976
let mut canvas = self.canvas.borrow_mut();
977977
draw_glyphs(&layout, &mut canvas, &paint);

internal/renderers/femtovg/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ impl<B: GraphicsBackend> RendererSealed for FemtoVGRenderer<B> {
290290
) -> LogicalSize {
291291
let layout = sharedparley::layout(
292292
text,
293-
scale_factor.get(),
293+
scale_factor,
294294
sharedparley::LayoutOptions {
295-
max_physical_width: max_width.map(|max_width| max_width * scale_factor),
295+
max_width,
296296
text_wrap,
297297
font_request: Some(font_request),
298298
..Default::default()
@@ -335,13 +335,12 @@ impl<B: GraphicsBackend> RendererSealed for FemtoVGRenderer<B> {
335335

336336
let layout = sharedparley::layout(
337337
&text,
338-
scale_factor.get(),
338+
scale_factor,
339339
sharedparley::LayoutOptions {
340340
font_request: Some(font_request),
341-
max_physical_width: Some(width * scale_factor),
341+
max_width: Some(width),
342342
max_height: Some(height),
343343
vertical_align: text_input.vertical_alignment(),
344-
345344
..Default::default()
346345
},
347346
);
@@ -374,9 +373,9 @@ impl<B: GraphicsBackend> RendererSealed for FemtoVGRenderer<B> {
374373

375374
let layout = sharedparley::layout(
376375
&text,
377-
scale_factor.get(),
376+
scale_factor,
378377
sharedparley::LayoutOptions {
379-
max_physical_width: Some(width * scale_factor),
378+
max_width: Some(width),
380379
max_height: Some(height),
381380
..Default::default()
382381
},

0 commit comments

Comments
 (0)