Skip to content

Commit

Permalink
wip: checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Feb 6, 2024
1 parent 57caab8 commit 53905f8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core.rs
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;
Expand Down
51 changes: 51 additions & 0 deletions src/core/checkbox.rs
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()
}
}
4 changes: 4 additions & 0 deletions src/core/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ impl Menu {
&self.items
}

pub fn position(&self) -> usize {
self.position
}

pub fn get(&self) -> String {
self.items
.get(self.position)
Expand Down

0 comments on commit 53905f8

Please sign in to comment.