Browse Source

Fix disabled textedit blocking focus shift. (#748)

* Fix disabled textedit blocking focus shift.

Fixes #732. Ui::interact was being called twice for the frame rect
regardless of enabled status which was causing problems for kb focus.
Now the interact function is called zero or one time.

* Apply clippy suggestion

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>

Co-authored-by: Persson <Simon.Persson@nov.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
pull/785/head
Simon Persson 3 years ago
committed by GitHub
parent
commit
7df2408482
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      egui/src/widgets/text_edit.rs

12
egui/src/widgets/text_edit.rs

@ -406,24 +406,26 @@ impl<'t, S: TextBuffer> TextEdit<'t, S> {
impl<'t, S: TextBuffer> Widget for TextEdit<'t, S> { impl<'t, S: TextBuffer> Widget for TextEdit<'t, S> {
fn ui(self, ui: &mut Ui) -> Response { fn ui(self, ui: &mut Ui) -> Response {
let frame = self.frame; let frame = self.frame;
let enabled = self.enabled;
let where_to_put_background = ui.painter().add(Shape::Noop); let where_to_put_background = ui.painter().add(Shape::Noop);
let margin = Vec2::new(4.0, 2.0); let margin = Vec2::new(4.0, 2.0);
let max_rect = ui.available_rect_before_wrap().shrink2(margin); let max_rect = ui.available_rect_before_wrap().shrink2(margin);
let mut content_ui = ui.child_ui(max_rect, *ui.layout()); let mut content_ui = ui.child_ui(max_rect, *ui.layout());
let response = self.content_ui(&mut content_ui); let mut response = self.content_ui(&mut content_ui);
let id = response.id; let id = response.id;
let frame_rect = response.rect.expand2(margin); let frame_rect = response.rect.expand2(margin);
ui.allocate_rect(frame_rect, Sense::hover()); ui.allocate_space(frame_rect.size());
let frame_response = ui.interact(frame_rect, id, Sense::click()); if enabled {
let response = response | frame_response; response |= ui.interact(frame_rect, id, Sense::click())
}
if response.clicked() && !response.lost_focus() { if response.clicked() && !response.lost_focus() {
ui.memory().request_focus(response.id); ui.memory().request_focus(response.id);
} }
if frame { if frame {
let visuals = ui.style().interact(&response); let visuals = ui.style().interact(&response);
let frame_rect = response.rect.expand(visuals.expansion); let frame_rect = frame_rect.expand(visuals.expansion);
let shape = if response.has_focus() { let shape = if response.has_focus() {
epaint::RectShape { epaint::RectShape {
rect: frame_rect, rect: frame_rect,

Loading…
Cancel
Save