TextInput: Added possibility to set function on DropDown icon

This commit is contained in:
YuSanka 2024-01-16 14:33:49 +01:00 committed by David Kocik
parent a336a2c379
commit e92304c6eb
3 changed files with 14 additions and 0 deletions

View File

@ -533,6 +533,8 @@ void OptionsSearcher::set_search_input(TextInput* input_ctrl)
event.Skip();
update_dialog_position();
});
search_input->SetOnDropDownIcon([](){ GUI::wxGetApp().show_search_dialog(); });
}
void OptionsSearcher::add_key(const std::string& opt_key, Preset::Type type, const wxString& group, const wxString& category)

View File

@ -86,6 +86,12 @@ void TextInput::Create(wxWindow * parent,
if (!icon.IsEmpty()) {
this->drop_down_icon = ScalableBitmap(this, icon.ToStdString(), 16);
this->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& event) {
const wxPoint pos = event.GetLogicalPosition(wxClientDC(this));
if (OnClickDropDownIcon && dd_icon_rect.Contains(pos))
OnClickDropDownIcon();
event.Skip();
});
}
messureSize();
}
@ -295,6 +301,7 @@ void TextInput::render(wxDC& dc)
wxSize szIcon = drop_down_icon.GetSize();
pt_r.x -= szIcon.x + 2;
pt_r.y = (size.y - szIcon.y) / 2;
dd_icon_rect = wxRect(pt_r, szIcon);
dc.DrawBitmap(drop_down_icon.get_bitmap(), pt_r);
}

View File

@ -17,6 +17,9 @@ class TextInput : public wxNavigationEnabled<StaticBox>
static const int TextInputWidth = 200;
static const int TextInputHeight = 50;
wxRect dd_icon_rect;
std::function<void()> OnClickDropDownIcon{ nullptr };
public:
TextInput();
@ -73,6 +76,8 @@ public:
void SysColorsChanged();
void SetOnDropDownIcon(std::function<void()> click_drop_down_icon_fn) { OnClickDropDownIcon = click_drop_down_icon_fn; }
protected:
virtual void OnEdit() {}