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: FlexItemStyleFlex item style when this view is a direct child of Row / Column.
size_hint: LayoutSizeHintDeclarative 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>.
impl<A> View<A>
Provides the operations defined for View<A>.
Sourcepub fn key_ref(&self) -> Option<&str>
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>.
impl<A> View<A>
Provides the operations defined for View<A>.
Sourcepub fn empty() -> Self
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));Sourcepub fn leaf(widget: impl Widget<A> + 'static) -> Self
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());Sourcepub fn node(widget: impl Widget<A> + 'static, children: Vec<View<A>>) -> Self
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);Sourcepub fn component(component: impl ComponentNode<A> + 'static) -> Self
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(_)));Sourcepub fn with_flex_item(self, flex_item: FlexItemStyle) -> Self
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);Sourcepub fn with_size_hint(self, size_hint: LayoutSizeHint) -> Self
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);Sourcepub fn key(self, key: impl Into<String>) -> Self
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"));Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
impl<A> IntoClickAction<A> for Awhere
A: Clone + 'static,
Source§fn into_click_action(self) -> ClickAction<A>
fn into_click_action(self) -> ClickAction<A>
Implements the into_click_action helper used by this module.