ratatui_kit/components/
center.rs

1use crate::{AnyElement, Props, component, element, prelude::View};
2use ratatui::layout::{Constraint, Direction, Flex};
3
4#[derive(Default, Props)]
5pub struct CenterProps<'a> {
6    pub width: Constraint,
7    pub height: Constraint,
8    pub children: Vec<AnyElement<'a>>,
9}
10
11/// 居中布局组件
12#[component]
13pub fn Center<'a>(props: &mut CenterProps<'a>) -> impl Into<AnyElement<'a>> {
14    element!(
15        View(
16            justify_content:Flex::Center
17        ){
18            View(
19               height:props.height,
20               justify_content:Flex::Center,
21               flex_direction:Direction::Horizontal,
22            ){
23                View(
24                    width:props.width,
25                    justify_content:Flex::Center,
26                    flex_direction:Direction::Vertical,
27                ){
28                    #(props.children.iter_mut())
29                }
30            }
31        }
32    )
33}