viewport: local_viewport() opt-out of root-viewport inheritance; list_item: height/font_size builders
`Viewport::local_viewport()` resolves the child's viewport-relative (vw / vh / vmin) and fluid Lengths against the viewport's own rect instead of the root layout viewport the sub-canvas inherits since the fluid-resolution inheritance change. That inheritance is right for scroll-like clips (content renders the same size inside and outside), but it is exactly wrong for a fixed-size floating mini-UI — crustace's phone-shaped quick-settings pill pinned to a corner of a desktop-wide surface resolved its vw text and fluid stock geometry against the whole monitor, inflating the content past the pill's fixed clip and cutting off the bottom stripe. The flag pins the sub-canvas's layout viewport to its own size via the new crate-internal Canvas::set_local_layout_viewport, nested sub-canvases keep propagating the pinned value, and a unit test covers the override plus propagation. `ListItem::height( impl Into<Length> )` and `ListItem::font_size( impl Into<Length> )` mirror the Toggle / Radio height() builders: override the theme row height (floored at the label's rendered height so the text never clips) and the primary-label font size (subtitle and trailing keep their theme sizes), letting dense context menus trade the stock touch-target generosity for row density. Docs: widgets.md gains both builder sets, architecture.md documents the layout-viewport inheritance model next to the per-canvas density it parallels, the cookbook slide-in panel recipe notes when the pill needs local_viewport(), and the toggle / radio height() rustdoc demotes its private theme::HEIGHT link to a code span so cargo doc is warning-free again. CHANGELOG entries added.
This commit is contained in:
@@ -30,13 +30,17 @@ pub struct Viewport<Msg: Clone>
|
||||
/// the leading edge of the animation does not knife-cut against the layer
|
||||
/// below it.
|
||||
pub( crate ) fade_bottom: f32,
|
||||
/// Resolve the child's viewport-relative and fluid `Length`s against
|
||||
/// this viewport's own rect instead of the inherited root layout
|
||||
/// viewport. See [`Self::local_viewport`].
|
||||
pub( crate ) local_viewport: bool,
|
||||
}
|
||||
|
||||
impl<Msg: Clone> Viewport<Msg>
|
||||
{
|
||||
pub fn new( child: impl Into<Element<Msg>> ) -> Self
|
||||
{
|
||||
Self { child: Box::new( child.into() ), width: None, height: None, fade_bottom: 0.0 }
|
||||
Self { child: Box::new( child.into() ), width: None, height: None, fade_bottom: 0.0, local_viewport: false }
|
||||
}
|
||||
|
||||
/// Set a fixed viewport width in logical pixels. Mirrors
|
||||
@@ -66,6 +70,20 @@ impl<Msg: Clone> Viewport<Msg>
|
||||
self
|
||||
}
|
||||
|
||||
/// Resolve the child's viewport-relative (`vw` / `vh` / `vmin`) and
|
||||
/// fluid `Length`s against this viewport's own rect instead of the
|
||||
/// root surface the sub-canvas normally inherits. For a fixed-size
|
||||
/// floating mini-UI (e.g. a phone-shaped panel pinned to a corner of
|
||||
/// a desktop-wide surface) whose content is calibrated against the
|
||||
/// panel rect and must not scale with the host surface. Scroll-like
|
||||
/// clips should keep the default inheritance so content renders at
|
||||
/// the same size inside and outside the clip.
|
||||
pub fn local_viewport( mut self ) -> Self
|
||||
{
|
||||
self.local_viewport = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn preferred_size( &self, max_width: f32, canvas: &Canvas ) -> ( f32, f32 )
|
||||
{
|
||||
let inner_w = self.width.unwrap_or( max_width );
|
||||
@@ -83,10 +101,11 @@ impl<Msg: Clone> Viewport<Msg>
|
||||
{
|
||||
Viewport
|
||||
{
|
||||
child: Box::new( self.child.map_arc( f ) ),
|
||||
width: self.width,
|
||||
height: self.height,
|
||||
fade_bottom: self.fade_bottom,
|
||||
child: Box::new( self.child.map_arc( f ) ),
|
||||
width: self.width,
|
||||
height: self.height,
|
||||
fade_bottom: self.fade_bottom,
|
||||
local_viewport: self.local_viewport,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user