Skip to content

Commit

Permalink
Fix drag_value.edit_string unexpected reset (#2421)
Browse files Browse the repository at this point in the history
* Fix drag_value.edit_string unexpected reset

  solve issue #2418 #2370

* Also reset drag_value.edit_string on click

* Fix for clippy check
  • Loading branch information
tkkcc authored Dec 10, 2022
1 parent aca3807 commit e7471f1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/egui/src/widgets/drag_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ impl<'a> Widget for DragValue<'a> {
// screen readers.
ui.memory().interested_in_focus(id);
let is_kb_editing = ui.memory().has_focus(id);
if ui.memory().gained_focus(id) {
ui.memory().drag_value.edit_string = None;
}

let old_value = get(&mut get_set_value);
let mut value = old_value;
Expand Down Expand Up @@ -476,7 +479,6 @@ impl<'a> Widget for DragValue<'a> {
ui.memory().drag_value.edit_string = Some(value_text);
response
} else {
ui.memory().drag_value.edit_string = None;
let button = Button::new(
RichText::new(format!("{}{}{}", prefix, value_text.clone(), suffix)).monospace(),
)
Expand All @@ -497,6 +499,7 @@ impl<'a> Widget for DragValue<'a> {
}

if response.clicked() {
ui.memory().drag_value.edit_string = None;
ui.memory().request_focus(id);
} else if response.dragged() {
ui.output().cursor_icon = CursorIcon::ResizeHorizontal;
Expand Down

0 comments on commit e7471f1

Please sign in to comment.