Struct View

Source
pub struct View<A> {
    pub key: Option<String>,
    pub kind: ViewKind<A>,
    pub children: Vec<View<A>>,
    pub flex_item: FlexItemStyle,
    pub size_hint: LayoutSizeHint,
}
Expand description

Declarative view tree node (widget, component, or empty).

A view is transient input to reconciliation. Keys are optional owned UTF-8 strings, children preserve insertion order, and flex/size metadata matters only when interpreted by a compatible parent widget. Cloning shares widget and component implementations through Rc but recursively clones metadata and the child vector.

§Examples

use ailloli_ui_runtime::component::{View, ViewKind};
let view = View::<()>::empty().key("root");
assert_eq!(view.key_ref(), Some("root"));
assert!(matches!(view.kind, ViewKind::Empty));

Fields§

§key: Option<String>

Stable identity for reconciliation (see IntoViewKeyExt::key).

§kind: ViewKind<A>

Empty, widget, or component payload.

§children: Vec<View<A>>

Direct declarative children in reconciliation and paint order.

§flex_item: FlexItemStyle

Flex item style when this view is a direct child of Row / Column.

§size_hint: LayoutSizeHint

Declarative width/height from builders; used by parent flex for main-axis Fill.

Implementations§

Source§

impl<A> View<A>

Provides the operations defined for View<A>.

Source

pub fn key_ref(&self) -> Option<&str>

Borrows the reconciliation key as &str without allocating.

None means positional reconciliation; Some("") is a real empty key.

§Examples
use ailloli_ui_runtime::component::View;
let view = View::<()>::empty().key(String::from("item-1"));
assert_eq!(view.key_ref(), Some("item-1"));
Source§

impl<A> View<A>

Provides the operations defined for View<A>.

Source

pub fn empty() -> Self

Creates an unkeyed empty view with no children and default metadata.

§Examples
use ailloli_ui_runtime::component::{View, ViewKind};
let view = View::<()>::empty();
assert!(view.key.is_none() && view.children.is_empty());
assert!(matches!(view.kind, ViewKind::Empty));
Source

pub fn leaf(widget: impl Widget<A> + 'static) -> Self

Wraps a widget in an unkeyed view with no declarative children.

§Examples
use ailloli_ui_core::{Constraints, Rect};
use ailloli_ui_runtime::component::{View, Widget};
use ailloli_ui_runtime::layout::{LayoutChild, LayoutCtx, LayoutEngine, LayoutResult};
use ailloli_ui_runtime::scene::PaintCtx;
struct W;
impl Widget<()> for W {
    fn debug_name(&self) -> &'static str { "W" }
    fn layout(&self, _: &mut LayoutEngine<'_, ()>, _: &mut LayoutCtx<'_>, _: &mut [LayoutChild], _: Constraints) -> LayoutResult { LayoutResult::empty() }
    fn paint(&self, _: &mut PaintCtx<'_>, _: Rect, _: &LayoutResult) {}
}
assert!(View::leaf(W).children.is_empty());
Source

pub fn node(widget: impl Widget<A> + 'static, children: Vec<View<A>>) -> Self

Wraps a widget and an ordered vector of declarative children.

Children are moved without cloning; no parent pointer or key validation occurs until reconciliation.

§Examples
use ailloli_ui_core::{Constraints, Rect};
use ailloli_ui_runtime::component::{View, Widget};
use ailloli_ui_runtime::layout::{LayoutChild, LayoutCtx, LayoutEngine, LayoutResult};
use ailloli_ui_runtime::scene::PaintCtx;
struct W;
impl Widget<()> for W {
    fn debug_name(&self) -> &'static str { "W" }
    fn layout(&self, _: &mut LayoutEngine<'_, ()>, _: &mut LayoutCtx<'_>, _: &mut [LayoutChild], _: Constraints) -> LayoutResult { LayoutResult::empty() }
    fn paint(&self, _: &mut PaintCtx<'_>, _: Rect, _: &LayoutResult) {}
}
let view = View::node(W, vec![View::empty(), View::empty()]);
assert_eq!(view.children.len(), 2);
Source

pub fn component(component: impl ComponentNode<A> + 'static) -> Self

Wraps a stateful component in an unkeyed view.

Declarative children start empty because reconciliation obtains the component’s single built child by invoking ComponentNode::build.

§Examples
use ailloli_ui_runtime::component::{ComponentNode, Context, View, ViewKind};
struct C;
impl ComponentNode<()> for C {
    fn build(&self, _: &mut Context<()>) -> View<()> { View::empty() }
}
let view = View::component(C);
assert!(matches!(view.kind, ViewKind::Component(_)));
Source

pub fn with_flex_item(self, flex_item: FlexItemStyle) -> Self

Replaces this view’s flex-child metadata and returns it.

Values have already been normalized only if the caller used FlexItemStyle builders; direct public-field values are preserved.

§Examples
use ailloli_ui_core::style::FlexItemStyle;
use ailloli_ui_runtime::component::View;
let view = View::<()>::empty().with_flex_item(FlexItemStyle::new().flex_grow(2.0));
assert_eq!(view.flex_item.flex_grow, 2.0);
Source

pub fn with_size_hint(self, size_hint: LayoutSizeHint) -> Self

Replaces declarative width/height hints and returns this view.

§Examples
use ailloli_ui_core::style::{LayoutSizeHint, Length};
use ailloli_ui_runtime::component::View;
let hint = LayoutSizeHint::new(Length::Fill, Length::px(20.0));
let view = View::<()>::empty().with_size_hint(hint);
assert_eq!(view.size_hint, hint);
Source

pub fn key(self, key: impl Into<String>) -> Self

Sets an owned reconciliation key and returns this view.

Empty and duplicate strings are accepted here. Reconciliation compares exact UTF-8 text and has compatibility behavior for duplicates.

§Examples
use ailloli_ui_runtime::component::View;
assert_eq!(View::<()>::empty().key("toolbar").key_ref(), Some("toolbar"));
Source

pub fn from<V: IntoView<A>>(value: V) -> Self

Wraps a declarative builder into a View (same as IntoView::into_view).

§Examples
use ailloli_ui_runtime::component::View;
let view = View::<()>::from(View::empty().key("root"));
assert_eq!(view.key_ref(), Some("root"));

Trait Implementations§

Source§

impl<A> Clone for View<A>

Implements the Clone contract for View<A>.

Source§

fn clone(&self) -> Self

Produces the clone required by the standard cloning contract.

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<A> IntoView<A> for View<A>

Implements the IntoView<A> contract for View<A>.

Source§

fn into_view(self) -> View<A>

Converts this value into its retained view representation.

Auto Trait Implementations§

§

impl<A> Freeze for View<A>

§

impl<A> !RefUnwindSafe for View<A>

§

impl<A> !Send for View<A>

§

impl<A> !Sync for View<A>

§

impl<A> Unpin for View<A>

§

impl<A> !UnwindSafe for View<A>

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<A> IntoClickAction<A> for A
where A: Clone + 'static,

Source§

fn into_click_action(self) -> ClickAction<A>

Implements the into_click_action helper used by this module.

Source§

impl<T, A> IntoViewKeyExt<A> for T
where T: IntoView<A>,

Source§

fn key(self, key: impl Into<String>) -> View<A>

Converts self, assigns the owned key, and returns the view. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Props for T
where T: Clone + 'static,