Repository navigation
Fix #664, #714: restyle and move selected ink, long-press page menu #741
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3499,6 +3499,10 @@ impl NoteCraftApp { | |
| let unobscured = |at| ctx.layer_id_at(at).is_none_or(|layer| layer.order < egui::Order::Foreground); | ||
| let on_page = |at| page.is_some_and(|page| page.contains(at)) && unobscured(at); | ||
| let on_text = |at| type_tap && self.ink_text_targets.iter().any(|rect| rect.contains(at)); | ||
| // A stylus held still opens the page's menu only where a pen on the page does not draw (#714). | ||
| self.touch.pen_menu = page.is_some() | ||
| && (matches!(self.pointer, ribbon::Pointer::Pick | ribbon::Pointer::Pan) | ||
| || (self.pointer == ribbon::Pointer::Write && !self.auto_switch)); | ||
| let file = self.backstage.is_some() && self.dialog.is_none(); | ||
| let tap = self.touch.route(&mut raw.events, time, |at| { | ||
| if on_page(at) { | ||
|
|
@@ -8848,8 +8852,14 @@ impl NoteCraftApp { | |
| ribbon::Act::InkPointer(p) => self.pointer = p, | ||
| ribbon::Act::InkPen(i) => { | ||
| self.nib = i.min(self.rack.len().saturating_sub(1)); | ||
| self.pointer = ribbon::Pointer::Draw; | ||
| self.remember_rack(); | ||
| // With ink picked up, the pen chosen restyles it, as in OneNote (issue #664): the | ||
| // ink stays picked up and the pointer stays as it was, to go on editing it. | ||
| if self.pad.as_ref().is_some_and(|pad| pad.holding() > 0) { | ||
| self.restyle_held_ink(); | ||
| } else { | ||
| self.pointer = ribbon::Pointer::Draw; | ||
| } | ||
| } | ||
| ribbon::Act::InkRack(edit) => self.edit_rack(edit), | ||
| ribbon::Act::Table(what) => self.edit_table(what), | ||
|
|
@@ -9737,6 +9747,22 @@ impl NoteCraftApp { | |
| }); | ||
| } | ||
|
|
||
| /// Gives the ink picked up the chosen pen's kind, colour and thickness (issue #664), and writes | ||
| /// the drawing. | ||
| fn restyle_held_ink(&mut self) { | ||
| self.take_ink_save(true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pen selection can freeze the UI while held ink saves to slow storage. With ink held, choosing a pen calls The same blocking pattern already exists in other held-ink edits, such as Apply the restyle in memory. Persist the result through the non-waiting background save path that the repository already uses. Keep the save ordered after any pending write so an older completion cannot mark the newer restyle as saved. Scope of the fix
|
||
| let Some(nib) = self.rack.get(self.nib).copied() else { return }; | ||
| let Some(pad) = self.pad.as_mut().filter(|pad| pad.holding() > 0) else { return }; | ||
| if !pad.restyle_held(nib.tool, nib.colour, nib.width()) { | ||
|
Comment on lines
+9755
to
+9756
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restyling held ink can change a locked page. Locking a page sets its editor to read only, and held ink stays held. Pressing Alt+digit then calls Add the same lock check that other edits use. Return before any mutation or save: Suggested fix
With this guard, the pen choice on a locked page makes no change and no save. Give the user a status message for that case. Keep the restyle behavior on unlocked, writable pages.
|
||
| return; | ||
| } | ||
| match pad.save() { | ||
| Ok(()) => self.say(crate::tl_id!("ui.ink_restyled")), | ||
| Err(e) => self.complain(&crate::i18n::format_message_id("ui.cannot_write_the_drawing_error", &[("error", &e.to_string())])), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep save errors visible after a keyboard pen change. When Alt+2 to Alt+9 picks a pen while ink is held, Have the pen selection report whether the restyle save failed. When it failed,
|
||
| } | ||
| self.tell_kept_ink(); | ||
| } | ||
|
|
||
| /// Draw > Rotate (issue #544): turns or mirrors the ink picked up, as one group about its | ||
| /// middle, and writes the drawing. It stays picked up, to be turned again or moved. | ||
| fn turn_ink(&mut self, how: notecraft_ink::pick::Turn) { | ||
|
|
@@ -18590,6 +18616,8 @@ impl NoteCraftApp { | |
| "bounds": self.pad.as_ref().and_then(crate::inkpad::Pad::bounds), | ||
| "gain": self.gain(), | ||
| "strokes": self.pad.as_ref().map(crate::inkpad::Pad::strokes), | ||
| // Each stroke's colour, in order, so a restyle can be seen (issue #664). | ||
| "strokeColours": self.pad.as_ref().map(|p| p.drawing().strokes.iter().map(|s| s.colour.hex()).collect::<Vec<_>>()), | ||
| "inked": self.pad.as_ref().is_some_and(|p| !p.is_empty()), | ||
| // The readings of the newest stroke, in page points (issues #44, #293). | ||
| "lastStroke": self.pad.as_ref().map(crate::inkpad::Pad::last_stroke), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -608,6 +608,27 @@ impl Pad { | |
| self.delete_held() | ||
| } | ||
|
|
||
| /// Gives the held ink a pen's kind, colour and thickness (issue #664) and says whether any | ||
| /// changed. It stays held, and the change is one step for undo. | ||
| pub fn restyle_held(&mut self, tool: Tool, colour: Rgb, width: f32) -> bool { | ||
| let mut changed = false; | ||
| let width = Stroke::new(tool, colour, width).width; | ||
| for &i in &self.held { | ||
| if let Some(stroke) = self.drawing.strokes.get_mut(i) | ||
| && (stroke.tool != tool || stroke.colour != colour || (stroke.width - width).abs() > f32::EPSILON) | ||
| { | ||
| (stroke.tool, stroke.colour, stroke.width) = (tool, colour, width); | ||
| changed = true; | ||
| } | ||
| } | ||
| self.dirty |= changed; | ||
| self.touched |= changed; | ||
| if changed { | ||
| self.settle(); | ||
| } | ||
| changed | ||
| } | ||
|
|
||
| /// Throws away the held ink and says whether any went. | ||
| pub fn delete_held(&mut self) -> bool { | ||
| let went = pick::remove(&mut self.drawing, &self.held) > 0; | ||
|
|
@@ -1046,11 +1067,21 @@ pub fn show( | |
| let colour = ui.visuals().text_color().gamma_multiply(0.6); | ||
| painter.circle_stroke(p, r.max(1.5), egui::Stroke::new(1.0, colour)); | ||
| } | ||
| // Ink the lasso holds is moved, stretched and deleted as in Select (issues #664, #715): its box | ||
| // and its Delete take the pointer over the ink layer, and a press anywhere else draws a new loop. | ||
| let mut held_changed = false; | ||
| if pen.pointer == Pointer::Lasso && pad.loop_now.is_empty() { | ||
| if pad.held.is_empty() { | ||
| ui.data_mut(|d| d.remove::<egui::Rect>(held_area_id())); | ||
| } else { | ||
| held_changed = held_in_write(ui, body, origin, pad, zoom, modal_owns_keys, t); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lasso-selected ink moves boxes that were selected before the lasso. If a box is selected and then a new Lasso loop selects unrelated ink, dragging that ink also moves the box. The shift from Clear the container selection when a Lasso selection forms: Suggested fix
With no box selected, the call does nothing, and dragging lasso-selected ink still moves that ink alone.
|
||
| } | ||
| } | ||
| // Not egui's drag, which only begins once the pointer has travelled far enough: a pen | ||
| // put down and lifted in one place is a dot, and a dot is ink. | ||
| let down = resp.is_pointer_button_down_on(); | ||
| let at = ui.ctx().pointer_interact_pos().filter(|p| body.contains(*p)).map(|p| ((p.x - origin.x) / zoom, (p.y - origin.y) / zoom)); | ||
| let mut changed = false; | ||
| let mut changed = held_changed; | ||
| match pen.pointer { | ||
| Pointer::Erase => { | ||
| if let Some((x, y)) = at.filter(|_| down) { | ||
|
|
@@ -1168,13 +1199,6 @@ pub fn show( | |
| // Write and Pick were answered above, with the page. | ||
| Pointer::Write | Pointer::Pick | Pointer::Pan | Pointer::Laser | Pointer::Eyedropper(_) => {} | ||
| } | ||
| // Ink the lasso holds offers Delete beside it too, for a finger or a mouse (issue #715). | ||
| if pad.loop_now.is_empty() | ||
| && let Some(held) = held_box(pad, origin, zoom) | ||
| && held_delete_button(ui, held, body, t).0 | ||
| { | ||
| changed |= pad.delete_held(); | ||
| } | ||
| // Delete throws away whatever is held, unless the keyboard belongs to a dialog. | ||
| if !modal_owns_keys && !pad.held.is_empty() && ui.input(|i| i.key_pressed(egui::Key::Delete) || i.key_pressed(egui::Key::Backspace)) { | ||
| changed |= pad.delete_held(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A stylus contact restyles held ink instead of drawing.
With automatic switching on, Type can leave ink selected. A stylus that then touches the page calls
InkPen. With held ink, that call restyles the selection and keeps the pointer in Write. The contact does not start a stroke, and the selected ink changes on that touch. The documented auto-pickup behavior requires the pen to draw from its first touch.Keep the restyle for an explicit pen choice. Make the automatic pickup in
switch_by_deviceset the pointer to Draw in every case, as it did before this change. Keep the pen selection and rack memory thatInkPenapplies.