Compare commits
11 Commits
579aace306
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| c63babb599 | |||
| fac896161e | |||
| 945bb4d9fe | |||
| 47b7feeab8 | |||
| b1eb5f91be | |||
| 3669f54936 | |||
| 2fb9908329 | |||
| 0acab0413c | |||
| 8f16741705 | |||
| a663de3ca0 | |||
| 61575fbf65 |
853
Cargo.lock
generated
853
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
54
src/app.rs
54
src/app.rs
@ -11,11 +11,12 @@ use crate::{
|
|||||||
file_editor::{FileEditor, SaveStatus},
|
file_editor::{FileEditor, SaveStatus},
|
||||||
folder::Folder,
|
folder::Folder,
|
||||||
preferences::Preferences,
|
preferences::Preferences,
|
||||||
|
text_styles::{H1, H1_MONO, H2, H2_MONO, H3, H3_MONO, H4, H4_MONO, H5, H5_MONO, H6, H6_MONO},
|
||||||
util::{GuiSender, file_mtime, log_error},
|
util::{GuiSender, file_mtime, log_error},
|
||||||
};
|
};
|
||||||
use egui::{
|
use egui::{
|
||||||
Align, Button, Context, FontData, FontDefinitions, FontId, Image, Key, Modifiers,
|
Align, Button, Context, FontData, FontDefinitions, FontFamily, FontId, Frame, Image, Key,
|
||||||
PointerButton, RichText, ScrollArea, Widget, include_image,
|
Modifiers, PointerButton, RichText, ScrollArea, Theme, Widget, include_image,
|
||||||
};
|
};
|
||||||
use eyre::eyre;
|
use eyre::eyre;
|
||||||
|
|
||||||
@ -190,36 +191,38 @@ impl App {
|
|||||||
.map(|(name, data)| (name.to_string(), Arc::new(FontData::from_static(data))))
|
.map(|(name, data)| (name.to_string(), Arc::new(FontData::from_static(data))))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
fonts.families.insert(
|
fonts
|
||||||
egui::FontFamily::Proportional,
|
.families
|
||||||
vec!["IosevkaAile-Regular".into()],
|
.insert(FontFamily::Proportional, vec!["IosevkaAile-Regular".into()]);
|
||||||
);
|
|
||||||
|
|
||||||
fonts
|
fonts
|
||||||
.families
|
.families
|
||||||
.insert(egui::FontFamily::Monospace, vec!["Iosevka-Thin".into()]);
|
.insert(FontFamily::Monospace, vec!["Iosevka-Thin".into()]);
|
||||||
|
|
||||||
cc.egui_ctx.set_fonts(fonts);
|
cc.egui_ctx.set_fonts(fonts);
|
||||||
|
|
||||||
// markdown font styles
|
// markdown font styles
|
||||||
cc.egui_ctx.style_mut(|style| {
|
for theme in [Theme::Dark, Theme::Light] {
|
||||||
for (name, size) in [
|
cc.egui_ctx.style_mut_of(theme, |style| {
|
||||||
("H1", 28.0),
|
for (name, size, family) in [
|
||||||
("H2", 26.0),
|
(H1, 28.0, FontFamily::Proportional),
|
||||||
("H3", 24.0),
|
(H2, 26.0, FontFamily::Proportional),
|
||||||
("H4", 22.0),
|
(H3, 24.0, FontFamily::Proportional),
|
||||||
("H5", 20.0),
|
(H4, 22.0, FontFamily::Proportional),
|
||||||
("H6", 18.0),
|
(H5, 20.0, FontFamily::Proportional),
|
||||||
|
(H6, 18.0, FontFamily::Proportional),
|
||||||
|
(H1_MONO, 28.0, FontFamily::Monospace),
|
||||||
|
(H2_MONO, 26.0, FontFamily::Monospace),
|
||||||
|
(H3_MONO, 24.0, FontFamily::Monospace),
|
||||||
|
(H4_MONO, 22.0, FontFamily::Monospace),
|
||||||
|
(H5_MONO, 20.0, FontFamily::Monospace),
|
||||||
|
(H6_MONO, 18.0, FontFamily::Monospace),
|
||||||
] {
|
] {
|
||||||
style.text_styles.insert(
|
let name = egui::TextStyle::Name(name.into());
|
||||||
egui::TextStyle::Name(name.into()),
|
style.text_styles.insert(name, FontId { size, family });
|
||||||
FontId {
|
|
||||||
size,
|
|
||||||
family: egui::FontFamily::Proportional,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// enable features on egui_extras to add more image types
|
// enable features on egui_extras to add more image types
|
||||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||||
@ -468,7 +471,12 @@ impl eframe::App for App {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
egui::CentralPanel::default()
|
||||||
|
.frame(Frame {
|
||||||
|
fill: ctx.style().visuals.window_fill(),
|
||||||
|
..Frame::central_panel(&ctx.style())
|
||||||
|
})
|
||||||
|
.show(ctx, |ui| {
|
||||||
if let Some(Tab::File(file_editor)) = self
|
if let Some(Tab::File(file_editor)) = self
|
||||||
.open_tab_index
|
.open_tab_index
|
||||||
.and_then(|i| self.tabs.get_mut(i))
|
.and_then(|i| self.tabs.get_mut(i))
|
||||||
|
|||||||
@ -11,8 +11,7 @@ use std::{
|
|||||||
|
|
||||||
use chrono::{DateTime, Local};
|
use chrono::{DateTime, Local};
|
||||||
use egui::{
|
use egui::{
|
||||||
Align, Button, Context, DragAndDrop, Frame, Layout, ScrollArea, Ui, UiBuilder, Vec2,
|
Align, Button, Context, DragAndDrop, Frame, Layout, ScrollArea, Ui, UiBuilder, Vec2, vec2,
|
||||||
Widget as _, vec2,
|
|
||||||
};
|
};
|
||||||
use eyre::eyre;
|
use eyre::eyre;
|
||||||
use notify::{EventKind, Watcher};
|
use notify::{EventKind, Watcher};
|
||||||
@ -220,7 +219,7 @@ impl FileEditor {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
self.scroll_delta = scroll_area.inner_rect.height() * 0.9;
|
self.scroll_delta = scroll_area.inner_rect.height() * 0.5;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,25 +246,16 @@ impl FileEditor {
|
|||||||
|
|
||||||
let mut retain = true;
|
let mut retain = true;
|
||||||
|
|
||||||
if is_dragging {
|
// Createa horizontal area to draw the buffer item. The three things drawn here are:
|
||||||
let (_, drop) = ui.dnd_drop_zone::<DraggingItem, _>(Frame::NONE, |ui| {
|
// - The controls that exist at the left-size of the buffer item, i.e. "up"/"down".
|
||||||
ui.set_min_size(vec2(ui.available_width(), drag_zone_height));
|
// - The buffer item.
|
||||||
});
|
// - The controls that exist at the right-size of the buffer item, i.e. "delete".
|
||||||
if let Some(drop) = drop {
|
|
||||||
drop_from_to = Some((drop.index, i));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// the dnd_drop_zone adds 3pts work of extra space
|
|
||||||
ui.add_space(drag_zone_height + 3.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
// We don't know how tall the buffer item will be, so we'll reserve
|
// At this point, we don't know how tall the buffer item will be, so we'll reserve
|
||||||
// some horizontal space here and come back to drawing the dragger
|
// some horizontal space here and come back to drawing the controls later.
|
||||||
// later.
|
let (_id, mut left_controls_rect) = ui.allocate_space(Vec2::new(20.0, 1.0));
|
||||||
let (dragger_id, mut dragger_rect) = ui.allocate_space(Vec2::new(20.0, 1.0));
|
|
||||||
|
|
||||||
// Leave some space at the end for the delete button..
|
// Leave some space at the end for the delete button.
|
||||||
let w = ui.available_width();
|
let w = ui.available_width();
|
||||||
let item_size = Vec2::new(w - 20.0, 0.0);
|
let item_size = Vec2::new(w - 20.0, 0.0);
|
||||||
|
|
||||||
@ -288,18 +278,17 @@ impl FileEditor {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Delete-button
|
// Delete-button
|
||||||
if ui.button("x").clicked() {
|
if ui.button("⌫").clicked() {
|
||||||
retain = false;
|
retain = false;
|
||||||
ui.ctx().request_repaint();
|
ui.ctx().request_repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the dragger using the height from the buffer item
|
left_controls_rect.set_height(item_response.response.rect.height());
|
||||||
dragger_rect.set_height(item_response.response.rect.height());
|
|
||||||
|
|
||||||
// Controls for moving the buffer item
|
// Controls for moving the buffer item
|
||||||
ui.scope_builder(
|
ui.scope_builder(
|
||||||
UiBuilder::new()
|
UiBuilder::new()
|
||||||
.max_rect(dragger_rect)
|
.max_rect(left_controls_rect)
|
||||||
.layout(Layout::top_down(Align::Center)),
|
.layout(Layout::top_down(Align::Center)),
|
||||||
|ui| {
|
|ui| {
|
||||||
let up_button_response = ui.add_enabled(!is_first, Button::new("⇡"));
|
let up_button_response = ui.add_enabled(!is_first, Button::new("⇡"));
|
||||||
@ -307,17 +296,12 @@ impl FileEditor {
|
|||||||
drop_from_to = Some((i, i - 1));
|
drop_from_to = Some((i, i - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.dnd_drag_source(dragger_id, DraggingItem { index: i }, |ui| {
|
// Add some space so that the next button is drawn
|
||||||
Button::new("≡")
|
// at the bottom of the buffer item.
|
||||||
.min_size(
|
ui.add_space(
|
||||||
// Use all available height, save for the height taken up by
|
left_controls_rect.height()
|
||||||
// the up/down buttons + padding. Assume down-button is the
|
- (up_button_response.rect.height() * 2.0 + 4.0),
|
||||||
// equally tall as the up-button.
|
);
|
||||||
dragger_rect.size()
|
|
||||||
- Vec2::Y * (up_button_response.rect.height() * 2.0 + 4.0),
|
|
||||||
)
|
|
||||||
.ui(ui);
|
|
||||||
});
|
|
||||||
|
|
||||||
if ui.add_enabled(!is_last, Button::new("⇣")).clicked() {
|
if ui.add_enabled(!is_last, Button::new("⇣")).clicked() {
|
||||||
drop_from_to = Some((i, i + 2));
|
drop_from_to = Some((i, i + 2));
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use std::{
|
|||||||
thread,
|
thread,
|
||||||
};
|
};
|
||||||
|
|
||||||
use egui::{Response, Ui};
|
use egui::{Button, Color32, Response, Stroke, TextWrapMode, Ui, Vec2, Widget};
|
||||||
use eyre::{Context, OptionExt, eyre};
|
use eyre::{Context, OptionExt, eyre};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -52,20 +52,59 @@ impl Deref for FolderResponse<'_> {
|
|||||||
impl LoadedFolder {
|
impl LoadedFolder {
|
||||||
pub fn show<'a>(&'a mut self, ui: &mut Ui) -> FolderResponse<'a> {
|
pub fn show<'a>(&'a mut self, ui: &mut Ui) -> FolderResponse<'a> {
|
||||||
let mut open_file = None;
|
let mut open_file = None;
|
||||||
|
|
||||||
|
let draw_highlight = |ui: &mut Ui, rect| {
|
||||||
|
ui.painter().rect(
|
||||||
|
rect,
|
||||||
|
2.0,
|
||||||
|
if ui.visuals().dark_mode {
|
||||||
|
Color32::from_white_alpha(16)
|
||||||
|
} else {
|
||||||
|
Color32::from_black_alpha(16)
|
||||||
|
},
|
||||||
|
Stroke::NONE,
|
||||||
|
egui::StrokeKind::Outside,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
let inner = ui
|
let inner = ui
|
||||||
.collapsing(&self.name, |ui| {
|
.collapsing(&self.name, |ui| {
|
||||||
for folder in &mut self.child_folders {
|
for folder in &mut self.child_folders {
|
||||||
open_file = open_file.or(folder.show(ui).open_file);
|
open_file = open_file.or(folder.show(ui).open_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let w = ui.available_width();
|
||||||
|
|
||||||
|
let mut first = true;
|
||||||
|
|
||||||
for file in &mut self.child_files {
|
for file in &mut self.child_files {
|
||||||
if ui.button(&file.name).clicked() {
|
if !first {
|
||||||
|
ui.add_space(2.0);
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
|
||||||
|
let button = Button::new(&file.name)
|
||||||
|
.min_size(Vec2::new(w, 0.0))
|
||||||
|
.wrap_mode(TextWrapMode::Truncate)
|
||||||
|
.frame(false)
|
||||||
|
.corner_radius(0.0)
|
||||||
|
.ui(ui);
|
||||||
|
|
||||||
|
if button.hovered() {
|
||||||
|
draw_highlight(ui, button.rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
if button.clicked() {
|
||||||
open_file = Some(file.path.as_path())
|
open_file = Some(file.path.as_path())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.header_response;
|
.header_response;
|
||||||
|
|
||||||
|
if inner.hovered() {
|
||||||
|
draw_highlight(ui, inner.rect);
|
||||||
|
}
|
||||||
|
|
||||||
FolderResponse { inner, open_file }
|
FolderResponse { inner, open_file }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,11 +133,18 @@ impl LoadedFolder {
|
|||||||
log::error!("Symlinks not yet supported, skipping {path:?}");
|
log::error!("Symlinks not yet supported, skipping {path:?}");
|
||||||
continue;
|
continue;
|
||||||
} else if file_type.is_file() {
|
} else if file_type.is_file() {
|
||||||
|
if filter_file(&name) {
|
||||||
child_files.push(File { name, path });
|
child_files.push(File { name, path });
|
||||||
|
}
|
||||||
} else if file_type.is_dir() {
|
} else if file_type.is_dir() {
|
||||||
|
if filter_folder(&name) {
|
||||||
child_folders.push(Folder::NotLoaded { name, path });
|
child_folders.push(Folder::NotLoaded { name, path });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
child_folders.sort_by_key(|folder| folder.name().to_owned());
|
||||||
|
child_files.sort_by_key(|file| (!file.name.ends_with(".md"), file.name.clone()));
|
||||||
|
|
||||||
let folder = LoadedFolder {
|
let folder = LoadedFolder {
|
||||||
name,
|
name,
|
||||||
@ -216,3 +262,11 @@ impl<'de> Deserialize<'de> for Folder {
|
|||||||
Ok(Folder::NotLoaded { name, path })
|
Ok(Folder::NotLoaded { name, path })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn filter_folder(_folder_name: &str) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn filter_file(file_name: &str) -> bool {
|
||||||
|
file_name != ".DS_Store"
|
||||||
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
mod canvas_rasterizer;
|
mod canvas_rasterizer;
|
||||||
mod disk_format;
|
mod disk_format;
|
||||||
|
mod tool;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{self, Display},
|
fmt::{self, Display},
|
||||||
@ -15,7 +16,7 @@ use disk_format::{DiskFormat, RawStroke, RawStrokeHeader, f16_le};
|
|||||||
use egui::{
|
use egui::{
|
||||||
Color32, Event, Frame, Id, Mesh, PointerButton, Pos2, Rect, Sense, Shape, Stroke, Theme, Ui,
|
Color32, Event, Frame, Id, Mesh, PointerButton, Pos2, Rect, Sense, Shape, Stroke, Theme, Ui,
|
||||||
Vec2,
|
Vec2,
|
||||||
emath::{self, TSTransform},
|
emath::{self, RectTransform, TSTransform},
|
||||||
epaint::{TessellationOptions, Tessellator, Vertex},
|
epaint::{TessellationOptions, Tessellator, Vertex},
|
||||||
};
|
};
|
||||||
use eyre::{Context, bail};
|
use eyre::{Context, bail};
|
||||||
@ -26,6 +27,8 @@ use zerocopy::{FromBytes, IntoBytes};
|
|||||||
use crate::{custom_code_block::try_from_custom_code_block, rasterizer};
|
use crate::{custom_code_block::try_from_custom_code_block, rasterizer};
|
||||||
use crate::{custom_code_block::write_custom_code_block, util::random_id};
|
use crate::{custom_code_block::write_custom_code_block, util::random_id};
|
||||||
|
|
||||||
|
use self::tool::{Tool, ToolEvent};
|
||||||
|
|
||||||
const HANDWRITING_MIN_HEIGHT: f32 = 100.0;
|
const HANDWRITING_MIN_HEIGHT: f32 = 100.0;
|
||||||
const HANDWRITING_BOTTOM_PADDING: f32 = 80.0;
|
const HANDWRITING_BOTTOM_PADDING: f32 = 80.0;
|
||||||
const HANDWRITING_MARGIN: f32 = 0.05;
|
const HANDWRITING_MARGIN: f32 = 0.05;
|
||||||
@ -78,10 +81,20 @@ struct Ephemeral {
|
|||||||
|
|
||||||
canvas_rasterizer: CanvasRasterizer,
|
canvas_rasterizer: CanvasRasterizer,
|
||||||
|
|
||||||
|
tool: Tool,
|
||||||
|
|
||||||
|
/// Tool position in canvas space.
|
||||||
|
tool_position: Option<Pos2>,
|
||||||
|
|
||||||
|
/// Tool position last frame, in canvas space.
|
||||||
|
last_tool_position: Option<Pos2>,
|
||||||
|
|
||||||
/// The stroke that is currently being drawed.
|
/// The stroke that is currently being drawed.
|
||||||
current_stroke: Vec<Pos2>,
|
current_stroke: Vec<Pos2>,
|
||||||
|
|
||||||
/// The lines that have not been blitted to `texture` yet.
|
/// The lines that have not been blitted to `texture` yet.
|
||||||
|
///
|
||||||
|
/// Each pair of [Pos2]s is the start and end of one line.
|
||||||
unblitted_lines: Vec<[Pos2; 2]>,
|
unblitted_lines: Vec<[Pos2; 2]>,
|
||||||
|
|
||||||
tessellator: Option<Tessellator>,
|
tessellator: Option<Tessellator>,
|
||||||
@ -126,6 +139,9 @@ impl Default for Ephemeral {
|
|||||||
Self {
|
Self {
|
||||||
id: random_id(),
|
id: random_id(),
|
||||||
canvas_rasterizer: Default::default(),
|
canvas_rasterizer: Default::default(),
|
||||||
|
tool: Tool::Pencil,
|
||||||
|
tool_position: None,
|
||||||
|
last_tool_position: None,
|
||||||
current_stroke: Default::default(),
|
current_stroke: Default::default(),
|
||||||
tessellator: None,
|
tessellator: None,
|
||||||
mesh: Default::default(),
|
mesh: Default::default(),
|
||||||
@ -170,6 +186,14 @@ impl Handwriting {
|
|||||||
let _ = Clipboard::new().unwrap().set_text(text);
|
let _ = Clipboard::new().unwrap().set_text(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let (label, switch_to_tool) = match self.e.tool {
|
||||||
|
Tool::Pencil => ("eraser", Tool::Eraser),
|
||||||
|
Tool::Eraser => ("pencil", Tool::Pencil),
|
||||||
|
};
|
||||||
|
if ui.button(label).clicked() {
|
||||||
|
self.e.tool = switch_to_tool;
|
||||||
|
}
|
||||||
|
|
||||||
let vertex_count: usize = self.e.mesh.indices.len() / 3;
|
let vertex_count: usize = self.e.mesh.indices.len() / 3;
|
||||||
ui.label(format!("vertices: {vertex_count}"));
|
ui.label(format!("vertices: {vertex_count}"));
|
||||||
})
|
})
|
||||||
@ -209,6 +233,8 @@ impl Handwriting {
|
|||||||
emath::RectTransform::from_to(Rect::from_min_size(Pos2::ZERO, size), response.rect);
|
emath::RectTransform::from_to(Rect::from_min_size(Pos2::ZERO, size), response.rect);
|
||||||
let from_screen = to_screen.inverse();
|
let from_screen = to_screen.inverse();
|
||||||
|
|
||||||
|
self.e.last_tool_position = self.e.tool_position;
|
||||||
|
|
||||||
// Was the user in the process of drawing a stroke last frame?
|
// Was the user in the process of drawing a stroke last frame?
|
||||||
let was_drawing = !self.e.current_stroke.is_empty();
|
let was_drawing = !self.e.current_stroke.is_empty();
|
||||||
|
|
||||||
@ -268,88 +294,21 @@ impl Handwriting {
|
|||||||
|
|
||||||
// Process input events and turn them into strokes
|
// Process input events and turn them into strokes
|
||||||
for event in events {
|
for event in events {
|
||||||
let last_canvas_pos = self.e.current_stroke.last();
|
let mut last_tool_position = self.e.last_tool_position;
|
||||||
|
process_event(&mut last_tool_position, from_screen, &event, |tool_event| {
|
||||||
match event {
|
self.e.tool_position = tool_event.position();
|
||||||
Event::PointerMoved(new_position) => {
|
match self.e.tool {
|
||||||
let new_canvas_pos = from_screen * new_position;
|
Tool::Pencil => {
|
||||||
if let Some(&last_canvas_pos) = last_canvas_pos {
|
hw_response.changed |= tool::pencil::on_tool_event(self, tool_event);
|
||||||
if last_canvas_pos != new_canvas_pos {
|
}
|
||||||
self.push_to_stroke(new_canvas_pos);
|
Tool::Eraser => {
|
||||||
response.mark_changed();
|
if tool::eraser::on_tool_event(self, tool_event) {
|
||||||
|
self.e.refresh_texture = true;
|
||||||
|
hw_response.changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
Event::MouseMoved(mut delta) => {
|
|
||||||
if delta.length() == 0.0 {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: pinenote: MouseMovement delta does *not* take into account screen
|
|
||||||
// scaling and rotation, so unless you've scaling=1 and no rotation, the
|
|
||||||
// MouseMoved values will be all wrong.
|
|
||||||
if cfg!(feature = "pinenote") {
|
|
||||||
delta /= 1.8;
|
|
||||||
delta = -delta.rot90();
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(&last_canvas_pos) = last_canvas_pos {
|
|
||||||
self.push_to_stroke(last_canvas_pos + delta);
|
|
||||||
response.mark_changed();
|
|
||||||
} else {
|
|
||||||
println!("Got `MouseMoved`, but have no previous pos");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Event::PointerButton {
|
|
||||||
pos,
|
|
||||||
button,
|
|
||||||
pressed,
|
|
||||||
modifiers: _,
|
|
||||||
} => match (button, pressed) {
|
|
||||||
(PointerButton::Primary, true) => {
|
|
||||||
if last_canvas_pos.is_none() {
|
|
||||||
self.e.current_stroke.push(from_screen * pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(PointerButton::Primary, false) => {
|
|
||||||
if last_canvas_pos.is_some() {
|
|
||||||
self.push_to_stroke(from_screen * pos);
|
|
||||||
self.commit_current_line(hw_response);
|
|
||||||
response.mark_changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop reading events.
|
|
||||||
// TODO: In theory, we can get multiple press->draw->release series
|
|
||||||
// in the same frame. Should handle this.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
(_, _) => continue,
|
|
||||||
},
|
|
||||||
|
|
||||||
// Stop drawing after pointer disappears or the window is unfocused
|
|
||||||
// TODO: In theory, we can get multiple press->draw->release series
|
|
||||||
// in the same frame. Should handle this.
|
|
||||||
Event::PointerGone | Event::WindowFocused(false) => {
|
|
||||||
if !self.e.current_stroke.is_empty() {
|
|
||||||
self.commit_current_line(hw_response);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Event::WindowFocused(true)
|
|
||||||
| Event::Copy
|
|
||||||
| Event::Cut
|
|
||||||
| Event::Paste(..)
|
|
||||||
| Event::Text(..)
|
|
||||||
| Event::Key { .. }
|
|
||||||
| Event::Zoom(..)
|
|
||||||
| Event::Ime(..)
|
|
||||||
| Event::Touch { .. }
|
|
||||||
| Event::MouseWheel { .. }
|
|
||||||
| Event::Screenshot { .. } => continue,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,6 +365,14 @@ impl Handwriting {
|
|||||||
// Draw the texture
|
// Draw the texture
|
||||||
self.e.canvas_rasterizer.show(ui.ctx(), &painter, mesh_rect);
|
self.e.canvas_rasterizer.show(ui.ctx(), &painter, mesh_rect);
|
||||||
|
|
||||||
|
if let Some(tool_position) = self.e.tool_position
|
||||||
|
&& let Tool::Eraser = self.e.tool
|
||||||
|
{
|
||||||
|
let pos = to_screen * tool_position;
|
||||||
|
let shape = Shape::circle_stroke(pos, tool::eraser::RADIUS, style.stroke);
|
||||||
|
painter.add(shape);
|
||||||
|
}
|
||||||
|
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,7 +392,7 @@ impl Handwriting {
|
|||||||
last_mesh_ctx,
|
last_mesh_ctx,
|
||||||
..
|
..
|
||||||
} = &mut self.e;
|
} = &mut self.e;
|
||||||
// TODO: don't tessellate and rasterize on the GUI thread
|
// TODO: avoid tessellating and rasterizing on the GUI thread
|
||||||
|
|
||||||
*last_mesh_ctx = Some(mesh_context);
|
*last_mesh_ctx = Some(mesh_context);
|
||||||
|
|
||||||
@ -444,10 +411,7 @@ impl Handwriting {
|
|||||||
.iter()
|
.iter()
|
||||||
.chain([&*current_stroke])
|
.chain([&*current_stroke])
|
||||||
.filter(|stroke| stroke.len() >= 2)
|
.filter(|stroke| stroke.len() >= 2)
|
||||||
.map(|stroke| {
|
.map(|stroke| egui::Shape::line(stroke.clone(), style.stroke))
|
||||||
//let points: Vec<Pos2> = stroke.iter().map(|&p| to_screen * p).collect();
|
|
||||||
egui::Shape::line(stroke.clone(), style.stroke)
|
|
||||||
})
|
|
||||||
.for_each(|shape| {
|
.for_each(|shape| {
|
||||||
tessellator.tessellate_shape(shape, mesh);
|
tessellator.tessellate_shape(shape, mesh);
|
||||||
});
|
});
|
||||||
@ -480,7 +444,6 @@ impl Handwriting {
|
|||||||
ui.vertical_centered_justified(|ui| {
|
ui.vertical_centered_justified(|ui| {
|
||||||
self.ui_control(None, ui, &mut response);
|
self.ui_control(None, ui, &mut response);
|
||||||
|
|
||||||
//ui.label("Paint with your mouse/touch!");
|
|
||||||
Frame::canvas(ui.style())
|
Frame::canvas(ui.style())
|
||||||
.corner_radius(20.0)
|
.corner_radius(20.0)
|
||||||
.stroke(Stroke::new(5.0, Color32::from_black_alpha(40)))
|
.stroke(Stroke::new(5.0, Color32::from_black_alpha(40)))
|
||||||
@ -591,6 +554,87 @@ impl Handwriting {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert [egui::Event]s to [ToolEvent]s.
|
||||||
|
fn process_event(
|
||||||
|
last_canvas_pos: &mut Option<Pos2>,
|
||||||
|
from_screen: RectTransform,
|
||||||
|
event: &Event,
|
||||||
|
mut on_tool_event: impl FnMut(ToolEvent),
|
||||||
|
) {
|
||||||
|
match event {
|
||||||
|
&Event::PointerMoved(new_position) => {
|
||||||
|
let new_canvas_pos = from_screen * new_position;
|
||||||
|
if last_canvas_pos.is_some() && *last_canvas_pos != Some(new_canvas_pos) {
|
||||||
|
*last_canvas_pos = Some(new_canvas_pos);
|
||||||
|
on_tool_event(ToolEvent::Move { to: new_canvas_pos });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&Event::MouseMoved(mut delta) => {
|
||||||
|
if delta.length() == 0.0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: pinenote: MouseMovement delta does *not* take into account screen
|
||||||
|
// scaling and rotation, so unless you've scaling=1 and no rotation, the
|
||||||
|
// MouseMoved values will be all wrong.
|
||||||
|
if cfg!(feature = "pinenote") {
|
||||||
|
delta /= 1.8;
|
||||||
|
delta = -delta.rot90();
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(pos) = last_canvas_pos {
|
||||||
|
*pos += delta;
|
||||||
|
on_tool_event(ToolEvent::Move { to: *pos });
|
||||||
|
} else {
|
||||||
|
println!("Got `MouseMoved`, but have no previous pos");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&Event::PointerButton {
|
||||||
|
pos,
|
||||||
|
button,
|
||||||
|
pressed,
|
||||||
|
modifiers: _,
|
||||||
|
} => match (button, pressed) {
|
||||||
|
(PointerButton::Primary, true) => {
|
||||||
|
if last_canvas_pos.is_none() {
|
||||||
|
let pos = from_screen * pos;
|
||||||
|
*last_canvas_pos = Some(pos);
|
||||||
|
on_tool_event(ToolEvent::Press { at: pos });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(PointerButton::Primary, false) => {
|
||||||
|
if last_canvas_pos.take().is_some() {
|
||||||
|
let pos = from_screen * pos;
|
||||||
|
on_tool_event(ToolEvent::Move { to: pos });
|
||||||
|
on_tool_event(ToolEvent::Release {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(_, _) => {}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Stop drawing after pointer disappears or the window is unfocused
|
||||||
|
Event::PointerGone | Event::WindowFocused(false) => {
|
||||||
|
if last_canvas_pos.take().is_some() {
|
||||||
|
on_tool_event(ToolEvent::Release {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Event::WindowFocused(true)
|
||||||
|
| Event::Copy
|
||||||
|
| Event::Cut
|
||||||
|
| Event::Paste(..)
|
||||||
|
| Event::Text(..)
|
||||||
|
| Event::Key { .. }
|
||||||
|
| Event::Zoom(..)
|
||||||
|
| Event::Ime(..)
|
||||||
|
| Event::Touch { .. }
|
||||||
|
| Event::MouseWheel { .. }
|
||||||
|
| Event::Screenshot { .. } => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn new_tessellator(pixels_per_point: f32) -> Tessellator {
|
fn new_tessellator(pixels_per_point: f32) -> Tessellator {
|
||||||
Tessellator::new(
|
Tessellator::new(
|
||||||
pixels_per_point,
|
pixels_per_point,
|
||||||
@ -734,7 +778,9 @@ fn mesh_triangles(mesh: &Mesh) -> impl Iterator<Item = [&Vertex; 3]> + Clone {
|
|||||||
mod test {
|
mod test {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use super::Handwriting;
|
use egui::{Event, Modifiers, PointerButton, Pos2, Rect, emath::RectTransform};
|
||||||
|
|
||||||
|
use super::{Handwriting, process_event};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_handwriting() {
|
fn serialize_handwriting() {
|
||||||
@ -748,4 +794,194 @@ mod test {
|
|||||||
Handwriting::from_str(&serialized).expect("Handwriting must de/serialize correctly");
|
Handwriting::from_str(&serialized).expect("Handwriting must de/serialize correctly");
|
||||||
insta::assert_debug_snapshot!("deserialized handwriting", deserialized.strokes);
|
insta::assert_debug_snapshot!("deserialized handwriting", deserialized.strokes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const TEST_EVENTS: &[Event] = &[
|
||||||
|
Event::PointerMoved(Pos2::new(749.9, 225.6)),
|
||||||
|
Event::PointerButton {
|
||||||
|
pos: Pos2::new(749.9, 225.6),
|
||||||
|
button: PointerButton::Primary,
|
||||||
|
pressed: true,
|
||||||
|
modifiers: Modifiers::NONE,
|
||||||
|
},
|
||||||
|
Event::PointerMoved(Pos2::new(749.9, 225.7)),
|
||||||
|
Event::PointerMoved(Pos2::new(749.9, 226.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(750.2, 228.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(751.0, 231.3)),
|
||||||
|
Event::PointerMoved(Pos2::new(752.6, 234.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(754.1, 237.7)),
|
||||||
|
Event::PointerMoved(Pos2::new(755.8, 241.1)),
|
||||||
|
Event::PointerMoved(Pos2::new(757.7, 244.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(759.3, 247.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(760.8, 250.2)),
|
||||||
|
Event::PointerMoved(Pos2::new(762.8, 253.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(765.1, 256.8)),
|
||||||
|
Event::PointerMoved(Pos2::new(767.7, 260.2)),
|
||||||
|
Event::PointerMoved(Pos2::new(771.2, 264.3)),
|
||||||
|
Event::PointerMoved(Pos2::new(774.6, 267.9)),
|
||||||
|
Event::PointerMoved(Pos2::new(778.2, 271.2)),
|
||||||
|
Event::PointerMoved(Pos2::new(782.7, 275.2)),
|
||||||
|
Event::PointerMoved(Pos2::new(786.7, 278.5)),
|
||||||
|
Event::PointerMoved(Pos2::new(790.4, 280.8)),
|
||||||
|
Event::PointerMoved(Pos2::new(794.1, 282.6)),
|
||||||
|
Event::PointerMoved(Pos2::new(797.9, 283.9)),
|
||||||
|
Event::PointerMoved(Pos2::new(801.9, 284.8)),
|
||||||
|
Event::PointerMoved(Pos2::new(805.9, 285.5)),
|
||||||
|
Event::PointerMoved(Pos2::new(810.2, 285.8)),
|
||||||
|
Event::PointerMoved(Pos2::new(814.5, 285.8)),
|
||||||
|
Event::PointerMoved(Pos2::new(818.2, 285.6)),
|
||||||
|
Event::PointerMoved(Pos2::new(821.6, 284.5)),
|
||||||
|
Event::PointerMoved(Pos2::new(824.7, 283.0)),
|
||||||
|
Event::PointerMoved(Pos2::new(827.5, 281.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(830.4, 279.6)),
|
||||||
|
Event::PointerMoved(Pos2::new(833.4, 277.7)),
|
||||||
|
Event::PointerMoved(Pos2::new(836.1, 275.7)),
|
||||||
|
Event::PointerMoved(Pos2::new(838.6, 273.6)),
|
||||||
|
Event::PointerMoved(Pos2::new(840.9, 271.7)),
|
||||||
|
Event::PointerMoved(Pos2::new(843.0, 269.6)),
|
||||||
|
Event::PointerMoved(Pos2::new(845.4, 267.2)),
|
||||||
|
Event::PointerMoved(Pos2::new(847.7, 265.1)),
|
||||||
|
Event::PointerMoved(Pos2::new(849.8, 262.7)),
|
||||||
|
Event::PointerMoved(Pos2::new(852.0, 260.0)),
|
||||||
|
Event::PointerMoved(Pos2::new(854.3, 256.8)),
|
||||||
|
Event::PointerMoved(Pos2::new(856.3, 253.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(858.2, 250.1)),
|
||||||
|
Event::PointerMoved(Pos2::new(860.0, 247.1)),
|
||||||
|
Event::PointerMoved(Pos2::new(861.5, 244.3)),
|
||||||
|
Event::PointerMoved(Pos2::new(862.8, 242.0)),
|
||||||
|
Event::PointerMoved(Pos2::new(864.1, 240.1)),
|
||||||
|
Event::PointerMoved(Pos2::new(865.0, 238.2)),
|
||||||
|
Event::PointerMoved(Pos2::new(865.8, 236.6)),
|
||||||
|
Event::PointerMoved(Pos2::new(866.5, 234.9)),
|
||||||
|
Event::PointerMoved(Pos2::new(867.1, 233.1)),
|
||||||
|
Event::PointerMoved(Pos2::new(867.8, 231.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(868.4, 229.8)),
|
||||||
|
Event::PointerMoved(Pos2::new(868.7, 228.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(868.9, 227.2)),
|
||||||
|
Event::PointerMoved(Pos2::new(869.1, 226.2)),
|
||||||
|
Event::PointerMoved(Pos2::new(869.1, 225.1)),
|
||||||
|
Event::PointerMoved(Pos2::new(869.1, 224.1)),
|
||||||
|
Event::PointerMoved(Pos2::new(869.1, 223.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(869.1, 222.8)),
|
||||||
|
Event::PointerMoved(Pos2::new(869.1, 222.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(869.1, 222.4)),
|
||||||
|
// Event::PointerButton {
|
||||||
|
// pos: Pos2::new(869.1, 222.4),
|
||||||
|
// button: PointerButton::Primary,
|
||||||
|
// pressed: false,
|
||||||
|
// modifiers: Modifiers::NONE,
|
||||||
|
// },
|
||||||
|
Event::PointerGone,
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 158.6)),
|
||||||
|
// --
|
||||||
|
// FIXME: This line looks weird. Probably because of a bug in the rasterizer when the X-coord is all the same.
|
||||||
|
Event::PointerButton {
|
||||||
|
pos: Pos2::new(779.3, 158.6),
|
||||||
|
button: PointerButton::Primary,
|
||||||
|
pressed: true,
|
||||||
|
modifiers: Modifiers::NONE,
|
||||||
|
},
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 159.0)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 160.9)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 164.6)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 169.6)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 175.2)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 180.3)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 185.0)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 189.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 192.8)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 194.9)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 196.1)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 197.0)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 197.6)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 198.1)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 198.5)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 198.8)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 199.0)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 199.2)),
|
||||||
|
Event::PointerMoved(Pos2::new(779.3, 199.2)),
|
||||||
|
Event::PointerButton {
|
||||||
|
pos: Pos2::new(779.3, 199.2),
|
||||||
|
button: PointerButton::Primary,
|
||||||
|
pressed: false,
|
||||||
|
modifiers: Modifiers::NONE,
|
||||||
|
},
|
||||||
|
// --
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 159.2)),
|
||||||
|
Event::PointerButton {
|
||||||
|
pos: Pos2::new(841.5, 159.2),
|
||||||
|
button: PointerButton::Primary,
|
||||||
|
pressed: true,
|
||||||
|
modifiers: Modifiers::NONE,
|
||||||
|
},
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 159.3)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 159.7)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 160.5)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 162.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 165.1)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 168.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 171.6)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 174.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 177.1)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 179.3)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 180.9)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 182.4)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 183.5)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 184.5)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 185.6)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 187.0)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 188.6)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 190.3)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.5, 191.8)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.3, 192.7)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.0, 193.3)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.0, 193.7)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.1, 193.9)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.3, 193.9)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.4, 194.0)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.4, 194.2)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.4, 194.6)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.4, 194.9)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.4, 195.1)),
|
||||||
|
Event::PointerMoved(Pos2::new(841.4, 195.1)),
|
||||||
|
Event::PointerButton {
|
||||||
|
pos: Pos2::new(841.4, 195.1),
|
||||||
|
button: PointerButton::Primary,
|
||||||
|
pressed: false,
|
||||||
|
modifiers: Modifiers::NONE,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
fn from_screen() -> RectTransform {
|
||||||
|
RectTransform::from_to(
|
||||||
|
Rect::from_two_pos(Pos2::new(570.0, 145.1), Pos2::new(1116.4, 245.1)),
|
||||||
|
Rect::from_two_pos(Pos2::new(0.0, 0.0), Pos2::new(546.4, 100.0)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn handle_input() {
|
||||||
|
let mut tool_events = vec![];
|
||||||
|
let mut last_pos = None;
|
||||||
|
let from_screen = from_screen();
|
||||||
|
for event in TEST_EVENTS {
|
||||||
|
process_event(&mut last_pos, from_screen, event, |tool_event| {
|
||||||
|
tool_events.push(tool_event)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
insta::assert_yaml_snapshot!(tool_events);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn input_to_handwriting() {
|
||||||
|
let mut handwriting = Handwriting::default();
|
||||||
|
let mut last_pos = None;
|
||||||
|
let from_screen = from_screen();
|
||||||
|
for event in TEST_EVENTS {
|
||||||
|
process_event(&mut last_pos, from_screen, event, |tool_event| {
|
||||||
|
handwriting.on_tool_event(tool_event);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let serialized = handwriting.to_string();
|
||||||
|
insta::assert_snapshot!("input events to handwriting", serialized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,455 @@
|
|||||||
|
---
|
||||||
|
source: src/handwriting/mod.rs
|
||||||
|
expression: tool_events
|
||||||
|
---
|
||||||
|
- Press:
|
||||||
|
at:
|
||||||
|
x: 179.90002
|
||||||
|
y: 80.5
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 179.90002
|
||||||
|
y: 80.59999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 179.90002
|
||||||
|
y: 81.29999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 180.20001
|
||||||
|
y: 83.29999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 181
|
||||||
|
y: 86.2
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 182.59998
|
||||||
|
y: 89.29999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 184.09998
|
||||||
|
y: 92.59999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 185.79999
|
||||||
|
y: 96
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 187.70001
|
||||||
|
y: 99.29999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 189.3
|
||||||
|
y: 102.29999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 190.8
|
||||||
|
y: 105.09999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 192.79999
|
||||||
|
y: 108.29998
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 195.09998
|
||||||
|
y: 111.69999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 197.70001
|
||||||
|
y: 115.100006
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 201.20001
|
||||||
|
y: 119.19998
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 204.59998
|
||||||
|
y: 122.799995
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 208.20001
|
||||||
|
y: 126.100006
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 212.70001
|
||||||
|
y: 130.1
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 216.70001
|
||||||
|
y: 133.4
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 220.40002
|
||||||
|
y: 135.69998
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 224.09998
|
||||||
|
y: 137.5
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 227.90002
|
||||||
|
y: 138.79999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 231.90002
|
||||||
|
y: 139.69998
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 235.90002
|
||||||
|
y: 140.4
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 240.20001
|
||||||
|
y: 140.69998
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 244.5
|
||||||
|
y: 140.69998
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 248.20001
|
||||||
|
y: 140.5
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 251.59996
|
||||||
|
y: 139.4
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 254.70001
|
||||||
|
y: 137.9
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 257.5
|
||||||
|
y: 136.29999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 260.40002
|
||||||
|
y: 134.5
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 263.40002
|
||||||
|
y: 132.6
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 266.09998
|
||||||
|
y: 130.6
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 268.59998
|
||||||
|
y: 128.5
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 270.90002
|
||||||
|
y: 126.600006
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 273
|
||||||
|
y: 124.5
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 275.40002
|
||||||
|
y: 122.100006
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 277.70004
|
||||||
|
y: 120.00001
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 279.8
|
||||||
|
y: 117.60001
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 282
|
||||||
|
y: 114.899994
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 284.3
|
||||||
|
y: 111.69999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 286.3
|
||||||
|
y: 108.29998
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 288.2
|
||||||
|
y: 104.99999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 290
|
||||||
|
y: 102
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 291.5
|
||||||
|
y: 99.2
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 292.8
|
||||||
|
y: 96.899994
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 294.09995
|
||||||
|
y: 95
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 295
|
||||||
|
y: 93.09999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 295.8
|
||||||
|
y: 91.5
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 296.5
|
||||||
|
y: 89.79999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 297.1
|
||||||
|
y: 88
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 297.8
|
||||||
|
y: 86.29999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 298.40005
|
||||||
|
y: 84.7
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 298.7
|
||||||
|
y: 83.29999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 298.90002
|
||||||
|
y: 82.09999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 299.1
|
||||||
|
y: 81.09999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 299.1
|
||||||
|
y: 80
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 299.1
|
||||||
|
y: 79
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 299.1
|
||||||
|
y: 78.29999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 299.1
|
||||||
|
y: 77.7
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 299.1
|
||||||
|
y: 77.29999
|
||||||
|
- Release
|
||||||
|
- Press:
|
||||||
|
at:
|
||||||
|
x: 209.29999
|
||||||
|
y: 13.500001
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 13.899994
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 15.799988
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 19.5
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 24.5
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 30.09999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 35.199997
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 39.899994
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 44.299988
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 47.699997
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 49.799988
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 51
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 51.899994
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 52.499996
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 52.999996
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 53.399994
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 53.699993
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 53.89999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 54.09999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 209.29999
|
||||||
|
y: 54.09999
|
||||||
|
- Release
|
||||||
|
- Press:
|
||||||
|
at:
|
||||||
|
x: 271.5
|
||||||
|
y: 14.099991
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 14.199998
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 14.599991
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 15.399994
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 17.299988
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 20
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 23.299988
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 26.499998
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 29.299986
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 32
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 34.199997
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 35.799988
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 37.299988
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 38.399994
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 39.399994
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 40.5
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 41.899994
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 43.5
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 45.199997
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.5
|
||||||
|
y: 46.699997
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.3
|
||||||
|
y: 47.59999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271
|
||||||
|
y: 48.199997
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271
|
||||||
|
y: 48.59999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.09998
|
||||||
|
y: 48.799988
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.3
|
||||||
|
y: 48.799988
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.40002
|
||||||
|
y: 48.899994
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.40002
|
||||||
|
y: 49.09999
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.40002
|
||||||
|
y: 49.5
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.40002
|
||||||
|
y: 49.799988
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.40002
|
||||||
|
y: 50
|
||||||
|
- Move:
|
||||||
|
to:
|
||||||
|
x: 271.40002
|
||||||
|
y: 50
|
||||||
|
- Release
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
source: src/handwriting/mod.rs
|
||||||
|
expression: serialized
|
||||||
|
---
|
||||||
|
```handwriting
|
||||||
|
AQA9AJ9ZCFWfWQpVn1kVVaJZNVWoWWNVtVmVVcFZylXOWQBW3lk1VupZZVb2WZJWBlrFVhla+1YuWjJXSlpzV2VarVeCWuJXploRWMZaK1jjWj5YAVtMWB9bVlg/W15YX1tjWIJbZlikW2ZYwltkWN1bW1j2W09YBlxCWBJcNFgeXCVYKFwVWDJcBFg8XOpXRFzIV05coldXXIBXX1xaV2hcLldxXPtWeVzFVoFckFaIXGBWjlwzVpNcDlaYXPBVnFzSVZ9cuFWiXJ1VpFyAVadcZVWqXEtVq1w1VaxcIlWsXBJVrFwAVaxc8FSsXOVUrFzbVKxc1VQTAIpawEqKWvNKilrmS4pa4EyKWiBOilqGT4paZlCKWv1QilqKUYpa9lGKWjpSilpgUopafVKKWpBSilqgUoparVKKWrZSilq9Uopaw1IeAD5cDUs+XBpLPlxNSz5cs0s+XFNMPlwATT5c000+XKBOPlxTTz5cAFA+XEZQPlx6UD5cqlA+XM1QPlztUD5cEFE+XD1RPlxwUT5cplE+XNZRPVzzUTxcBlI8XBNSPFwaUj1cGlI+XB1SPlwjUj5cMFI+XDpSPlxAUg==
|
||||||
|
```
|
||||||
32
src/handwriting/tool/eraser.rs
Normal file
32
src/handwriting/tool/eraser.rs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
use crate::handwriting::{Handwriting, ToolEvent};
|
||||||
|
use egui::Pos2;
|
||||||
|
|
||||||
|
pub const RADIUS: f32 = 12.0;
|
||||||
|
|
||||||
|
/// Handle a [ToolEvent]. Returns true if a stroke was completed.
|
||||||
|
pub fn on_tool_event(handwriting: &mut Handwriting, tool_event: ToolEvent) -> bool {
|
||||||
|
match tool_event {
|
||||||
|
ToolEvent::Press { at } => {
|
||||||
|
erase(handwriting, at, RADIUS)
|
||||||
|
}
|
||||||
|
ToolEvent::Move { to } => {
|
||||||
|
erase(handwriting, to, RADIUS)
|
||||||
|
}
|
||||||
|
ToolEvent::Release => {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn erase(handwriting: &mut Handwriting, at: Pos2, radius: f32) -> bool {
|
||||||
|
let strokes = handwriting.strokes.len();
|
||||||
|
|
||||||
|
handwriting.strokes.retain(|stroke| {
|
||||||
|
stroke.iter().all(|&point| {
|
||||||
|
(point - at).length() > radius
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
handwriting.strokes.len() < strokes
|
||||||
|
}
|
||||||
28
src/handwriting/tool/mod.rs
Normal file
28
src/handwriting/tool/mod.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
pub mod pencil;
|
||||||
|
pub mod eraser;
|
||||||
|
|
||||||
|
use egui::Pos2;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
pub enum Tool {
|
||||||
|
Pencil,
|
||||||
|
Eraser,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A simple event that can defines how a tool (e.g. the pen) is used on a [Handwriting].
|
||||||
|
#[derive(Debug, Serialize, Copy, Clone)]
|
||||||
|
pub enum ToolEvent {
|
||||||
|
Press { at: Pos2 },
|
||||||
|
Move { to: Pos2 },
|
||||||
|
Release,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToolEvent {
|
||||||
|
pub const fn position(&self) -> Option<Pos2> {
|
||||||
|
match self {
|
||||||
|
&ToolEvent::Press { at } => Some(at),
|
||||||
|
&ToolEvent::Move { to } => Some(to),
|
||||||
|
ToolEvent::Release => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/handwriting/tool/pencil.rs
Normal file
22
src/handwriting/tool/pencil.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
use crate::handwriting::{Handwriting, ToolEvent};
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
|
/// Handle a [ToolEvent]. Returns true if a stroke was completed.
|
||||||
|
pub fn on_tool_event(handwriting: &mut Handwriting, tool_event: ToolEvent) -> bool {
|
||||||
|
match tool_event {
|
||||||
|
ToolEvent::Press { at } => {
|
||||||
|
debug_assert!(handwriting.e.current_stroke.is_empty());
|
||||||
|
handwriting.push_to_stroke(at);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
ToolEvent::Move { to } => {
|
||||||
|
handwriting.push_to_stroke(to);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
ToolEvent::Release => {
|
||||||
|
debug_assert!(!handwriting.e.current_stroke.is_empty());
|
||||||
|
handwriting.strokes.push(mem::take(&mut handwriting.e.current_stroke));
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,6 +8,7 @@ pub mod markdown;
|
|||||||
pub mod preferences;
|
pub mod preferences;
|
||||||
pub mod rasterizer;
|
pub mod rasterizer;
|
||||||
pub mod text_editor;
|
pub mod text_editor;
|
||||||
|
pub mod text_styles;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
pub use app::App;
|
pub use app::App;
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
use egui::text::{CCursorRange, LayoutJob};
|
use egui::text::{CCursorRange, LayoutJob};
|
||||||
|
|
||||||
use crate::markdown::Heading;
|
use crate::{
|
||||||
|
markdown::Heading,
|
||||||
|
text_styles::{H1, H1_MONO, H2, H2_MONO, H3, H3_MONO, H4, H4_MONO, H5, H5_MONO, H6, H6_MONO},
|
||||||
|
};
|
||||||
|
|
||||||
use super::{Item, Style, parse};
|
use super::{Item, Style, parse};
|
||||||
|
|
||||||
@ -36,7 +39,6 @@ pub fn highlight_markdown(
|
|||||||
_cursor: Option<CCursorRange>,
|
_cursor: Option<CCursorRange>,
|
||||||
) -> LayoutJob {
|
) -> LayoutJob {
|
||||||
let mut job = LayoutJob::default();
|
let mut job = LayoutJob::default();
|
||||||
|
|
||||||
let code_style = Style {
|
let code_style = Style {
|
||||||
code: true,
|
code: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@ -74,14 +76,23 @@ fn format_from_style(egui_style: &egui::Style, style: &Style) -> egui::text::Tex
|
|||||||
};
|
};
|
||||||
|
|
||||||
let text_style = if let Some(heading) = style.heading {
|
let text_style = if let Some(heading) = style.heading {
|
||||||
match heading {
|
let text_style = match (heading, style.code) {
|
||||||
Heading::H1 => TextStyle::Name("H1".into()),
|
(Heading::H1, false) => H1,
|
||||||
Heading::H2 => TextStyle::Name("H2".into()),
|
(Heading::H2, false) => H2,
|
||||||
Heading::H3 => TextStyle::Name("H3".into()),
|
(Heading::H3, false) => H3,
|
||||||
Heading::H4 => TextStyle::Name("H4".into()),
|
(Heading::H4, false) => H4,
|
||||||
Heading::H5 => TextStyle::Name("H5".into()),
|
(Heading::H5, false) => H5,
|
||||||
Heading::H6 => TextStyle::Name("H6".into()),
|
(Heading::H6, false) => H6,
|
||||||
}
|
|
||||||
|
(Heading::H1, true) => H1_MONO,
|
||||||
|
(Heading::H2, true) => H2_MONO,
|
||||||
|
(Heading::H3, true) => H3_MONO,
|
||||||
|
(Heading::H4, true) => H4_MONO,
|
||||||
|
(Heading::H5, true) => H5_MONO,
|
||||||
|
(Heading::H6, true) => H6_MONO,
|
||||||
|
};
|
||||||
|
|
||||||
|
TextStyle::Name(text_style.into())
|
||||||
} else if style.code {
|
} else if style.code {
|
||||||
TextStyle::Monospace
|
TextStyle::Monospace
|
||||||
} else if style.small | style.raised {
|
} else if style.small | style.raised {
|
||||||
|
|||||||
@ -16,11 +16,6 @@ pub fn parse_tokens<'a>(mut tokens: &[Token<'a>]) -> Vec<Item<'a>> {
|
|||||||
|
|
||||||
let mut style = Style::default();
|
let mut style = Style::default();
|
||||||
|
|
||||||
let mono_style = Style {
|
|
||||||
code: true,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
iter::from_fn(move || {
|
iter::from_fn(move || {
|
||||||
if tokens.is_empty() {
|
if tokens.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
@ -73,7 +68,10 @@ pub fn parse_tokens<'a>(mut tokens: &[Token<'a>]) -> Vec<Item<'a>> {
|
|||||||
any_of([TokenKind::Mono, TokenKind::CodeBlock, TokenKind::Newline]),
|
any_of([TokenKind::Mono, TokenKind::CodeBlock, TokenKind::Newline]),
|
||||||
);
|
);
|
||||||
|
|
||||||
return Some(Item::Text { span, style: mono_style});
|
let mut style = style;
|
||||||
|
style.code = true;
|
||||||
|
|
||||||
|
return Some(Item::Text { span, style });
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: different heading strengths
|
// TODO: different heading strengths
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use egui::{Color32, Context, RichText, Theme, Ui, Visuals};
|
use egui::{Color32, Context, RichText, Theme, Ui, Visuals, style::ScrollAnimation};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
@ -14,7 +14,7 @@ pub struct Preferences {
|
|||||||
pub hide_handwriting_cursor: bool,
|
pub hide_handwriting_cursor: bool,
|
||||||
|
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
has_applied_theme: bool,
|
has_applied_prefs: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Preferences {
|
impl Default for Preferences {
|
||||||
@ -22,7 +22,7 @@ impl Default for Preferences {
|
|||||||
Self {
|
Self {
|
||||||
animations: true,
|
animations: true,
|
||||||
high_contrast: false,
|
high_contrast: false,
|
||||||
has_applied_theme: false,
|
has_applied_prefs: false,
|
||||||
hide_handwriting_cursor: false,
|
hide_handwriting_cursor: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,13 +31,30 @@ impl Default for Preferences {
|
|||||||
impl Preferences {
|
impl Preferences {
|
||||||
/// Apply preferences, if they haven't already been applied.
|
/// Apply preferences, if they haven't already been applied.
|
||||||
pub fn apply(&mut self, ctx: &Context) {
|
pub fn apply(&mut self, ctx: &Context) {
|
||||||
if !self.has_applied_theme {
|
if !self.has_applied_prefs {
|
||||||
self.has_applied_theme = true;
|
self.has_applied_prefs = true;
|
||||||
|
|
||||||
|
let scroll_animation = if self.animations {
|
||||||
|
ScrollAnimation::default()
|
||||||
|
} else {
|
||||||
|
ScrollAnimation::none()
|
||||||
|
};
|
||||||
|
|
||||||
|
for theme in [Theme::Dark, Theme::Light] {
|
||||||
|
ctx.style_mut_of(theme, |style| {
|
||||||
|
style.scroll_animation = scroll_animation;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let mut dark_visuals = Visuals::dark();
|
let mut dark_visuals = Visuals::dark();
|
||||||
let mut light_visuals = Visuals::light();
|
let mut light_visuals = Visuals::light();
|
||||||
|
|
||||||
dark_visuals.code_bg_color = Color32::BLACK;
|
dark_visuals.window_fill = Color32::from_rgb(0x1e, 0x1e, 0x1e);
|
||||||
|
dark_visuals.panel_fill = Color32::from_rgb(0x26, 0x26, 0x26);
|
||||||
|
|
||||||
|
light_visuals.window_fill = Color32::WHITE;
|
||||||
|
light_visuals.panel_fill = Color32::from_rgb(0xf6, 0xf6, 0xf6);
|
||||||
|
|
||||||
dark_visuals.code_bg_color = Color32::BLACK;
|
dark_visuals.code_bg_color = Color32::BLACK;
|
||||||
light_visuals.code_bg_color = Color32::WHITE;
|
light_visuals.code_bg_color = Color32::WHITE;
|
||||||
|
|
||||||
@ -71,11 +88,15 @@ impl Preferences {
|
|||||||
pub fn show(&mut self, ui: &mut Ui) {
|
pub fn show(&mut self, ui: &mut Ui) {
|
||||||
ui.label(RichText::new("Prefs").weak());
|
ui.label(RichText::new("Prefs").weak());
|
||||||
|
|
||||||
ui.toggle_value(&mut self.animations, "Animations");
|
let animations_toggle = ui.toggle_value(&mut self.animations, "Animations");
|
||||||
|
if animations_toggle.clicked() {
|
||||||
|
self.has_applied_prefs = false;
|
||||||
|
self.apply(ui.ctx());
|
||||||
|
}
|
||||||
|
|
||||||
let high_contrast_toggle = ui.toggle_value(&mut self.high_contrast, "High Contrast");
|
let high_contrast_toggle = ui.toggle_value(&mut self.high_contrast, "High Contrast");
|
||||||
if high_contrast_toggle.clicked() {
|
if high_contrast_toggle.clicked() {
|
||||||
self.has_applied_theme = false;
|
self.has_applied_prefs = false;
|
||||||
self.apply(ui.ctx());
|
self.apply(ui.ctx());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
src/text_styles.rs
Normal file
14
src/text_styles.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//! Name of custom [egui::TextStyle]s
|
||||||
|
|
||||||
|
pub const H1: &str = "H1";
|
||||||
|
pub const H2: &str = "H2";
|
||||||
|
pub const H3: &str = "H3";
|
||||||
|
pub const H4: &str = "H4";
|
||||||
|
pub const H5: &str = "H5";
|
||||||
|
pub const H6: &str = "H6";
|
||||||
|
pub const H1_MONO: &str = "H1-mono";
|
||||||
|
pub const H2_MONO: &str = "H2-mono";
|
||||||
|
pub const H3_MONO: &str = "H3-mono";
|
||||||
|
pub const H4_MONO: &str = "H4-mono";
|
||||||
|
pub const H5_MONO: &str = "H5-mono";
|
||||||
|
pub const H6_MONO: &str = "H6-mono";
|
||||||
Reference in New Issue
Block a user