Skip to content

Commit

Permalink
feat: line/pen highlighter refactor + extra features
Browse files Browse the repository at this point in the history
  • Loading branch information
DerpDays committed Jun 2, 2024
1 parent a34772b commit 7202726
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 113 deletions.
3 changes: 3 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ output-filename = "/tmp/test-%Y-%m-%d_%H:%M:%S.png"
save-after-copy = false
# Hide toolbars by default
default-hide-toolbars = false
# Whether to set block or line/pen as the default highlighter, other mode is accessible using CTRL.
default-block-highlight = true

# Font to use for text annotations
[font]
family = "Roboto"
Expand Down
4 changes: 4 additions & 0 deletions src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ pub struct CommandLine {
/// Font style to use for text annotations
#[arg(long)]
pub font_style: Option<String>,

/// Change the default highlighter to the line/pen highlighter.
#[arg(long)]
pub default_line_highlight: bool,
}

#[derive(Debug, Clone, Copy, Default, ValueEnum)]
Expand Down
13 changes: 13 additions & 0 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct Configuration {
color_palette: ColorPalette,
default_hide_toolbars: bool,
font: FontConfiguration,
default_block_highlight: bool,
}

#[derive(Default)]
Expand Down Expand Up @@ -170,6 +171,9 @@ impl Configuration {
if let Some(v) = general.default_hide_toolbars {
self.default_hide_toolbars = v;
}
if let Some(v) = general.default_block_highlight {
self.default_block_highlight = v;
}
}
fn merge(&mut self, file: Option<ConfigurationFile>, command_line: CommandLine) {
// input_filename is required and needs to be overwritten
Expand Down Expand Up @@ -219,6 +223,10 @@ impl Configuration {
if let Some(v) = command_line.font_style {
self.font.style = Some(v);
}

if command_line.default_line_highlight {
self.default_block_highlight = !command_line.default_line_highlight;
}
}

pub fn early_exit(&self) -> bool {
Expand Down Expand Up @@ -261,6 +269,9 @@ impl Configuration {
self.default_hide_toolbars
}

pub fn default_block_highlight(&self) -> bool {
self.default_block_highlight
}
pub fn font(&self) -> &FontConfiguration {
&self.font
}
Expand All @@ -280,6 +291,7 @@ impl Default for Configuration {
color_palette: ColorPalette::default(),
default_hide_toolbars: false,
font: FontConfiguration::default(),
default_block_highlight: true,
}
}
}
Expand Down Expand Up @@ -323,6 +335,7 @@ struct ConfiguationFileGeneral {
output_filename: Option<String>,
save_after_copy: Option<bool>,
default_hide_toolbars: Option<bool>,
default_block_highlight: Option<bool>,
}

#[derive(Deserialize)]
Expand Down
11 changes: 11 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ impl Component for App {
glib::Propagation::Stop
},

connect_key_released[sketch_board_sender] => move |controller, key, code, modifier | {
if let Some(im_context) = controller.im_context() {
im_context.focus_in();
if !im_context.filter_keypress(controller.current_event().unwrap()) {
sketch_board_sender.emit(SketchBoardInput::new_key_release_event(KeyEventMsg::new(key, code, modifier)));
}
} else {
sketch_board_sender.emit(SketchBoardInput::new_key_release_event(KeyEventMsg::new(key, code, modifier)));
}
},

#[wrap(Some)]
set_im_context = &gtk::IMMulticontext {
connect_commit[sketch_board_sender] => move |_cx, txt| {
Expand Down
5 changes: 5 additions & 0 deletions src/sketch_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub enum SketchBoardOutput {
pub enum InputEvent {
Mouse(MouseEventMsg),
Key(KeyEventMsg),
KeyRelease(KeyEventMsg),
Text(TextEventMsg),
}

Expand Down Expand Up @@ -105,6 +106,10 @@ impl SketchBoardInput {
SketchBoardInput::InputEvent(InputEvent::Key(event))
}

pub fn new_key_release_event(event: KeyEventMsg) -> SketchBoardInput {
SketchBoardInput::InputEvent(InputEvent::KeyRelease(event))
}

pub fn new_text_event(event: TextEventMsg) -> SketchBoardInput {
SketchBoardInput::InputEvent(InputEvent::Text(event))
}
Expand Down
4 changes: 4 additions & 0 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,8 @@ impl Size {
Size::Large => 45.0 * size_factor,
}
}

pub fn default_block_highlight(self) -> bool {
APP_CONFIG.read().default_block_highlight()
}
}
Loading

0 comments on commit 7202726

Please sign in to comment.