Skip to main content

WidgetBase

Struct WidgetBase 

Source
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: Insets

Space outside this widget’s bounds (read by the parent during layout).

§h_anchor: HAnchor

Horizontal anchor — how this widget positions/sizes itself horizontally.

§v_anchor: VAnchor

Vertical anchor — how this widget positions/sizes itself vertically.

§min_size: Size

Minimum size constraint (logical units). The parent will never assign a slot smaller than this in either axis.

§max_size: Size

Maximum size constraint (logical units). The parent will never assign a slot larger than this in either axis.

§enforce_integer_bounds: bool

Per-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

Source

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.

Source

pub fn with_margin(self, m: Insets) -> Self

Source

pub fn with_h_anchor(self, h: HAnchor) -> Self

Source

pub fn with_v_anchor(self, v: VAnchor) -> Self

Source

pub fn with_min_size(self, s: Size) -> Self

Source

pub fn with_max_size(self, s: Size) -> Self

Source

pub fn clamp_size(&self, proposed: Size) -> Size

Clamp proposed to [min_size, max_size].

Source

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

Source§

fn clone(&self) -> WidgetBase

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WidgetBase

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WidgetBase

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for WidgetBase

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.