Avoid reblinking cursor when clicking a focused TextInput
This commit is contained in:
parent
a980024bbf
commit
178bd2d83c
1 changed files with 7 additions and 12 deletions
|
|
@ -429,11 +429,10 @@ where
|
||||||
let is_clicked = layout.bounds().contains(cursor_position);
|
let is_clicked = layout.bounds().contains(cursor_position);
|
||||||
|
|
||||||
state.is_focused = if is_clicked {
|
state.is_focused = if is_clicked {
|
||||||
let now = Instant::now();
|
state.is_focused.or_else(|| {
|
||||||
|
let now = Instant::now();
|
||||||
|
|
||||||
Some(Focus {
|
Some(Focus { at: now, now })
|
||||||
at: now,
|
|
||||||
last_draw: now,
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
@ -785,7 +784,7 @@ where
|
||||||
let state = state();
|
let state = state();
|
||||||
|
|
||||||
if let Some(focus) = &mut state.is_focused {
|
if let Some(focus) = &mut state.is_focused {
|
||||||
focus.last_draw = now;
|
focus.now = now;
|
||||||
|
|
||||||
let millis_until_redraw = CURSOR_BLINK_INTERVAL_MILLIS
|
let millis_until_redraw = CURSOR_BLINK_INTERVAL_MILLIS
|
||||||
- (now - focus.at).as_millis()
|
- (now - focus.at).as_millis()
|
||||||
|
|
@ -864,8 +863,7 @@ pub fn draw<Renderer>(
|
||||||
font.clone(),
|
font.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let is_cursor_visible = ((focus.last_draw - focus.at)
|
let is_cursor_visible = ((focus.now - focus.at).as_millis()
|
||||||
.as_millis()
|
|
||||||
/ CURSOR_BLINK_INTERVAL_MILLIS)
|
/ CURSOR_BLINK_INTERVAL_MILLIS)
|
||||||
% 2
|
% 2
|
||||||
== 0;
|
== 0;
|
||||||
|
|
@ -1010,7 +1008,7 @@ pub struct State {
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
struct Focus {
|
struct Focus {
|
||||||
at: Instant,
|
at: Instant,
|
||||||
last_draw: Instant,
|
now: Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
|
|
@ -1045,10 +1043,7 @@ impl State {
|
||||||
pub fn focus(&mut self) {
|
pub fn focus(&mut self) {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
|
|
||||||
self.is_focused = Some(Focus {
|
self.is_focused = Some(Focus { at: now, now: now });
|
||||||
at: now,
|
|
||||||
last_draw: now,
|
|
||||||
});
|
|
||||||
|
|
||||||
self.move_cursor_to_end();
|
self.move_cursor_to_end();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue