Skip to content

Commit

Permalink
Added Graphs toggle Keybinding and CheckBox
Browse files Browse the repository at this point in the history
  • Loading branch information
PixelDoted committed Jun 6, 2024
1 parent 85f3ab3 commit 7d02e44
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions i18n/en/cosmic_color_picker.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ app-title = COSMIC Color Picker
## Menu
view = View
graphs = Graphs
menu-about = About
## About
Expand Down
32 changes: 29 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct ColorPicker {
show_graphs: bool,

colorspace_combo: widget::combo_box::State<ColorSpaceCombo>,
keybinds: HashMap<menu::KeyBind, Action>,
core: Core,
}

Expand All @@ -37,6 +38,7 @@ pub enum Message {
AddSpace,
RemoveSpace(usize),

ToggleGraphs,
ToggleAboutPage,
LaunchUrl(String),

Expand All @@ -46,6 +48,7 @@ pub enum Message {

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Action {
ToggleGraphs,
About,
}

Expand All @@ -54,6 +57,7 @@ impl MenuAction for Action {

fn message(&self) -> Message {
match self {
Action::ToggleGraphs => Message::ToggleGraphs,
Action::About => Message::ToggleAboutPage,
}
}
Expand All @@ -80,8 +84,11 @@ impl Application for ColorPicker {
vec![MenuBar::new(vec![menu::Tree::with_children(
menu::root(fl!("view")),
menu::items(
&HashMap::new(),
vec![menu::Item::Button(fl!("menu-about"), Action::About)],
&self.keybinds,
vec![
menu::Item::CheckBox(fl!("graphs"), self.show_graphs, Action::ToggleGraphs),
menu::Item::Button(fl!("menu-about"), Action::About),
],
),
)])
.into()]
Expand All @@ -92,10 +99,19 @@ impl Application for ColorPicker {
}

fn init(core: Core, _flags: Self::Flags) -> (Self, Command<Self::Message>) {
let mut keybinds = HashMap::new();
keybinds.insert(
menu::KeyBind {
modifiers: vec![menu::key_bind::Modifier::Ctrl],
key: Key::Character("g".into()),
},
Action::ToggleGraphs,
);

let mut app = ColorPicker {
spaces: vec![ColorSpace::default()],
last_edited: 0,
show_graphs: true,
show_graphs: false,

colorspace_combo: widget::combo_box::State::new(vec![
ColorSpaceCombo::Rgb,
Expand All @@ -104,6 +120,7 @@ impl Application for ColorPicker {
ColorSpaceCombo::Oklch,
ColorSpaceCombo::Cmyk,
]),
keybinds,
core,
};

Expand Down Expand Up @@ -137,6 +154,9 @@ impl Application for ColorPicker {
self.spaces.remove(index);
}

Message::ToggleGraphs => {
self.show_graphs = !self.show_graphs;
}
Message::ToggleAboutPage => {
self.core.window.show_context = !self.core.window.show_context;
}
Expand All @@ -151,6 +171,12 @@ impl Application for ColorPicker {
return self.copy_to_clipboard(index);
}
Message::Key(key, modifiers) => {
for (key_bind, action) in self.keybinds.iter() {
if key_bind.matches(modifiers, &key) {
return self.update(action.message());
}
}

if modifiers.control() && key == Key::Character("c".into()) {
return self.copy_to_clipboard(self.last_edited);
}
Expand Down

0 comments on commit 7d02e44

Please sign in to comment.