Skip to content

Commit

Permalink
add update text position toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
justDeeevin committed Mar 26, 2024
1 parent 117399f commit 286fd28
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
14 changes: 10 additions & 4 deletions src/nuhxboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub struct NuhxBoard {
pub save_style_as_window_id: Option<window::Id>,
pub save_style_as_name: String,
pub save_style_as_global: bool,
pub update_text_position: bool,
}

#[derive(Default)]
Expand Down Expand Up @@ -122,7 +123,8 @@ pub enum Message {
ChangeSaveKeyboardAsCategory(String),
ChangeSaveKeyboardAsName(String),
ChangeSaveStyleAsName(String),
ToggleSaveStyleAsGlobal
ToggleSaveStyleAsGlobal,
ToggleUpdateTextPosition,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -251,6 +253,7 @@ impl Application for NuhxBoard {
save_style_as_window_id: None,
save_style_as_name: "".into(),
save_style_as_global: false,
update_text_position: false,
},
Command::batch([
Command::perform(noop(), move |_| Message::ChangeKeyboardCategory(category)),
Expand Down Expand Up @@ -645,7 +648,7 @@ impl Application for NuhxBoard {
self.edit_mode = !self.edit_mode;
}
Message::MoveElement { index, delta } => {
self.config.elements[index].translate(delta);
self.config.elements[index].translate(delta, self.update_text_position);
}
Message::SaveKeyboard(file) => {
let path = file.unwrap_or(self.keyboards_path.clone().join(format!(
Expand Down Expand Up @@ -711,7 +714,7 @@ impl Application for NuhxBoard {
self.history_depth += 1;
match self.edit_history[self.edit_history.len() - self.history_depth] {
Change::MoveElement { index, delta } => {
self.config.elements[index].translate(-delta);
self.config.elements[index].translate(-delta, self.update_text_position);
}
}
}
Expand All @@ -721,7 +724,7 @@ impl Application for NuhxBoard {
self.history_depth -= 1;
match self.edit_history[self.edit_history.len() - self.history_depth - 1] {
Change::MoveElement { index, delta } => {
self.config.elements[index].translate(delta);
self.config.elements[index].translate(delta, self.update_text_position);
}
}
}
Expand Down Expand Up @@ -766,6 +769,9 @@ impl Application for NuhxBoard {
Message::ToggleSaveStyleAsGlobal => {
self.save_style_as_global = !self.save_style_as_global;
}
Message::ToggleUpdateTextPosition => {
self.update_text_position = !self.update_text_position;
}
}
self.canvas.clear();
Command::none()
Expand Down
18 changes: 10 additions & 8 deletions src/types/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum BoardElement {
}

impl BoardElement {
pub fn translate(&mut self, delta: geo::Coord) {
pub fn translate(&mut self, delta: geo::Coord, move_text: bool) {
match self {
BoardElement::MouseSpeedIndicator(key) => {
key.location += delta;
Expand All @@ -38,14 +38,16 @@ impl BoardElement {
for boundary in boundaries {
*boundary += delta;
}
let text_position = match self {
BoardElement::KeyboardKey(key) => &mut key.text_position,
BoardElement::MouseKey(key) => &mut key.text_position,
BoardElement::MouseScroll(key) => &mut key.text_position,
_ => return,
};
if move_text {
let text_position = match self {
BoardElement::KeyboardKey(key) => &mut key.text_position,
BoardElement::MouseKey(key) => &mut key.text_position,
BoardElement::MouseScroll(key) => &mut key.text_position,
_ => return,
};

*text_position += delta;
*text_position += delta;
}
}
}
}
Expand Down
34 changes: 33 additions & 1 deletion src/types/stylesheets.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use iced::widget::*;
use iced::{widget::*, Background, Border};

pub struct WhiteButton;

Expand Down Expand Up @@ -36,3 +36,35 @@ impl container::StyleSheet for ContextMenuBox {
}
}
}

pub struct ContextMenuCheckBox;

impl checkbox::StyleSheet for ContextMenuCheckBox {
type Style = iced::Theme;
fn active(&self, _style: &Self::Style, is_checked: bool) -> checkbox::Appearance {
checkbox::Appearance {
text_color: Some(iced::Color::BLACK),
background: Background::Color(match is_checked {
true => iced::Color::from_rgba(0.0, 0.4, 1.0, 0.5),
false => iced::Color::TRANSPARENT,
}),
border: Border {
color: iced::Color::BLACK,
width: 1.0,
radius: iced::border::Radius::default(),
},
icon_color: iced::Color::BLACK,
}
}

fn hovered(&self, style: &Self::Style, is_checked: bool) -> checkbox::Appearance {
checkbox::Appearance {
border: Border {
color: iced::Color::BLACK,
width: 2.0,
radius: iced::border::Radius::default(),
},
..self.active(style, is_checked)
}
}
}
6 changes: 6 additions & 0 deletions src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ impl NuhxBoard {

if self.edit_mode {
menu.append(&mut vec![
checkbox("Update Text Position", self.update_text_position)
.on_toggle(|_| Message::ToggleUpdateTextPosition)
.style(iced::theme::Checkbox::Custom(Box::new(
ContextMenuCheckBox {},
)))
.into(),
button("Keyboard Properties")
.on_press(Message::OpenKeyboardProperties)
.style(iced::theme::Button::Custom(Box::new(WhiteButton {})))
Expand Down

0 comments on commit 286fd28

Please sign in to comment.