Skip to main content

Layout

Struct Layout 

Source
pub struct Layout { /* private fields */ }
Expand description

Represents a new layout instance with the specified format string.

§Examples

use appcui::prelude::*;

// Absolute positioning with alignment
let layout = layout!("x:8,y:5,w:33%,h:6,p:tl");

// Anchors with short aliases
let layout = layout!("t:10,r:20,w:50,h:20");

// Aligning to parent with short alias
let layout = layout!("a:c,w:30,h:50%");

// Full anchors with short aliases
let layout = layout!("l:20,t:7,r:10,b:10");

Implementations§

Source§

impl Layout

Source

pub fn absolute(x: i32, y: i32, width: u32, height: u32) -> Self

Creates a new layout instance with absolute positioning.

In absolute positioning, the control’s position is defined by its top-left corner at coordinates (x, y), and its size is specified by width and height. The control does not automatically adjust to parent size changes and will remain at the specified fixed position.

This is the simplest and most predictable layout mode, typically used when you need full control over the element’s exact position on the screen.

§Parameters
  • x - The X coordinate of the control’s top-left corner (absolute or relative to the parent).
  • y - The Y coordinate of the control’s top-left corner.
  • width - The width of the control (in character cells).
  • height - The height of the control (in character cells).
§Examples
use appcui::prelude::*;

// Creates a control positioned at (8, 5) with a size of 33x6 characters.
let layout = Layout::absolute(8, 5, 33, 6);
Source

pub fn fill() -> Self

Creates a new layout instance that completely fills the parent container.

This layout mode uses Dock::Fill, meaning the control will occupy all available space inside its parent. It is typically used for elements like panels or views that should expand and resize automatically with the parent container.

Unlike absolute or pivot layouts, a fill layout automatically adapts when the parent size changes, ensuring the control always covers the entire area.

§Behavior
  • The control will ignore its own width and height settings.
  • It will stretch horizontally and vertically to match the parent’s size.
§Examples
use appcui::prelude::*;

// Creates a layout that occupies the entire parent container.
let layout = Layout::fill();
Source

pub fn pivot(x: i32, y: i32, width: u32, height: u32, pivot: Pivot) -> Self

Creates a new layout instance using a pivot point.

A pivot point determines how the control is positioned relative to a given reference point (x, y). Unlike absolute positioning (which always treats (x, y) as the top-left corner), a pivot allows (x, y) to represent any logical point of the control (e.g., center, bottom-right).

The pivot parameter specifies which part of the control is aligned to the (x, y) coordinates:

  • Pivot::TopLeft(x, y) will be the top-left corner of the control.
  • Pivot::TopCenter(x, y) will align with the middle of the top edge.
  • Pivot::Center(x, y) will be the center of the control.
  • Pivot::BottomRight(x, y) will be the bottom-right corner.

This is useful for positioning elements in a more natural way without manually adjusting offsets.

§Parameters
  • x - The reference X coordinate (absolute or relative to the parent).
  • y - The reference Y coordinate.
  • width - The width of the control.
  • height - The height of the control.
  • pivot - A Pivot value indicating which point of the control attaches to (x, y).
§Examples
use appcui::prelude::*;

// Create a layout for a 6x6 control, with its center positioned at (10, 10)
let layout = Layout::pivot(10, 10, 6, 6, Pivot::Center);

// Another example: align bottom-right corner at (50, 20)
let layout_br = Layout::pivot(50, 20, 12, 5, Pivot::BottomRight);
Source

pub fn aligned(align: Alignment, width: u32, height: u32) -> Self

Creates a new layout instance that positions the control using alignment relative to its parent container.

The align parameter determines which position within the parent the control will occupy. This can be one of nine predefined positions:

  • Alignment::TopLeft
  • Alignment::TopCenter
  • Alignment::TopRight
  • Alignment::CenterLeft
  • Alignment::Center
  • Alignment::CenterRight
  • Alignment::BottomLeft
  • Alignment::BottomCenter
  • Alignment::BottomRight

The control’s size is fixed using width and height. Unlike a dock or fill layout, an aligned control does not stretch; it simply places the control at the specified alignment within its parent.

§Parameters
  • align - An Alignment value specifying the position relative to the parent.
  • width - The width of the control (in character cells).
  • height - The height of the control (in character cells).
§Examples
use appcui::prelude::*;

// Creates a control aligned to the bottom-right corner of the parent with a fixed size.
let layout = Layout::aligned(Alignment::BottomRight, 20, 5);

Trait Implementations§

Source§

impl Clone for Layout

Source§

fn clone(&self) -> Layout

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Layout

Source§

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

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

impl Eq for Layout

Source§

impl PartialEq for Layout

Source§

fn eq(&self, other: &Layout) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Layout

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more