graphix_package_gui/widgets/
space.rs1use super::{GuiW, GuiWidget, IcedElement};
2use crate::types::LengthV;
3use anyhow::{Context, Result};
4use arcstr::ArcStr;
5use graphix_compiler::expr::ExprId;
6use graphix_rt::{GXExt, GXHandle, TRef};
7use iced_widget as widget;
8use netidx::publisher::Value;
9use tokio::try_join;
10
11pub(crate) struct SpaceW<X: GXExt> {
12 width: TRef<X, LengthV>,
13 height: TRef<X, LengthV>,
14}
15
16impl<X: GXExt> SpaceW<X> {
17 pub(crate) async fn compile(gx: GXHandle<X>, source: Value) -> Result<GuiW<X>> {
18 let [(_, height), (_, width)] =
19 source.cast_to::<[(ArcStr, u64); 2]>().context("space flds")?;
20 let (height, width) = try_join! {
21 gx.compile_ref(height),
22 gx.compile_ref(width),
23 }?;
24 Ok(Box::new(Self {
25 width: TRef::new(width).context("space tref width")?,
26 height: TRef::new(height).context("space tref height")?,
27 }))
28 }
29}
30
31impl<X: GXExt> GuiWidget<X> for SpaceW<X> {
32 fn handle_update(
33 &mut self,
34 _rt: &tokio::runtime::Handle,
35 id: ExprId,
36 v: &Value,
37 ) -> Result<bool> {
38 let mut changed = false;
39 changed |= self.width.update(id, v).context("space update width")?.is_some();
40 changed |= self.height.update(id, v).context("space update height")?.is_some();
41 Ok(changed)
42 }
43
44 fn view(&self) -> IcedElement<'_> {
45 let mut s = widget::Space::new();
46 if let Some(w) = self.width.t.as_ref() {
47 s = s.width(w.0);
48 }
49 if let Some(h) = self.height.t.as_ref() {
50 s = s.height(h.0);
51 }
52 s.into()
53 }
54}