ratatui_kit/components/
view.rs1use ratatui::layout::{Constraint, Direction, Flex, Margin, Offset};
2use ratatui_kit_macros::Props;
3
4use crate::{AnyElement, Component, layout_style::LayoutStyle};
5
6#[derive(Default, Props)]
7pub struct ViewProps<'a> {
8 pub flex_direction: Direction,
9 pub justify_content: Flex,
10 pub gap: i32,
11 pub margin: Margin,
12 pub offset: Offset,
13 pub width: Constraint,
14 pub height: Constraint,
15 pub children: Vec<AnyElement<'a>>,
16}
17
18pub struct View;
19
20impl<'a> From<&ViewProps<'a>> for LayoutStyle {
21 fn from(props: &ViewProps) -> Self {
22 LayoutStyle {
23 flex_direction: props.flex_direction,
24 justify_content: props.justify_content,
25 gap: props.gap,
26 margin: props.margin,
27 offset: props.offset,
28 width: props.width,
29 height: props.height,
30 }
31 }
32}
33
34impl Component for View {
35 type Props<'a> = ViewProps<'a>;
36
37 fn new(_props: &Self::Props<'_>) -> Self {
38 Self
39 }
40
41 fn update(
42 &mut self,
43 props: &mut Self::Props<'_>,
44 _hooks: crate::Hooks,
45 updater: &mut crate::ComponentUpdater,
46 ) {
47 let layout_style = LayoutStyle::from(&*props);
48 updater.set_layout_style(layout_style);
49 updater.update_children(&mut props.children, None);
50 }
51}