diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 2bbf8bcbd6..9ddd6a1490 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -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) { diff --git a/Common/UI/View.h b/Common/UI/View.h index b9ccd91fd5..1d9b038f2d 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -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: diff --git a/UI/AdhocServerScreen.cpp b/UI/AdhocServerScreen.cpp index 3106842127..4324ff8241 100644 --- a/UI/AdhocServerScreen.cpp +++ b/UI/AdhocServerScreen.cpp @@ -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") {