Compare commits
1 Commits
master
...
c73f8455e9
| Author | SHA1 | Date | |
|---|---|---|---|
| c73f8455e9 |
@ -76,6 +76,9 @@ pub struct Handwriting {
|
|||||||
struct Ephemeral {
|
struct Ephemeral {
|
||||||
id: Id,
|
id: Id,
|
||||||
|
|
||||||
|
/// Whether the handwriting element is being interacted with.
|
||||||
|
is_focused: bool,
|
||||||
|
|
||||||
/// The stroke that is currently being drawed.
|
/// The stroke that is currently being drawed.
|
||||||
current_stroke: Vec<Pos2>,
|
current_stroke: Vec<Pos2>,
|
||||||
|
|
||||||
@ -163,6 +166,7 @@ impl Default for Ephemeral {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: random_id(),
|
id: random_id(),
|
||||||
|
is_focused: false,
|
||||||
current_stroke: Default::default(),
|
current_stroke: Default::default(),
|
||||||
tessellator: None,
|
tessellator: None,
|
||||||
mesh: Default::default(),
|
mesh: Default::default(),
|
||||||
@ -246,9 +250,16 @@ impl Handwriting {
|
|||||||
// 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();
|
||||||
|
|
||||||
// Is the user in the process of drawing a stroke now?
|
// Is the user in the process of drawing a stroke now?;
|
||||||
let is_drawing = response.interact_pointer_pos().is_some();
|
let is_drawing = response.interact_pointer_pos().is_some();
|
||||||
|
|
||||||
|
if is_drawing {
|
||||||
|
self.e.is_focused = true;
|
||||||
|
} else if ui.ctx().input(|i| i.pointer.any_down()) {
|
||||||
|
// if the user starts interactive with something else, unfocus the handwriting area.
|
||||||
|
self.e.is_focused = false;
|
||||||
|
}
|
||||||
|
|
||||||
if !is_drawing {
|
if !is_drawing {
|
||||||
if was_drawing {
|
if was_drawing {
|
||||||
// commit current line
|
// commit current line
|
||||||
@ -256,12 +267,18 @@ impl Handwriting {
|
|||||||
response.mark_changed();
|
response.mark_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let padding = if self.e.is_focused {
|
||||||
|
HANDWRITING_BOTTOM_PADDING
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
// recalculate how tall the widget should be
|
// recalculate how tall the widget should be
|
||||||
let lines_max_y = self
|
let lines_max_y = self
|
||||||
.strokes
|
.strokes
|
||||||
.iter()
|
.iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
.map(|p| p.y + HANDWRITING_BOTTOM_PADDING)
|
.map(|p| p.y + padding)
|
||||||
.fold(HANDWRITING_MIN_HEIGHT, |max, y| max.max(y));
|
.fold(HANDWRITING_MIN_HEIGHT, |max, y| max.max(y));
|
||||||
|
|
||||||
// Change the height of the handwriting item.
|
// Change the height of the handwriting item.
|
||||||
|
|||||||
Reference in New Issue
Block a user