-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod checkbox; | ||
pub mod menu; | ||
pub mod text; | ||
pub mod text_editor; | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use std::{collections::HashSet, fmt, iter::FromIterator}; | ||
|
||
use crate::core::menu::Menu; | ||
// mod render; | ||
// pub use render::Renderer; | ||
// mod build; | ||
// pub use build::Builder; | ||
|
||
#[derive(Clone, Default)] | ||
pub struct Checkbox { | ||
menu: Menu, | ||
picked: HashSet<usize>, | ||
} | ||
|
||
impl<T: fmt::Display> FromIterator<T> for Checkbox { | ||
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self { | ||
Self { | ||
menu: Menu::from_iter(iter), | ||
picked: HashSet::new(), | ||
} | ||
} | ||
} | ||
|
||
impl Checkbox { | ||
pub fn items(&self) -> &Vec<String> { | ||
self.menu.items() | ||
} | ||
|
||
pub fn pick(&mut self) -> String { | ||
if !self.items().is_empty() { | ||
self.picked.insert(self.menu.position()); | ||
} | ||
self.menu.get() | ||
} | ||
|
||
pub fn backward(&mut self) -> bool { | ||
self.menu.backward() | ||
} | ||
|
||
pub fn forward(&mut self) -> bool { | ||
self.menu.forward() | ||
} | ||
|
||
pub fn move_to_head(&mut self) { | ||
self.menu.move_to_head() | ||
} | ||
|
||
pub fn move_to_tail(&mut self) { | ||
self.menu.move_to_tail() | ||
} | ||
} |
This file contains 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