Skip to content

Commit

Permalink
fix: autosize surface layout
Browse files Browse the repository at this point in the history
Autosized surfaces perform the layout step to get the size and then again when building the interface, but sometimes the calculated size is not enough space when used as a bound, so we need to add a tiny amount to the calculated size. This also makes the event loop timeout duration configurable. Viewport physical size is calculated directly from the logical size now as well in iced-sctk to avoid inconsistencies that resulted from recalculating the logical size after using it to calculate the physical size.
  • Loading branch information
wash2 committed Feb 14, 2024
1 parent 831fa81 commit c65715c
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 104 deletions.
17 changes: 17 additions & 0 deletions graphics/src/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ pub struct Viewport {
}

impl Viewport {
/// Creates a new [`Viewport`] with the given logical dimensions and scale factor
pub fn with_logical_size(size: Size<f32>, scale_factor: f64) -> Viewport {
let physical_size = Size::new(
(size.width as f64 * scale_factor).ceil() as u32,
(size.height as f64 * scale_factor).ceil() as u32,
);
Viewport {
physical_size,
logical_size: size,
scale_factor,
projection: Transformation::orthographic(
physical_size.width,
physical_size.height,
),
}
}

/// Creates a new [`Viewport`] with the given physical dimensions and scale
/// factor.
pub fn with_physical_size(size: Size<u32>, scale_factor: f64) -> Viewport {
Expand Down
Loading

0 comments on commit c65715c

Please sign in to comment.