Skip to main content

Margin

Struct Margin 

Source
pub struct Margin {
    pub left: f32,
    pub right: f32,
    pub top: f32,
    pub bottom: f32,
    /* private fields */
}
Expand description

Maintains a margin around a singular child.

Using a negative margin will expand the minimum size but not restrict the space of the child. This can be used to make the child occupy more space than it would otherwise.

The space is restricted by the margin before alignment is applied, so if the child’s alignment is Center the child will be centered based on the restricted space, resulting in an unexpected shift if top != bottom or left != right. All other alignments are unaffected.

Maintains the margin as a minimum size even if child is None, however, once a child is assigned, it cannot be removed. If you intend to use the margin as a minimum size, you should use Minimum with no child instead.

Fields§

§left: f32

The left margin amount.

§right: f32

The right margin amount.

§top: f32

The top margin amount.

§bottom: f32

The bottom margin amount.

Implementations§

Source§

impl Margin

Source

pub fn new() -> Self

Creates a new Margin with no child, no margin, and (Begin, Begin) alignment.

Source

pub fn with_child(self, index: NodeIndex) -> Self

Bind a child node.

§Panics

If there is already a child node.

Source

pub fn with_align(self, align: (Alignment, Alignment)) -> Self

Set the horizontal and vertical alignment.

Source

pub fn with_margins(self, left: f32, right: f32, top: f32, bottom: f32) -> Self

Set the left, right, top, and bottom margins.

Source

pub fn with_equal_x(self, lr: f32) -> Self

Set the left and right margins to the same value.

Source

pub fn with_equal_y(self, tb: f32) -> Self

Set the top and bottom margins to the same value.

Source

pub fn with_equal_xy(self, lr: f32, tb: f32) -> Self

Set both the left and right margins, and both the top and bottom margins.

Source

pub fn with_equal(self, margin: f32) -> Self

Set the left, right, top, and bottom margins to the same value.

Source

pub fn with_left(self, left: f32) -> Self

Set the left margin.

Source

pub fn with_right(self, right: f32) -> Self

Set the right margin.

Source

pub fn with_top(self, top: f32) -> Self

Set the top margin.

Source

pub fn with_bottom(self, bottom: f32) -> Self

Set the bottom margin.

Source

pub fn get_child(&self) -> Option<NodeIndex>

Get the tree index of the child.

Trait Implementations§

Source§

impl Default for Margin

Source§

fn default() -> Self

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

impl UiNode for Margin

Source§

fn get_align(&self) -> (Alignment, Alignment)

Get the alignment of the node.
Source§

fn get_align_mut(&mut self) -> (&mut Alignment, &mut Alignment)

Get a mutable reference to the alignment of the node.
Source§

fn calculate_min_size(&self, tree: &UiTree) -> (f32, f32)

Calculate the minimum size of the node. Read more
Source§

fn calculate_rects(&self, cache: &NodeCache, tree: &UiTree) -> Vec<Rect>

Recalculate the position and size of child nodes, in the same order and count as get_visible_children. Read more
Source§

fn get_children(&self) -> Vec<NodeIndex>

Get all children of the node, if applicable.
Source§

fn get_visible_children(&self) -> Vec<NodeIndex>

Get all visible children of the node, if applicable. Read more

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> 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, 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.