Skip to content

Commit

Permalink
feat: add Text Highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
decipher3114 committed Oct 1, 2024
1 parent 01a9905 commit 8f0ffef
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 47 deletions.
Binary file modified assets/fonts/icons.ttf
Binary file not shown.
28 changes: 15 additions & 13 deletions src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub const FONT_MEDIUM: &[u8; 86616] = include_bytes!("../assets/fonts/SpaceGrote

pub const FONT_BOLD: &[u8; 86520] = include_bytes!("../assets/fonts/SpaceGrotesk-Bold.ttf");

pub const FONT_ICONS: &[u8; 2168] = include_bytes!("../assets/fonts/icons.ttf");
pub const FONT_ICONS: &[u8; 2336] = include_bytes!("../assets/fonts/icons.ttf");

pub const APPICON: &[u8; 1358] = include_bytes!("../assets/icons/icon.png");

Expand All @@ -24,26 +24,28 @@ pub const BOLD: Font = Font {
style: iced::font::Style::Normal,
};

pub const ICON: Font = Font::with_name("icomoon");
pub const ICON: Font = Font::with_name("icons");

pub const FOLDER_ICON: char = '\u{E901}';
pub const FOLDER_ICON: char = '\u{E100}';

pub const CANCEL: char = '\u{E902}';
pub const RECT_FILLED: char = '\u{F101}';

pub const DONE: char = '\u{E903}';
pub const RECT_STROKE: char = '\u{F102}';

pub const RECT_FILLED: char = '\u{E904}';
pub const ELLIPSE_FILLED: char = '\u{F103}';

pub const RECT_STROKE: char = '\u{E905}';
pub const ELLIPSE_STROKE: char = '\u{F104}';

pub const ELLIPSE_FILLED: char = '\u{E906}';
pub const LINE: char = '\u{F105}';

pub const ELLIPSE_STROKE: char = '\u{E907}';
pub const HIGHLIGHT: char = '\u{F106}';

pub const LINE: char = '\u{E908}';
pub const CANCEL: char = '\u{F201}';

pub const STROKE_THIN: char = '\u{E909}';
pub const DONE: char = '\u{F202}';

pub const STROKE_MEDIUM: char = '\u{E910}';
pub const STROKE_THIN: char = '\u{F301}';

pub const STROKE_BROAD: char = '\u{E911}';
pub const STROKE_MEDIUM: char = '\u{F302}';

pub const STROKE_BROAD: char = '\u{F303}';
2 changes: 1 addition & 1 deletion src/entities/capture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct CaptureWindow {
pub enum CaptureEvent {
Cancel,
Done,
ChooseShapeType(ShapeType, bool),
ChooseShapeType(ShapeType, bool, bool),
ChangeStroke(ShapeStroke),
ChangeColor(ShapeColor),
SetInitialPoint,
Expand Down
1 change: 1 addition & 0 deletions src/entities/capture/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct Shape {
pub endpoints: Endpoints,
pub color: ShapeColor,
pub is_filled: bool,
pub is_solid: bool,
pub stroke_width: ShapeStroke,
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/capture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl CaptureWindow {
let initial_pt = shape.endpoints.initial_pt.unwrap();
let final_pt = shape.endpoints.final_pt.unwrap();
let mut paint = Paint::default();
let color = shape.color.into_paint();
let color = shape.color.into_paint(shape.is_solid);
paint.set_color(color);
let mut stroke = Stroke::default();
if !shape.is_filled {
Expand Down
32 changes: 16 additions & 16 deletions src/utils/capture/shape.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
use iced::color;

use crate::entities::capture::shape::{ShapeColor, ShapeStroke};

impl ShapeColor {
pub fn into_iced_color(self) -> iced::Color {
pub fn into_iced_color(self, solid: bool) -> iced::Color {
let opacity = if solid { 1.0 } else { 0.3 };
match self {
Self::Red => color!(0xff0000),
Self::Blue => color!(0x0000ff),
Self::Green => color!(0x00ff00),
Self::Yellow => color!(0xffff00),
Self::Black => color!(0x000000),
Self::White => color!(0xffffff),
ShapeColor::Red => iced::Color::from_rgba8(255, 0, 0, opacity),
ShapeColor::Green => iced::Color::from_rgba8(0, 255, 0, opacity),
ShapeColor::Blue => iced::Color::from_rgba8(0, 0, 255, opacity),
ShapeColor::Yellow => iced::Color::from_rgba8(255, 255, 0, opacity),
ShapeColor::Black => iced::Color::from_rgba8(0, 0, 0, opacity),
ShapeColor::White => iced::Color::from_rgba8(255, 255, 255, opacity),
}
}

pub fn into_paint(self) -> tiny_skia::Color {
pub fn into_paint(self, solid: bool) -> tiny_skia::Color {
let opacity = if solid { 255 } else { 77 };
match self {
ShapeColor::Red => tiny_skia::Color::from_rgba8(255, 0, 0, 255),
ShapeColor::Green => tiny_skia::Color::from_rgba8(0, 255, 0, 255),
ShapeColor::Blue => tiny_skia::Color::from_rgba8(0, 0, 255, 255),
ShapeColor::Yellow => tiny_skia::Color::from_rgba8(255, 255, 0, 255),
ShapeColor::Black => tiny_skia::Color::from_rgba8(0, 0, 0, 255),
ShapeColor::White => tiny_skia::Color::from_rgba8(255, 255, 255, 255),
ShapeColor::Red => tiny_skia::Color::from_rgba8(255, 0, 0, opacity),
ShapeColor::Green => tiny_skia::Color::from_rgba8(0, 255, 0, opacity),
ShapeColor::Blue => tiny_skia::Color::from_rgba8(0, 0, 255, opacity),
ShapeColor::Yellow => tiny_skia::Color::from_rgba8(255, 255, 0, opacity),
ShapeColor::Black => tiny_skia::Color::from_rgba8(0, 0, 0, opacity),
ShapeColor::White => tiny_skia::Color::from_rgba8(255, 255, 255, opacity),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/windows/capture/annotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn draw_shape(frame: &mut Frame, shape: &Shape) {
(shape.endpoints.initial_pt, shape.endpoints.final_pt)
{
let shape_type = shape.shape_type;
let color = shape.color.into_iced_color();
let color = shape.color.into_iced_color(shape.is_solid);
match shape_type {
ShapeType::Rectangle => {
let top_left = initial_pt;
Expand Down
30 changes: 15 additions & 15 deletions src/windows/capture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ use iced::{
widget::{
button, canvas, column, container, horizontal_space, image::Handle, row, stack, text,
vertical_space, Image,
},
Alignment::Center,
Length::Fill,
Task,
}, Alignment::Center, Length::Fill, Task
};

pub mod annotate;

use crate::{
assets::{
CANCEL, DONE, ELLIPSE_FILLED, ELLIPSE_STROKE, ICON, LINE, RECT_FILLED, RECT_STROKE,
STROKE_BROAD, STROKE_MEDIUM, STROKE_THIN,
CANCEL, DONE, ELLIPSE_FILLED, ELLIPSE_STROKE, HIGHLIGHT, ICON, LINE, RECT_FILLED, RECT_STROKE, STROKE_BROAD, STROKE_MEDIUM, STROKE_THIN
},
entities::{
capture::{
Expand Down Expand Up @@ -49,11 +45,12 @@ impl CaptureWindow {
self.endpoints.clear();
}
}
CaptureEvent::ChooseShapeType(shape_type, is_filled) => {
CaptureEvent::ChooseShapeType(shape_type, is_filled, is_solid) => {
self.endpoints.clear();
self.mode = Mode::Draw;
self.shape.shape_type = shape_type;
self.shape.is_filled = is_filled;
self.shape.is_solid = is_solid;
}
CaptureEvent::ChangeStroke(stroke_width) => {
self.shape.stroke_width = stroke_width;
Expand Down Expand Up @@ -125,30 +122,32 @@ impl CaptureWindow {

toolbar = toolbar.push(horizontal_space().width(Fill));

let shapes_icon = |utf, shape_type, is_filled| {
let shapes_icon = |utf, shape_type, is_filled, is_solid| {
let button_class = if self.mode == Mode::Draw
&& self.shape.shape_type == shape_type
&& self.shape.is_filled == is_filled
&& self.shape.is_solid == is_solid
{
ButtonClass::Selected
} else {
ButtonClass::Default
};

button(text(utf).font(ICON).size(TEXT).center())
.on_press(CaptureEvent::ChooseShapeType(shape_type, is_filled))
.on_press(CaptureEvent::ChooseShapeType(shape_type, is_filled, is_solid))
.height(SQUARE)
.width(SQUARE)
.class(button_class)
};

let shapes = panel(
row![
shapes_icon(RECT_FILLED, ShapeType::Rectangle, true),
shapes_icon(RECT_STROKE, ShapeType::Rectangle, false),
shapes_icon(ELLIPSE_FILLED, ShapeType::Ellipse, true),
shapes_icon(ELLIPSE_STROKE, ShapeType::Ellipse, false),
shapes_icon(LINE, ShapeType::Line, false),
shapes_icon(RECT_FILLED, ShapeType::Rectangle, true, true),
shapes_icon(RECT_STROKE, ShapeType::Rectangle, false, true),
shapes_icon(ELLIPSE_FILLED, ShapeType::Ellipse, true, true),
shapes_icon(ELLIPSE_STROKE, ShapeType::Ellipse, false, true),
shapes_icon(LINE, ShapeType::Line, false, true),
shapes_icon(HIGHLIGHT, ShapeType::Rectangle, true, false)
]
.spacing(ROW),
);
Expand Down Expand Up @@ -192,7 +191,8 @@ impl CaptureWindow {
.font(ICON)
.size(TEXT)
.center()
.class(TextClass::Custom(color.into_iced_color())),
// .color(color!(0.0, 0.0, 0.0, 1.0))
.class(TextClass::Custom(color.into_iced_color(true))),
)
.on_press(CaptureEvent::ChangeColor(color))
.height(SQUARE)
Expand Down

0 comments on commit 8f0ffef

Please sign in to comment.