Rename Focus::at to Focus::updated_at in text_input

This commit is contained in:
Héctor Ramón Jiménez 2023-01-12 04:54:34 +01:00
parent 0b86c4a299
commit 502c9bfbf6
No known key found for this signature in database
GPG key ID: 140CC052C94F138E

View file

@ -432,7 +432,10 @@ where
state.is_focused.or_else(|| { state.is_focused.or_else(|| {
let now = Instant::now(); let now = Instant::now();
Some(Focus { at: now, now }) Some(Focus {
updated_at: now,
now,
})
}) })
} else { } else {
None None
@ -564,7 +567,7 @@ where
let message = (on_change)(editor.contents()); let message = (on_change)(editor.contents());
shell.publish(message); shell.publish(message);
focus.at = Instant::now(); focus.updated_at = Instant::now();
return event::Status::Captured; return event::Status::Captured;
} }
@ -575,7 +578,7 @@ where
if let Some(focus) = &mut state.is_focused { if let Some(focus) = &mut state.is_focused {
let modifiers = state.keyboard_modifiers; let modifiers = state.keyboard_modifiers;
focus.at = Instant::now(); focus.updated_at = Instant::now();
match key_code { match key_code {
keyboard::KeyCode::Enter keyboard::KeyCode::Enter
@ -787,7 +790,7 @@ where
focus.now = 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.updated_at).as_millis()
% CURSOR_BLINK_INTERVAL_MILLIS; % CURSOR_BLINK_INTERVAL_MILLIS;
shell.request_redraw( shell.request_redraw(
@ -863,7 +866,8 @@ pub fn draw<Renderer>(
font.clone(), font.clone(),
); );
let is_cursor_visible = ((focus.now - focus.at).as_millis() let is_cursor_visible = ((focus.now - focus.updated_at)
.as_millis()
/ CURSOR_BLINK_INTERVAL_MILLIS) / CURSOR_BLINK_INTERVAL_MILLIS)
% 2 % 2
== 0; == 0;
@ -1007,7 +1011,7 @@ pub struct State {
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
struct Focus { struct Focus {
at: Instant, updated_at: Instant,
now: Instant, now: Instant,
} }
@ -1043,7 +1047,10 @@ 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 { at: now, now }); self.is_focused = Some(Focus {
updated_at: now,
now,
});
self.move_cursor_to_end(); self.move_cursor_to_end();
} }