Hello World,
i have some structs like Control .Control>Edit> enz
how do I put those in a vec!
Here is sample code that better explains what i am trying to do
pub trait ControlMarker {}
#[derive(Default)]
pub struct Control<D: ControlMarker> {
name: String,
_isFocused: bool,
_isVisible: bool,
_isEnabled: bool,
_Flags: u8,
_control: D,
}
impl<T: ControlMarker> Control<T> {
pub fn SetIsFocused(&mut self, new_focus: bool) {
self._isFocused = new_focus
}
pub fn SetIsVisible(&mut self, new_visible: bool) {
self._isVisible = new_visible
}
pub fn SetIsEnabled(&mut self, new_enabled: bool) {
self._isEnabled = new_enabled
}
pub fn IsFocused(&self) -> bool {
self._isFocused
}
pub fn IsVisible(&self) -> bool {
self._isVisible
}
pub fn IsEnabled(&self) -> bool {
self._isEnabled
}
}
////////Toggle///////
#[derive(Default)]
pub struct Toggle {toggle: bool,}
impl ControlMarker for Toggle {}
impl Control<Toggle> {
pub fn Flip(&mut self) {
self._control.toggle = !(self._control.toggle)
}
}
////////Editable///////
#[derive(Default)]
struct Editable {buffer: String,}
impl ControlMarker for Editable {}
impl Control<Editable> {
pub fn StartEdit(&self) -> () { /* Strat here */
}
}
impl ControlMarker for Box<(dyn ControlMarker + 'static)> {} // o o bad sign.....
struct Host {
widgets: Vec<Control<Box<dyn ControlMarker>>>, // here starts the confusion....
}
impl Host {
pub fn EnableAll(&mut self) {
for w in &mut self.widgets {
w.SetIsEnabled(true)
}
}
}
pub fn main() {
let mut ToggleButton = Control::<Toggle>::default();
let mut Entry = Control::<Editable>::default();
Entry.StartEdit();
ToggleButton.Flip();
ToggleButton.SetIsEnabled(false);
Entry.SetIsVisible(true);
let cnt = Host {widgets: vec![(ToggleButton), (Entry)],}; // ofcourse this doent work :(
cnt.EnableAll()
}
Regards,
Remco