Previously text boxes could only be focused by cycling through focus with the tab key, now you can click with the mouse as well.
This commit is contained in:
parent
2f08e14b1c
commit
4dd25de709
|
@ -379,10 +379,19 @@ impl Container {
|
||||||
let mx = (x / width) * SCALED_WIDTH;
|
let mx = (x / width) * SCALED_WIDTH;
|
||||||
let my = (y / height) * SCALED_HEIGHT;
|
let my = (y / height) * SCALED_HEIGHT;
|
||||||
|
|
||||||
|
let mut clicked_element: Option<&Element> = None;
|
||||||
for e in &self.elements {
|
for e in &self.elements {
|
||||||
let r = Self::compute_draw_region(e, sw, sh, &SCREEN);
|
let r = Self::compute_draw_region(e, sw, sh, &SCREEN);
|
||||||
if mx >= r.x && mx <= r.x + r.w && my >= r.y && my <= r.y + r.h {
|
if mx >= r.x && mx <= r.x + r.w && my >= r.y && my <= r.y + r.h {
|
||||||
e.click_at(&r, game, mx, my, sw, sh);
|
e.click_at(&r, game, mx, my, sw, sh);
|
||||||
|
clicked_element = Some(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(e) = clicked_element {
|
||||||
|
if let Element::TextBox(_) = e {
|
||||||
|
self.clear_focus();
|
||||||
|
e.set_focused(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -391,6 +400,12 @@ impl Container {
|
||||||
self.focusable_elements.push(el);
|
self.focusable_elements.push(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn clear_focus(&self) {
|
||||||
|
for e in &self.elements {
|
||||||
|
e.set_focused(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn cycle_focus(&mut self) {
|
pub fn cycle_focus(&mut self) {
|
||||||
if self.focusable_elements.is_empty() {
|
if self.focusable_elements.is_empty() {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue