Browse Source

[text] highlight the text edit widget being edited

pull/15/head
Emil Ernerfeldt 4 years ago
parent
commit
81d642b1f1
  1. 9
      egui/src/context.rs
  2. 6
      egui/src/style.rs
  3. 9
      egui/src/types.rs
  4. 2
      egui/src/ui.rs

9
egui/src/context.rs

@ -337,6 +337,9 @@ impl Context {
) -> InteractInfo {
let interact_rect = rect.expand2(0.5 * self.style().item_spacing); // make it easier to click. TODO: nice way to do this
let hovered = self.contains_mouse(layer, clip_rect, interact_rect);
let has_kb_focus = interaction_id
.map(|id| self.memory().has_kb_focus(id))
.unwrap_or(false);
if interaction_id.is_none() || sense == Sense::nothing() {
// Not interested in input:
@ -347,6 +350,7 @@ impl Context {
clicked: false,
double_clicked: false,
active: false,
has_kb_focus,
};
}
let interaction_id = interaction_id.unwrap();
@ -368,6 +372,7 @@ impl Context {
clicked: false,
double_clicked: false,
active: false,
has_kb_focus,
};
if sense.click && memory.interaction.click_id.is_none() {
@ -396,6 +401,7 @@ impl Context {
clicked: false,
double_clicked: false,
active: false,
has_kb_focus,
}
}
} else if self.input.mouse.released {
@ -407,6 +413,7 @@ impl Context {
clicked,
double_clicked: clicked && self.input.mouse.double_click,
active,
has_kb_focus,
}
} else if self.input.mouse.down {
InteractInfo {
@ -416,6 +423,7 @@ impl Context {
clicked: false,
double_clicked: false,
active,
has_kb_focus,
}
} else {
InteractInfo {
@ -425,6 +433,7 @@ impl Context {
clicked: false,
double_clicked: false,
active,
has_kb_focus,
}
}
}

6
egui/src/style.rs

@ -149,10 +149,10 @@ impl Default for Interact {
impl Interact {
pub fn style(&self, interact: &InteractInfo) -> &WidgetStyle {
if interact.sense == Sense::nothing() {
&self.disabled
} else if interact.active {
if interact.active || interact.has_kb_focus {
&self.active
} else if interact.sense == Sense::nothing() {
&self.disabled
} else if interact.hovered {
&self.hovered
} else {

9
egui/src/types.rs

@ -66,6 +66,9 @@ pub struct InteractInfo {
/// The mouse is interacting with this thing (e.g. dragging it or holding it)
pub active: bool,
/// This widget has the keyboard focus (i.e. is receiving key pressed)
pub has_kb_focus: bool,
/// The region of the screen we are talking about
pub rect: Rect,
}
@ -78,6 +81,7 @@ impl InteractInfo {
clicked: false,
double_clicked: false,
active: false,
has_kb_focus: false,
rect: Rect::nothing(),
}
}
@ -89,6 +93,7 @@ impl InteractInfo {
clicked: self.clicked || other.clicked,
double_clicked: self.double_clicked || other.double_clicked,
active: self.active || other.active,
has_kb_focus: self.has_kb_focus || other.has_kb_focus,
rect: self.rect.union(other.rect),
}
}
@ -115,6 +120,9 @@ pub struct GuiResponse {
/// The mouse is interacting with this thing (e.g. dragging it)
pub active: bool,
/// This widget has the keyboard focus (i.e. is receiving key pressed)
pub has_kb_focus: bool,
/// The area of the screen we are talking about
pub rect: Rect,
@ -147,6 +155,7 @@ impl Into<InteractInfo> for GuiResponse {
clicked: self.clicked,
double_clicked: self.double_clicked,
active: self.active,
has_kb_focus: self.has_kb_focus,
rect: self.rect,
}
}

2
egui/src/ui.rs

@ -336,6 +336,7 @@ impl Ui {
clicked,
double_clicked,
active,
has_kb_focus,
rect,
} = interact;
GuiResponse {
@ -344,6 +345,7 @@ impl Ui {
clicked,
double_clicked,
active,
has_kb_focus,
rect,
ctx: self.ctx().clone(),
}

Loading…
Cancel
Save