ratatui_kit/components/
adapter.rs1use crate::Component;
2use ratatui::widgets::WidgetRef;
3use ratatui_kit_macros::Props;
4use std::sync::Arc;
5
6#[derive(Props, Default)]
7pub struct AdapterProps(pub Option<Arc<dyn WidgetRef + Sync + Send + 'static>>);
8
9pub struct Adapter {
10 inner: Arc<dyn WidgetRef + Sync + Send + 'static>,
11}
12impl Component for Adapter {
13 type Props<'a> = AdapterProps;
14
15 fn new(props: &Self::Props<'_>) -> Self {
16 Self {
17 inner: props
18 .0
19 .as_ref()
20 .expect("AdapterProps must contain a WidgetRef")
21 .clone(),
22 }
23 }
24
25 fn update(
26 &mut self,
27 props: &mut Self::Props<'_>,
28 _hooks: crate::Hooks,
29 _updater: &mut crate::ComponentUpdater,
30 ) {
31 self.inner = props
32 .0
33 .as_ref()
34 .expect("AdapterProps must contain a WidgetRef")
35 .clone();
36 }
37
38 fn render_ref(&self, area: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) {
39 self.inner.render_ref(area, buf);
40 }
41}