fix mers, fix space not pausing in idle display

bug that is fixed now:
if a textbox was focused on the main screen,
and then the idle display opened, pressing
spacebar would type a space character into
that textbox (even though the box isnt visible),
and would not trigger pause/resume.
now, the textbox remains unchanged and
the player will pause/resume.
This commit is contained in:
Mark
2024-09-26 21:45:43 +02:00
parent 0d261371b7
commit f41bec1423
12 changed files with 862 additions and 723 deletions

View File

@@ -10,7 +10,7 @@ use speedy2d::{
window::{ModifiersState, MouseButton},
};
use crate::gui::{GuiAction, GuiElem, GuiElemCfg, GuiServerImage};
use crate::gui::{EventInfo, GuiAction, GuiElem, GuiElemCfg, GuiServerImage};
/*
@@ -224,12 +224,24 @@ impl GuiElem for TextField {
g.draw_line(info.pos.top_left(), info.pos.bottom_left(), t, c);
g.draw_line(info.pos.top_right(), info.pos.bottom_right(), t, c);
}
fn mouse_pressed(&mut self, _button: MouseButton) -> Vec<GuiAction> {
self.config.request_keyboard_focus = true;
vec![GuiAction::ResetKeyboardFocus]
fn mouse_pressed(&mut self, e: &mut EventInfo, _button: MouseButton) -> Vec<GuiAction> {
if e.take() {
self.config.request_keyboard_focus = true;
vec![GuiAction::ResetKeyboardFocus]
} else {
vec![]
}
}
fn char_focus(&mut self, modifiers: ModifiersState, key: char) -> Vec<GuiAction> {
if !(modifiers.ctrl() || modifiers.alt() || modifiers.logo()) && !key.is_control() {
fn char_focus(
&mut self,
e: &mut EventInfo,
modifiers: ModifiersState,
key: char,
) -> Vec<GuiAction> {
if !(modifiers.ctrl() || modifiers.alt() || modifiers.logo())
&& !key.is_control()
&& e.take()
{
let content = &mut self.c_input.content;
let was_empty = content.get_text().is_empty();
content.text().push(key);
@@ -249,6 +261,7 @@ impl GuiElem for TextField {
}
fn key_focus(
&mut self,
e: &mut EventInfo,
modifiers: ModifiersState,
down: bool,
key: Option<speedy2d::window::VirtualKeyCode>,
@@ -257,6 +270,7 @@ impl GuiElem for TextField {
if down
&& !(modifiers.alt() || modifiers.logo())
&& key == Some(speedy2d::window::VirtualKeyCode::Backspace)
&& e.take()
{
let content = &mut self.c_input.content;
if !content.get_text().is_empty() {