Last active
July 9, 2022 23:56
-
-
Save dymk/955907ea1d4e65cedf8ce3d3fa913b2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use tui::widgets::TextInputState; | |
| tui::interactive_form_state!(struct Foo { | |
| bar: TextInputState = "baz", | |
| quux: TextInputState = "smaz", | |
| whup: TextInputState | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use tui::widgets::TextInputState; | |
| struct Foo { | |
| focused_state_idx: Option<usize>, | |
| bar: TextInputState, | |
| quux: TextInputState, | |
| whup: TextInputState, | |
| } | |
| impl Foo { | |
| pub fn input_states_len() -> usize { | |
| <[()]>::len(&[(), (), ()]) | |
| } | |
| #[allow(unused_variables)] | |
| pub fn input_state_at( | |
| &self, | |
| idx: usize, | |
| ) -> Option<&dyn crate::widgets::InteractiveWidgetState> { | |
| if 0 == idx { | |
| Some(&self.bar) | |
| } else { | |
| if (0 + 1) == idx { | |
| Some(&self.quux) | |
| } else { | |
| if ((0 + 1) + 1) == idx { | |
| Some(&self.whup) | |
| } else { | |
| None | |
| } | |
| } | |
| } | |
| } | |
| } | |
| impl std::default::Default for Foo { | |
| fn default() -> Foo { | |
| #[allow(unused_imports)] | |
| Foo { | |
| focused_state_idx: None, | |
| bar: "baz".into(), | |
| quux: "smaz".into(), | |
| whup: Default::default(), | |
| } | |
| } | |
| } | |
| impl crate::interactive_form::InteractiveFormHooks for Foo { | |
| fn focused_state_idx(&self) -> Option<usize> { | |
| self.focused_state_idx | |
| } | |
| fn set_focused_state_idx(&mut self, idx: Option<usize>) { | |
| self.focused_state_idx = idx; | |
| } | |
| fn input_states_len(&self) -> usize { | |
| Foo::input_states_len() | |
| } | |
| #[allow(unused_variables)] | |
| fn input_state_at_mut( | |
| &mut self, | |
| idx: usize, | |
| ) -> Option<&mut dyn crate::widgets::InteractiveWidgetState> { | |
| if 0 == idx { | |
| Some(&mut self.bar) | |
| } else { | |
| if (0 + 1) == idx { | |
| Some(&mut self.quux) | |
| } else { | |
| if ((0 + 1) + 1) == idx { | |
| Some(&mut self.whup) | |
| } else { | |
| None | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment