a2ui_tui/components/
modal.rs1use ratatui::{Frame, layout::Rect};
6
7use a2ui_base::model::component_context::ComponentContext;
8use crate::component_impl::TuiComponent;
9
10pub struct ModalComponent;
18
19impl TuiComponent for ModalComponent {
20 fn name(&self) -> &'static str {
21 "Modal"
22 }
23
24 fn render(
25 &self,
26 ctx: &ComponentContext,
27 area: Rect,
28 frame: &mut Frame,
29 render_child: &mut dyn FnMut(&str, Rect, &mut Frame, &str),
30 _measure_child: &mut dyn FnMut(&str, &str, u16) -> Option<u16>,
31 ) {
32 let comp_model = match ctx.components.get(&ctx.component_id) {
33 Some(m) => m,
34 None => return,
35 };
36
37 if let Some(trigger_id) = comp_model.get_property::<String>("trigger") {
40 if area.width > 0 && area.height > 0 {
41 render_child(&trigger_id, area, frame, "");
42 }
43 }
44 }
45
46 fn natural_height(
47 &self,
48 ctx: &ComponentContext,
49 available_width: u16,
50 measure_child: &mut dyn FnMut(&str, &str, u16) -> Option<u16>,
51 ) -> Option<u16> {
52 let comp_model = ctx.components.get(&ctx.component_id)?;
53 let child_id = comp_model.get_property::<String>("trigger")?;
56 measure_child(&child_id, "", available_width)
57 }
58}