Not super pretty, but implements keyboard navigation for the adhoc server list

This commit is contained in:
Henrik Rydgård
2026-03-15 14:43:28 +01:00
parent 672eba3625
commit 3352df3ae7
3 changed files with 39 additions and 1 deletions
+30
View File
@@ -1201,6 +1201,36 @@ bool ClickableTextView::Touch(const TouchInput &input) {
return contains;
}
bool ClickableTextView::Key(const KeyInput &key) {
if (!HasFocus() && key.deviceId != DEVICE_ID_MOUSE) {
down_ = false;
return false;
}
// TODO: Replace most of Update with this.
bool ret = false;
if (key.flags & KeyInputFlags::DOWN) {
if (IsAcceptKey(key)) {
down_ = true;
ret = true;
}
}
if (key.flags & KeyInputFlags::UP) {
if (IsAcceptKey(key)) {
if (down_) {
EventParams e{};
e.v = this;
OnClick.Trigger(e);
down_ = false;
ret = true;
}
} else if (down_ && IsEscapeKey(key)) {
down_ = false;
}
}
return ret;
}
TextEdit::TextEdit(std::string_view text, std::string_view title, std::string_view placeholderText, LayoutParams *layoutParams)
: View(layoutParams), text_(text), title_(title), undo_(text), placeholderText_(placeholderText),
textColor_(0xFFFFFFFF), maxLen_(255) {
+2
View File
@@ -1086,6 +1086,8 @@ public:
ClickableTextView(std::string_view text, LayoutParams *layoutParams = 0)
: TextView(text, layoutParams) {}
bool Touch(const TouchInput &input) override;
bool Key(const KeyInput &input) override;
Event OnClick;
private:
+7 -1
View File
@@ -223,7 +223,13 @@ AdhocServerRow::AdhocServerRow(std::string *editValue, const AdhocServerListEntr
LinearLayout *lines = Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(Margins(5, 5))));
lines->SetSpacing(0.0f);
lines->Add(new TextView(entry.name));
ClickableTextView *name = lines->Add(new ClickableTextView(entry.name));
name->SetFocusable(true);
name->OnClick.Add([this](UI::EventParams &e) {
EventParams e2;
e2.v = this;
OnSelected.Trigger(e2);
});
std::string secondLine = entry.host;
if (entry.host == "localhost") {