-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
text cursor blink in TextEdit #4121
Changes from 55 commits
b553092
11e31ea
8dd93b4
e56ad08
c6a0fca
61362e5
53991c4
ae48093
f534359
86e0910
f748437
443e68b
5a55d0b
790609c
183500b
8d21de6
6b76c1c
e20c05f
ff68bd2
7ce3353
35704f7
ee4a20b
691308b
bc1e54a
ea247ec
ded8e31
c813943
3c8bc78
8cbe04b
037c4ac
ce54c56
0b3c88e
043ac3f
782fd9d
01675d1
d5fcd5c
55a7c5e
ea89cf6
79eb765
8faf0f5
894fc2f
6ca5eeb
f231579
14ef3f4
f62a193
0ba726e
79dddbf
08daf51
875114f
eb64586
c293e19
956b853
135b88d
9505776
9ee6ca6
ec0f56a
55467b3
a1a3d11
0681300
de4fa6e
0b4ea7f
1600d32
fbabc24
a2eee07
82d3814
24e86d1
d098a8f
27098a1
e50f80d
7dd8226
94f8424
f101c92
837c277
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 | ||
---|---|---|---|---|
|
@@ -728,6 +728,15 @@ pub struct Visuals { | |||
/// show where the text cursor would be if you clicked | ||||
pub text_cursor_preview: bool, | ||||
|
||||
/// set the text cursor to blink | ||||
pub text_cursor_blink: bool, | ||||
|
||||
/// set the text cursor on duration | ||||
pub text_cursor_on_duration: f64, | ||||
|
||||
/// set the text cursor off duration | ||||
pub text_cursor_off_duration: f64, | ||||
|
||||
/// Allow child widgets to be just on the border and still have a stroke with some thickness | ||||
pub clip_rect_margin: f32, | ||||
|
||||
|
@@ -1097,6 +1106,10 @@ impl Visuals { | |||
text_cursor: Stroke::new(2.0, Color32::from_rgb(192, 222, 255)), | ||||
text_cursor_preview: false, | ||||
|
||||
text_cursor_blink: true, | ||||
text_cursor_on_duration: 1.0, | ||||
text_cursor_off_duration: 0.3, | ||||
|
||||
clip_rect_margin: 3.0, // should be at least half the size of the widest frame stroke + max WidgetVisuals::expansion | ||||
button_frame: true, | ||||
collapsing_header_frame: false, | ||||
|
@@ -1581,10 +1594,10 @@ impl Interaction { | |||
impl Widgets { | ||||
pub fn ui(&mut self, ui: &mut crate::Ui) { | ||||
let Self { | ||||
active, | ||||
hovered, | ||||
inactive, | ||||
noninteractive, | ||||
inactive, | ||||
hovered, | ||||
active, | ||||
open, | ||||
} = self; | ||||
|
||||
|
@@ -1739,6 +1752,9 @@ impl Visuals { | |||
resize_corner_size, | ||||
text_cursor, | ||||
text_cursor_preview, | ||||
text_cursor_blink, | ||||
text_cursor_on_duration, | ||||
text_cursor_off_duration, | ||||
clip_rect_margin, | ||||
button_frame, | ||||
collapsing_header_frame, | ||||
|
@@ -1846,6 +1862,15 @@ impl Visuals { | |||
ui.checkbox(text_cursor_preview, "Preview text cursor on hover"); | ||||
ui.add(Slider::new(clip_rect_margin, 0.0..=20.0).text("clip_rect_margin")); | ||||
|
||||
ui.add(Slider::new(resize_corner_size, 0.0..=20.0).text("resize_corner_size")); | ||||
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.
Suggested change
|
||||
ui.checkbox(text_cursor_preview, "Preview text cursor on hover"); | ||||
ui.checkbox(text_cursor_blink, "text cursor to blink"); | ||||
ui.add(Slider::new(text_cursor_on_duration, 0.0..=2.0).text("text cursor on duration")); | ||||
ui.add( | ||||
Slider::new(text_cursor_off_duration, 0.0..=2.0).text("text cursor off duration") | ||||
); | ||||
ui.add(Slider::new(clip_rect_margin, 0.0..=20.0).text("clip_rect_margin")); | ||||
|
||||
ui.checkbox(button_frame, "Button has a frame"); | ||||
ui.checkbox(collapsing_header_frame, "Collapsing header has a frame"); | ||||
ui.checkbox( | ||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -73,3 +73,44 @@ pub fn paint_cursor(painter: &Painter, visuals: &Visuals, cursor_rect: Rect) { | |||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
/// Paint text cursor. | ||||||||||||||||||||||||||||||||||||||
pub fn paint_text_cursor( | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+77
to
+78
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.
|
||||||||||||||||||||||||||||||||||||||
ui: &mut Ui, | ||||||||||||||||||||||||||||||||||||||
painter: &Painter, | ||||||||||||||||||||||||||||||||||||||
primary_cursor_rect: Rect, | ||||||||||||||||||||||||||||||||||||||
is_stay_cursor: bool, | ||||||||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||||||||
let i_time = ui.input(|i| i.time); | ||||||||||||||||||||||||||||||||||||||
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. Currently the cursor still blinks while typing, which is quite annoying. If we instead reset a timer each time the user presses a key, it won't blink until So, I think you were right to put this timer in |
||||||||||||||||||||||||||||||||||||||
let blink_mode = ui.visuals().text_cursor_blink; | ||||||||||||||||||||||||||||||||||||||
let is_blink_mode = blink_mode && is_stay_cursor; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
let on_duration = ui.visuals().text_cursor_on_duration; | ||||||||||||||||||||||||||||||||||||||
let off_duration = ui.visuals().text_cursor_off_duration; | ||||||||||||||||||||||||||||||||||||||
let total_duration = on_duration + off_duration; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
let mut is_cursor_visible = true; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
if is_blink_mode { | ||||||||||||||||||||||||||||||||||||||
is_cursor_visible = (i_time % total_duration) < on_duration; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
if is_cursor_visible { | ||||||||||||||||||||||||||||||||||||||
paint_cursor(painter, ui.visuals(), primary_cursor_rect); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
if is_blink_mode { | ||||||||||||||||||||||||||||||||||||||
if is_cursor_visible { | ||||||||||||||||||||||||||||||||||||||
ui.ctx() | ||||||||||||||||||||||||||||||||||||||
.request_repaint_after(std::time::Duration::from_millis( | ||||||||||||||||||||||||||||||||||||||
(on_duration * 1000.0) as u64, | ||||||||||||||||||||||||||||||||||||||
)); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
if !is_cursor_visible { | ||||||||||||||||||||||||||||||||||||||
ui.ctx() | ||||||||||||||||||||||||||||||||||||||
.request_repaint_after(std::time::Duration::from_millis( | ||||||||||||||||||||||||||||||||||||||
(off_duration * 1000.0) as u64, | ||||||||||||||||||||||||||||||||||||||
)); | ||||||||||||||||||||||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
} |
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.
I think it's time to group all these in a
struct TextCursorStyle
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.
…but I can do that in a later PR