Add ability to set keyboard focus to specific screens. Needed for searchbar on Mac.

This commit is contained in:
Henrik Rydgård committed 2026-05-04 14:29:26 +02:00
1 parent a1f83ca5c4
commit ea4c46f27c
9 files changed
+36 -6

No files matched your search

+9
View File
@@ -949,6 +949,15 @@ ViewGroup *CreateSoftKeyboard(TextEdit *edit, SoftKeyboardState *state) {
return scrollView;
}
TextEditPopupScreen::TextEditPopupScreen(std::string *value, std::string_view placeholder, std::string_view title, int maxLen)
: PopupScreen(title, T(I18NCat::DIALOG, "OK"), T(I18NCat::DIALOG, "Cancel")), value_(value), placeholder_(placeholder), maxLen_(maxLen) {
if (!value_) {
// Point it to our temporary.
value_ = &textEditValue_;
}
}
void TextEditPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
using namespace UI;
UIContext &dc = *screenManager()->getUIContext();
+1 -2
View File
@@ -233,8 +233,7 @@ ViewGroup *CreateSoftKeyboard(TextEdit *edit, SoftKeyboardState *state);
class TextEditPopupScreen : public PopupScreen {
public:
TextEditPopupScreen(std::string *value, std::string_view placeholder, std::string_view title, int maxLen)
: PopupScreen(title, T(I18NCat::DIALOG, "OK"), T(I18NCat::DIALOG, "Cancel")), value_(value), placeholder_(placeholder), maxLen_(maxLen) {}
TextEditPopupScreen(std::string *value, std::string_view placeholder, std::string_view title, int maxLen);
void CreatePopupContents(ViewGroup *parent) override;
const char *tag() const override { return "TextEditPopup"; }
+16 -2
View File
@@ -15,8 +15,22 @@
void Screen::focusChanged(ScreenFocusChange focusChange) {
const char *eventName = "";
switch (focusChange) {
case ScreenFocusChange::FOCUS_LOST_TOP: eventName = "FOCUS_LOST_TOP"; break;
case ScreenFocusChange::FOCUS_BECAME_TOP: eventName = "FOCUS_BECAME_TOP"; break;
case ScreenFocusChange::FOCUS_LOST_TOP:
#if !defined(MOBILE_DEVICE)
if (WantsTextInput()) {
System_NotifyUIEvent(UIEventNotification::TEXT_LOSTFOCUS);
}
#endif
eventName = "FOCUS_LOST_TOP";
break;
case ScreenFocusChange::FOCUS_BECAME_TOP:
#if !defined(MOBILE_DEVICE)
if (WantsTextInput()) {
System_NotifyUIEvent(UIEventNotification::TEXT_GOTFOCUS);
}
#endif
eventName = "FOCUS_BECAME_TOP";
break;
}
DEBUG_LOG(Log::UI, "Screen %s got %s", this->tag(), eventName);
}
+1
View File
@@ -113,6 +113,7 @@ public:
virtual bool isTopLevel() const { return false; }
virtual TouchInput transformTouch(const TouchInput &touch) { return touch; }
virtual bool WantsTextInput() const { return false; }
protected:
int GetRequesterToken();
+1
View File
@@ -75,6 +75,7 @@ public:
virtual UI::Margins RootMargins() const { return UI::Margins(0); }
virtual void focusChanged(ScreenFocusChange focusChange) override {
Screen::focusChanged(focusChange);
modifiersPressed_ = Modifier::NONE;
}
+2
View File
@@ -50,6 +50,8 @@ public:
const char *tag() const override { return "CwCheat"; }
bool WantsTextInput() const override { return true; }
protected:
void BeforeCreateViews() override;
void CreateSettingsViews(UI::ViewGroup *) override;
+1
View File
@@ -52,6 +52,7 @@ public:
bool key(const KeyInput &touch) override;
bool WantsTextInput() const override { return true; }
protected:
ViewLayoutMode LayoutMode() const override { return ViewLayoutMode::IgnoreBottomInset; }
+4 -1
View File
@@ -325,6 +325,10 @@ void SearchBar::Draw(UIContext &dc) {
dc.DrawText(searchFilter_, bounds_.x + leftMargin, bounds_.centerY(), 0xFFFFFFFF, ALIGN_VCENTER);
}
SearchBar::SearchBar(UI::LayoutParams *params) : UI::InertView(params) {
SetVisibility(UI::Visibility::V_GONE);
}
void SearchBar::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
w = 0;
h = 0;
@@ -439,7 +443,6 @@ bool ViewSearch::Key(UI::ViewGroup *viewGroup, const KeyInput &input) {
const int unichar = input.keyCode;
if (unichar >= 0x20 && unichar != 127) { // 127 gets produced from Ctrl+Backspace on Windows for some reason.
// TODO: Save focus state here.
// Insert it! (todo: do it with a string insert)
char buf[8];
buf[u8_wc_toutf8(buf, unichar)] = '\0';
+1 -1
View File
@@ -103,7 +103,7 @@ void AddRotationPicker(ScreenManager *screenManager, UI::ViewGroup *parent, bool
class SearchBar : public UI::InertView {
public:
SearchBar(UI::LayoutParams *params) : UI::InertView(params) { SetVisibility(UI::Visibility::V_GONE); }
SearchBar(UI::LayoutParams *params);
void Draw(UIContext &dc) override;
bool Touch(const TouchInput &input) override;