pub struct WidgetBase {
pub margin: Insets,
pub h_anchor: HAnchor,
pub v_anchor: VAnchor,
pub min_size: Size,
pub max_size: Size,
pub enforce_integer_bounds: bool,
}Expand description
Stores the five universal layout properties that every widget carries.
Embed in every concrete widget and delegate the five
Widget layout-property getters to the
corresponding fields. The builder methods return Self so they can be
chained on the concrete type.
pub struct MyWidget {
bounds: Rect,
children: Vec<Box<dyn Widget>>,
base: WidgetBase,
// ...widget-specific fields...
}
impl Widget for MyWidget {
fn margin(&self) -> Insets { self.base.margin }
fn h_anchor(&self) -> HAnchor { self.base.h_anchor }
fn v_anchor(&self) -> VAnchor { self.base.v_anchor }
fn min_size(&self) -> Size { self.base.min_size }
fn max_size(&self) -> Size { self.base.max_size }
// ...
}
impl MyWidget {
pub fn with_margin(mut self, m: Insets) -> Self { self.base.margin = m; self }
pub fn with_h_anchor(mut self, h: HAnchor) -> Self { self.base.h_anchor = h; self }
pub fn with_v_anchor(mut self, v: VAnchor) -> Self { self.base.v_anchor = v; self }
pub fn with_min_size(mut self, s: Size) -> Self { self.base.min_size = s; self }
pub fn with_max_size(mut self, s: Size) -> Self { self.base.max_size = s; self }
}Fields§
§margin: InsetsSpace outside this widget’s bounds (read by the parent during layout).
h_anchor: HAnchorHorizontal anchor — how this widget positions/sizes itself horizontally.
v_anchor: VAnchorVertical anchor — how this widget positions/sizes itself vertically.
min_size: SizeMinimum size constraint (logical units). The parent will never assign a slot smaller than this in either axis.
max_size: SizeMaximum size constraint (logical units). The parent will never assign a slot larger than this in either axis.
enforce_integer_bounds: boolPer-widget override of the global pixel-alignment policy. When
true (the common default) paint_subtree rounds the child
translation to the physical pixel grid before painting, so crisp text
and strokes land on whole pixels regardless of fractional Label
heights (font_size × 1.5) accumulating through a flex stack.
Disable for widgets that deliberately want sub-pixel positioning
(smooth-scrolling markers, zoomed canvases).
Mirrors MatterCAD’s GuiWidget.EnforceIntegerBounds. Captured from
[pixel_bounds::default_enforce_integer_bounds] at construction;
later global changes do NOT retroactively alter existing widgets.
Implementations§
Source§impl WidgetBase
impl WidgetBase
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct a WidgetBase with all defaults:
zero margin, FIT anchors, ZERO min size, Size::MAX max size.
enforce_integer_bounds captures the current process-wide default.
pub fn with_margin(self, m: Insets) -> Self
pub fn with_h_anchor(self, h: HAnchor) -> Self
pub fn with_v_anchor(self, v: VAnchor) -> Self
pub fn with_min_size(self, s: Size) -> Self
pub fn with_max_size(self, s: Size) -> Self
Sourcepub fn clamp_size(&self, proposed: Size) -> Size
pub fn clamp_size(&self, proposed: Size) -> Size
Clamp proposed to [min_size, max_size].
Sourcepub fn scaled_margin(&self) -> Insets
pub fn scaled_margin(&self) -> Insets
Return margin in logical units.
Previously multiplied by device_scale
when margin handling was spread across widgets. DPI scaling is now
applied once at the App boundary via a paint-
ctx transform, so widgets work in logical units end-to-end and this
helper is a simple passthrough kept for call-site readability.
Trait Implementations§
Source§impl Clone for WidgetBase
impl Clone for WidgetBase
Source§fn clone(&self) -> WidgetBase
fn clone(&self) -> WidgetBase
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more