[text] highlight the text edit widget being edited

This commit is contained in:
Emil Ernerfeldt 2020-08-05 13:59:33 +02:00
parent 2f161dd3d4
commit 81d642b1f1
4 changed files with 23 additions and 3 deletions

View file

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

View file

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

View file

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

View file

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