Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option to specify the "corner roundness" #140

Merged
merged 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 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 disabled rounded corners)
corner_roundness = 12,
schaumtier marked this conversation as resolved.
Show resolved Hide resolved
# 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
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
18 changes: 14 additions & 4 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub struct Style {
pub fill: bool,
}

#[derive(Clone, Copy, Debug, Default)]
pub struct Properties {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this struct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't really know - just needed a place to attach the getter function... maybe its better kept somewhere else. rust is really not my programming language


#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Color {
pub r: u8,
Expand Down Expand Up @@ -176,6 +179,12 @@ impl FromVariant for Size {
}
}

impl Properties {
pub fn corner_roundness() -> f32 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little redundant. Perhaps we could directly reference APP_CONFIG.read().corner_roundness() where it's used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initially i thought of the need to differentiate between "Small", "Medium" and "Large" - thats why i've made a function. but of course would it be enough to have the numeric value.
if it's okay to reference APP_CONFIG directly in e.g. rectangle.rs, i can do this there.

return APP_CONFIG.read().corner_roundness();
}
}

impl Size {
pub fn to_text_size(self) -> i32 {
let size_factor = APP_CONFIG.read().annotation_size_factor();
Expand Down Expand Up @@ -215,11 +224,12 @@ impl Size {
}
}

pub fn to_corner_radius(self) -> f32 {
pub fn to_corner_roundness(self) -> f32 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this function needed? It always returns the same value, regardless of self. At a glance, it also seems unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's right - I just forgot to remove it

let corner_roundness = APP_CONFIG.read().corner_roundness();
match self {
Size::Small => 12.0,
Size::Medium => 12.0,
Size::Large => 12.0,
Size::Small => corner_roundness,
Size::Medium => corner_roundness,
Size::Large => corner_roundness,
}
}
}
12 changes: 3 additions & 9 deletions src/tools/blur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use relm4::gtk::gdk::Key;
use crate::{
math::{self, Vec2D},
sketch_board::{MouseEventMsg, MouseEventType},
style::{Size, Style},
style::{Properties, Size, Style},
};

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

// draw
Expand All @@ -103,13 +103,7 @@ impl Drawable for Blur {
}

let mut path = Path::new();
path.rounded_rect(
pos.x,
pos.y,
size.x,
size.y,
Size::Medium.to_corner_radius(),
);
path.rounded_rect(pos.x, pos.y, size.x, size.y, Properties::corner_roundness());

canvas.fill_path(
&path,
Expand Down
10 changes: 2 additions & 8 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::{Properties, Style},
tools::DrawableClone,
};

Expand Down Expand Up @@ -99,13 +99,7 @@ impl Highlight for Highlighter<BlockHighlight> {
let (pos, size) = math::rect_ensure_positive_size(self.data.top_left, size);

let mut shadow_path = Path::new();
shadow_path.rounded_rect(
pos.x,
pos.y,
size.x,
size.y,
Size::Medium.to_corner_radius(),
);
shadow_path.rounded_rect(pos.x, pos.y, size.x, size.y, Properties::corner_roundness());

let shadow_paint = Paint::color(femtovg::Color::rgba(
self.style.color.r,
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use relm4::gtk::gdk::{Key, ModifierType};
use crate::{
math::Vec2D,
sketch_board::{MouseEventMsg, MouseEventType},
style::{Size, Style},
style::{Properties, Style},
};

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

if self.style.fill {
Expand Down
Loading