render: sub-canvases inherit the root layout viewport for fluid resolution
Content drawn inside a scroll rendered smaller than identical content outside it: the scroll viewport draws its child into a sub-canvas sized to the viewport rect, and Canvas::viewport_layout / viewport_logical — the viewports that geom_px and font_px resolve fluid Lengths against — returned the canvas's own size. Inside a 312 px sub-canvas on a 360 px surface every fluid geometry (icon sizes, row heights, paddings) and font size resolved against 312 instead of 360, shrinking the scroll content by the width ratio, ~13 % in a phone-sized window with 24 px margins. First observed in Eydos Settings' Wi-Fi list, where the connected network row sits outside the scroll and the rest inside: the same full-fan signal icon measured 21x18 px outside and 18x16 px inside. Add a layout_viewport field to SoftwareCanvas and GlesCanvas, None on root canvases and set by sub_canvas to the parent's effective layout viewport, so nested sub-canvases keep propagating the root surface size. viewport_layout and viewport_logical consult the inherited value before falling back to the canvas size. Root canvases are untouched, and the GLES clip layers, which reuse sub_canvas, get the same correction.
This commit is contained in:
@@ -137,6 +137,12 @@ pub struct SoftwareCanvas
|
||||
pub font_registry: Option<Arc<FontRegistry>>,
|
||||
/// DPI scale factor applied to font sizes.
|
||||
pub dpi_scale: f32,
|
||||
/// Layout-resolution viewport inherited from the parent canvas.
|
||||
/// `None` on a root canvas (resolve against own size); sub-canvases
|
||||
/// carry the root surface size so fluid geometry and fonts resolve
|
||||
/// the same inside offscreen content (scroll viewports, clip layers)
|
||||
/// as outside it.
|
||||
pub( crate ) layout_viewport: Option<( f32, f32 )>,
|
||||
/// Global alpha multiplier for all drawing operations (0.0 =
|
||||
/// transparent, 1.0 = opaque).
|
||||
pub global_alpha: f32,
|
||||
@@ -216,13 +222,21 @@ impl Canvas
|
||||
/// ```
|
||||
pub fn viewport_logical( &self ) -> ( f32, f32 )
|
||||
{
|
||||
let ( pw, ph ) = self.size();
|
||||
let ( pw, ph ) = match self.layout_viewport()
|
||||
{
|
||||
Some( ( w, h ) ) => ( w, h ),
|
||||
None =>
|
||||
{
|
||||
let ( w, h ) = self.size();
|
||||
( w as f32, h as f32 )
|
||||
}
|
||||
};
|
||||
let scale = self.dpi_scale();
|
||||
if scale > 0.0
|
||||
{
|
||||
( pw as f32 / scale, ph as f32 / scale )
|
||||
( pw / scale, ph / scale )
|
||||
} else {
|
||||
( pw as f32, ph as f32 )
|
||||
( pw, ph )
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,10 +249,21 @@ impl Canvas
|
||||
/// by `dpi_scale` at raster time, so they must NOT use this.
|
||||
pub fn viewport_layout( &self ) -> ( f32, f32 )
|
||||
{
|
||||
if let Some( v ) = self.layout_viewport() { return v; }
|
||||
let ( pw, ph ) = self.size();
|
||||
( pw as f32, ph as f32 )
|
||||
}
|
||||
|
||||
/// Inherited layout viewport, when this is a sub-canvas.
|
||||
fn layout_viewport( &self ) -> Option<( f32, f32 )>
|
||||
{
|
||||
match self
|
||||
{
|
||||
Canvas::Software( c ) => c.layout_viewport,
|
||||
Canvas::Gles( c ) => c.layout_viewport,
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolve a stock-widget **geometry** design pixel (height, padding,
|
||||
/// box size, gap…) through the process-wide [`crate::WidgetScaling`]
|
||||
/// mode, into a concrete physical-pixel value for the layout tree.
|
||||
|
||||
Reference in New Issue
Block a user