Search: Experiment button
This commit is contained in:
parent
ae51f280b8
commit
6a8d0c5d84
4 changed files with 245 additions and 2 deletions
|
@ -362,7 +362,6 @@ void SearchComboPopup::OnKeyDown(wxKeyEvent& event)
|
|||
|
||||
if (key == WXK_UP && selection > 0)
|
||||
selection--;
|
||||
int last_item_id = int(wxListBox::GetCount() - 1);
|
||||
if (key == WXK_DOWN && selection < int(wxListBox::GetCount() - 1))
|
||||
selection++;
|
||||
|
||||
|
@ -479,6 +478,205 @@ void SearchCtrl::OnLeftUpInTextCtrl(wxEvent &event)
|
|||
event.Skip();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------
|
||||
// PopupSearchList
|
||||
//------------------------------------------
|
||||
|
||||
PopupSearchList::PopupSearchList(wxWindow* parent) :
|
||||
wxPopupTransientWindow(parent, /*wxSTAY_ON_TOP*/wxWANTS_CHARS | wxBORDER_NONE)
|
||||
{
|
||||
panel = new wxPanel(this, wxID_ANY);
|
||||
|
||||
text = new wxTextCtrl(panel, 1);
|
||||
list = new wxListBox(panel, 2, wxDefaultPosition, wxSize(GUI::wxGetApp().em_unit() * 40, -1));
|
||||
check = new wxCheckBox(panel, 3, "Group");
|
||||
|
||||
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
text->Bind(wxEVT_MOUSE_CAPTURE_CHANGED, [](wxEvent& e) {
|
||||
int i = 0; });
|
||||
|
||||
// text->Bind(wxEVT_LEFT_DOWN, [this](wxEvent& e) {
|
||||
text->Bind(wxEVT_LEFT_UP, [this](wxEvent& e) {
|
||||
text->SetValue("mrrrrrty");
|
||||
});
|
||||
|
||||
text->Bind(wxEVT_MOTION, [this](wxMouseEvent& evt)
|
||||
{
|
||||
wxPoint pt = wxGetMousePosition() - text->GetScreenPosition();
|
||||
long pos;
|
||||
text->HitTest(pt, &pos);
|
||||
|
||||
if (pos == wxTE_HT_UNKNOWN)
|
||||
return;
|
||||
|
||||
list->SetSelection(wxNOT_FOUND);
|
||||
text->SetSelection(0, pos);
|
||||
});
|
||||
|
||||
text->Bind(wxEVT_TEXT, [this](wxCommandEvent& e)
|
||||
{
|
||||
text->SetSelection(0, 3);
|
||||
});
|
||||
|
||||
this->Bind(wxEVT_KEY_DOWN, [this](wxKeyEvent& event) {
|
||||
int key = event.GetKeyCode();
|
||||
|
||||
// change selected item in the list
|
||||
if (key == WXK_UP || key == WXK_DOWN)
|
||||
{
|
||||
int selection = list->GetSelection();
|
||||
|
||||
if (key == WXK_UP && selection > 0)
|
||||
selection--;
|
||||
if (key == WXK_DOWN && selection < int(list->GetCount() - 1))
|
||||
selection++;
|
||||
|
||||
list->Select(selection);
|
||||
}
|
||||
else
|
||||
event.Skip(); // !Needed to have EVT_CHAR generated as well
|
||||
});
|
||||
|
||||
this->Bind(wxEVT_CHAR, [this](wxKeyEvent& e) {
|
||||
int key = e.GetKeyCode();
|
||||
wxChar symbol = e.GetUnicodeKey();
|
||||
search_str += symbol;
|
||||
|
||||
text->SetValue(search_str);
|
||||
});
|
||||
|
||||
|
||||
list->Append("One");
|
||||
list->Append("Two");
|
||||
list->Append("Three");
|
||||
|
||||
list->Bind(wxEVT_LISTBOX, [this](wxCommandEvent& evt)
|
||||
{
|
||||
int selection = list->GetSelection();
|
||||
});
|
||||
|
||||
list->Bind(wxEVT_LEFT_UP, [this](wxMouseEvent& evt)
|
||||
{
|
||||
int selection = list->GetSelection();
|
||||
list->SetSelection(wxNOT_FOUND);
|
||||
|
||||
wxCommandEvent event(wxEVT_LISTBOX, list->GetId());
|
||||
event.SetInt(selection);
|
||||
event.SetEventObject(this);
|
||||
ProcessEvent(event);
|
||||
|
||||
Dismiss();
|
||||
});
|
||||
|
||||
list->Bind(wxEVT_MOTION, [this](wxMouseEvent& evt)
|
||||
{
|
||||
wxPoint pt = wxGetMousePosition() - list->GetScreenPosition();
|
||||
int selection = list->HitTest(pt);
|
||||
list->Select(selection);
|
||||
});
|
||||
|
||||
list->Bind(wxEVT_KEY_DOWN, [this](wxKeyEvent& event) {
|
||||
int key = event.GetKeyCode();
|
||||
|
||||
// change selected item in the list
|
||||
if (key == WXK_UP || key == WXK_DOWN)
|
||||
{
|
||||
int selection = list->GetSelection();
|
||||
|
||||
if (key == WXK_UP && selection > 0)
|
||||
selection--;
|
||||
if (key == WXK_DOWN && selection < int(list->GetCount() - 1))
|
||||
selection++;
|
||||
|
||||
list->Select(selection);
|
||||
}
|
||||
// send wxEVT_LISTBOX event if "Enter" was pushed
|
||||
else if (key == WXK_NUMPAD_ENTER || key == WXK_RETURN)
|
||||
{
|
||||
int selection = list->GetSelection();
|
||||
|
||||
wxCommandEvent event(wxEVT_LISTBOX, list->GetId());
|
||||
event.SetInt(selection);
|
||||
event.SetEventObject(this);
|
||||
ProcessEvent(event);
|
||||
|
||||
Dismiss();
|
||||
}
|
||||
else
|
||||
event.Skip(); // !Needed to have EVT_CHAR generated as well
|
||||
});
|
||||
|
||||
topSizer->Add(text, 0, wxEXPAND | wxALL, 2);
|
||||
topSizer->Add(list, 0, wxEXPAND | wxALL, 2);
|
||||
topSizer->Add(check, 0, wxEXPAND | wxALL, 2);
|
||||
|
||||
panel->SetSizer(topSizer);
|
||||
|
||||
topSizer->Fit(panel);
|
||||
SetClientSize(panel->GetSize());
|
||||
}
|
||||
|
||||
void PopupSearchList::Popup(wxWindow* WXUNUSED(focus))
|
||||
{
|
||||
wxPopupTransientWindow::Popup();
|
||||
}
|
||||
|
||||
void PopupSearchList::OnDismiss()
|
||||
{
|
||||
wxPopupTransientWindow::OnDismiss();
|
||||
}
|
||||
|
||||
bool PopupSearchList::ProcessLeftDown(wxMouseEvent& event)
|
||||
{
|
||||
return wxPopupTransientWindow::ProcessLeftDown(event);
|
||||
}
|
||||
bool PopupSearchList::Show(bool show)
|
||||
{
|
||||
return wxPopupTransientWindow::Show(show);
|
||||
}
|
||||
|
||||
void PopupSearchList::OnSize(wxSizeEvent& event)
|
||||
{
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void PopupSearchList::OnSetFocus(wxFocusEvent& event)
|
||||
{
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void PopupSearchList::OnKillFocus(wxFocusEvent& event)
|
||||
{
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------
|
||||
// SearchCtrl
|
||||
//------------------------------------------
|
||||
|
||||
SearchButton::SearchButton(wxWindow* parent) :
|
||||
ScalableButton(parent, wxID_ANY, "search")
|
||||
{
|
||||
popup_win = new PopupSearchList(parent);
|
||||
this->Bind(wxEVT_BUTTON, &SearchButton::PopupSearch, this);
|
||||
}
|
||||
|
||||
void SearchButton::PopupSearch(wxCommandEvent& e)
|
||||
{
|
||||
// popup_win->update_list(wxGetApp().sidebar().get_search_list().filters);
|
||||
wxPoint pos = this->ClientToScreen(wxPoint(0, 0));
|
||||
wxSize sz = wxSize(GUI::wxGetApp().em_unit()*40, -1);
|
||||
pos.x -= sz.GetWidth();
|
||||
pos.y += this->GetSize().y;
|
||||
popup_win->Position(pos, sz);
|
||||
popup_win->Popup();
|
||||
e.Skip();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // namespace Slic3r::GUI
|
||||
|
|
|
@ -174,6 +174,47 @@ public:
|
|||
void update_list(const std::vector<FoundOption>& filters);
|
||||
};
|
||||
|
||||
|
||||
#include <wx/popupwin.h>
|
||||
|
||||
class PopupSearchList : public wxPopupTransientWindow
|
||||
{
|
||||
wxString search_str;
|
||||
public:
|
||||
PopupSearchList(wxWindow* parent);
|
||||
~PopupSearchList() {}
|
||||
|
||||
// wxPopupTransientWindow virtual methods are all overridden to log them
|
||||
void Popup(wxWindow* focus = NULL) wxOVERRIDE;
|
||||
void OnDismiss() wxOVERRIDE;
|
||||
bool ProcessLeftDown(wxMouseEvent& event) wxOVERRIDE;
|
||||
bool Show(bool show = true) wxOVERRIDE;
|
||||
|
||||
private:
|
||||
wxWindow* panel;
|
||||
|
||||
wxTextCtrl* text {nullptr};
|
||||
wxListBox* list{ nullptr };
|
||||
wxCheckBox* check {nullptr};
|
||||
|
||||
void OnSize(wxSizeEvent& event);
|
||||
void OnSetFocus(wxFocusEvent& event);
|
||||
void OnKillFocus(wxFocusEvent& event);
|
||||
};
|
||||
|
||||
class SearchButton : public ScalableButton
|
||||
{
|
||||
PopupSearchList* popup_win{ nullptr };
|
||||
|
||||
void PopupSearch(wxCommandEvent& event);
|
||||
public:
|
||||
SearchButton(wxWindow* parent);
|
||||
~SearchButton() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // Search namespace
|
||||
}
|
||||
|
||||
|
|
|
@ -160,6 +160,8 @@ void Tab::create_preset_tab()
|
|||
|
||||
// search combox
|
||||
m_search = new Search::SearchCtrl(panel);
|
||||
// search combox
|
||||
m_search_btn = new Search::SearchButton(panel);
|
||||
|
||||
auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
|
||||
|
||||
|
@ -241,6 +243,8 @@ void Tab::create_preset_tab()
|
|||
m_hsizer->Add(m_undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL);
|
||||
m_hsizer->Add(m_undo_btn, 0, wxALIGN_CENTER_VERTICAL);
|
||||
m_hsizer->AddSpacer(int(/*32*/16 * scale_factor));
|
||||
m_hsizer->Add(m_search_btn, 0, wxALIGN_CENTER_VERTICAL);
|
||||
m_hsizer->AddSpacer(int(/*32*/16 * scale_factor));
|
||||
m_hsizer->Add(m_search, 0, wxALIGN_CENTER_VERTICAL);
|
||||
m_hsizer->AddSpacer(int(16 * scale_factor));
|
||||
// m_hsizer->AddSpacer(int(32 * scale_factor));
|
||||
|
|
|
@ -123,6 +123,7 @@ protected:
|
|||
const wxString m_title;
|
||||
PresetBitmapComboBox* m_presets_choice;
|
||||
Search::SearchCtrl* m_search;
|
||||
Search::SearchButton* m_search_btn;
|
||||
ScalableButton* m_btn_save_preset;
|
||||
ScalableButton* m_btn_delete_preset;
|
||||
ScalableButton* m_btn_hide_incompatible_presets;
|
||||
|
@ -327,7 +328,6 @@ public:
|
|||
|
||||
DynamicPrintConfig* get_config() { return m_config; }
|
||||
PresetCollection* get_presets() { return m_presets; }
|
||||
// SearchComboBox* get_search_cb() { return m_search_cb; }
|
||||
size_t get_selected_preset_item() { return m_selected_preset_item; }
|
||||
|
||||
void set_search_line(const std::string& search_line);
|
||||
|
|
Loading…
Reference in a new issue