1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
use crate::{ widget, widget::{ unit::content::{ContentBoxItemNode, ContentBoxNode}, utils::Transform, }, widget_component, }; use serde::{Deserialize, Serialize}; #[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct SwitchBoxProps { #[serde(default)] #[serde(skip_serializing_if = "Option::is_none")] pub active_index: Option<usize>, #[serde(default)] pub clipping: bool, #[serde(default)] pub transform: Transform, } implement_props_data!(SwitchBoxProps); widget_component! { pub switch_box(id, props, listed_slots) { let SwitchBoxProps { active_index, clipping, transform } = props.read_cloned_or_default(); let items = if let Some(index) = active_index { if let Some(slot) = listed_slots.into_iter().nth(index) { vec![ ContentBoxItemNode { slot, ..Default::default() } ] } else { vec![] } } else { vec![] }; widget! {{{ ContentBoxNode { id: id.to_owned(), props: props.clone(), items, clipping, transform, } }}} } }