Skip to content

Commit

Permalink
Merge pull request #140 from schaumtier/main
Browse files Browse the repository at this point in the history
option to specify the "corner roundness"
  • Loading branch information
gabm authored Dec 20, 2024
2 parents a6e195b + fba26a1 commit 891214b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ All configuration is done either at the config file in `XDG_CONFIG_DIR/.config/s
fullscreen = true
# Exit directly after copy/save action
early-exit = true
# Draw corners of rectangles round if the value is greater than 0 (0 disables rounded corners)
corner-roundness = 12
# Select the tool on startup [possible values: pointer, crop, line, arrow, rectangle, text, marker, blur, brush]
initial-tool = "brush"
# Configure the command to be called on copy, for example `wl-copy`
Expand Down Expand Up @@ -115,6 +117,8 @@ Options:
Filename to use for saving action. Omit to disable saving to file. Might contain format specifiers: <https://docs.rs/chrono/latest/chrono/format/strftime/index.html>
--early-exit
Exit directly after copy/save action
--corner-roundness <ROUNDNESS_FACTOR>
Draw corners of rectangles round if the value is greater than 0 (0 disables rounded corners)
--initial-tool <TOOL>
Select the tool on startup [aliases: init-tool] [possible values: pointer, crop, line, arrow, rectangle, text, marker, blur, brush]
--copy-command <COPY_COMMAND>
Expand Down
5 changes: 5 additions & 0 deletions src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ pub struct CommandLine {
#[arg(long)]
pub early_exit: bool,

/// Draw corners of rectangles round if the value is greater than 0
/// (Defaults to 12) (0 disables rounded corners)
#[arg(long)]
pub corner_roundness: Option<f32>,

/// Select the tool on startup
#[arg(long, value_name = "TOOL", visible_alias = "init-tool")]
pub initial_tool: Option<Tools>,
Expand Down
13 changes: 13 additions & 0 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct Configuration {
output_filename: Option<String>,
fullscreen: bool,
early_exit: bool,
corner_roundness: f32,
initial_tool: Tools,
copy_command: Option<String>,
annotation_size_factor: f32,
Expand Down Expand Up @@ -158,6 +159,9 @@ impl Configuration {
if let Some(v) = general.early_exit {
self.early_exit = v;
}
if let Some(v) = general.corner_roundness {
self.corner_roundness = v;
}
if let Some(v) = general.initial_tool {
self.initial_tool = v;
}
Expand Down Expand Up @@ -207,6 +211,9 @@ impl Configuration {
if command_line.early_exit {
self.early_exit = command_line.early_exit;
}
if let Some(v) = command_line.corner_roundness {
self.corner_roundness = v;
}
if command_line.default_hide_toolbars {
self.default_hide_toolbars = command_line.default_hide_toolbars;
}
Expand Down Expand Up @@ -244,6 +251,10 @@ impl Configuration {
self.early_exit
}

pub fn corner_roundness(&self) -> f32 {
self.corner_roundness
}

pub fn initial_tool(&self) -> Tools {
self.initial_tool
}
Expand Down Expand Up @@ -298,6 +309,7 @@ impl Default for Configuration {
output_filename: None,
fullscreen: false,
early_exit: false,
corner_roundness: 12.0,
initial_tool: Tools::Pointer,
copy_command: None,
annotation_size_factor: 1.0,
Expand Down Expand Up @@ -344,6 +356,7 @@ struct FontFile {
struct ConfigurationFileGeneral {
fullscreen: Option<bool>,
early_exit: Option<bool>,
corner_roundness: Option<f32>,
initial_tool: Option<Tools>,
copy_command: Option<String>,
annotation_size_factor: Option<f32>,
Expand Down
8 changes: 0 additions & 8 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,4 @@ impl Size {
Size::Large => 45.0 * size_factor,
}
}

pub fn to_corner_radius(self) -> f32 {
match self {
Size::Small => 12.0,
Size::Medium => 12.0,
Size::Large => 12.0,
}
}
}
5 changes: 3 additions & 2 deletions src/tools/blur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use femtovg::{imgref::Img, Color, ImageFilter, ImageFlags, ImageId, Paint, Path}
use relm4::gtk::gdk::Key;

use crate::{
configuration::APP_CONFIG,
math::{self, Vec2D},
sketch_board::{MouseEventMsg, MouseEventType},
style::{Size, Style},
Expand Down Expand Up @@ -84,7 +85,7 @@ impl Drawable for Blur {
self.top_left.y,
size.x,
size.y,
Size::Medium.to_corner_radius(),
APP_CONFIG.read().corner_roundness(),
);

// draw
Expand All @@ -108,7 +109,7 @@ impl Drawable for Blur {
pos.y,
size.x,
size.y,
Size::Medium.to_corner_radius(),
APP_CONFIG.read().corner_roundness(),
);

canvas.fill_path(
Expand Down
4 changes: 2 additions & 2 deletions src/tools/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
configuration::APP_CONFIG,
math::{self, Vec2D},
sketch_board::{MouseEventMsg, MouseEventType},
style::{Size, Style},
style::Style,
tools::DrawableClone,
};

Expand Down Expand Up @@ -104,7 +104,7 @@ impl Highlight for Highlighter<BlockHighlight> {
pos.y,
size.x,
size.y,
Size::Medium.to_corner_radius(),
APP_CONFIG.read().corner_roundness(),
);

let shadow_paint = Paint::color(femtovg::Color::rgba(
Expand Down
5 changes: 3 additions & 2 deletions src/tools/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use femtovg::{FontId, Path};
use relm4::gtk::gdk::{Key, ModifierType};

use crate::{
configuration::APP_CONFIG,
math::Vec2D,
sketch_board::{MouseEventMsg, MouseEventType},
style::{Size, Style},
style::Style,
};

use super::{Drawable, DrawableClone, Tool, ToolUpdateResult};
Expand Down Expand Up @@ -35,7 +36,7 @@ impl Drawable for Rectangle {
self.top_left.y,
size.x,
size.y,
Size::Medium.to_corner_radius(),
APP_CONFIG.read().corner_roundness(),
);

if self.style.fill {
Expand Down

0 comments on commit 891214b

Please sign in to comment.