Next experiments with search on Tabs
This commit is contained in:
parent
6faae0aa12
commit
17bd52342b
4
resources/icons/search_gray.svg
Normal file
4
resources/icons/search_gray.svg
Normal file
@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24px" height="24px">
|
||||
<path fill="#808080" d="M 13.261719 14.867188 L 15.742188 17.347656 C 15.363281 18.070313 15.324219 18.789063 15.722656 19.1875 L 20.25 23.714844 C 20.820313 24.285156 22.0625 23.972656 23.015625 23.015625 C 23.972656 22.058594 24.285156 20.820313 23.714844 20.25 L 19.191406 15.722656 C 18.789063 15.324219 18.070313 15.363281 17.347656 15.738281 L 14.867188 13.261719 Z M 8.5 0 C 3.804688 0 0 3.804688 0 8.5 C 0 13.195313 3.804688 17 8.5 17 C 13.195313 17 17 13.195313 17 8.5 C 17 3.804688 13.195313 0 8.5 0 Z M 8.5 15 C 4.910156 15 2 12.089844 2 8.5 C 2 4.910156 4.910156 2 8.5 2 C 12.089844 2 15 4.910156 15 8.5 C 15 12.089844 12.089844 15 8.5 15 Z"/>
|
||||
<path fill="#808080" d="M 13.261719 14.867188 L 19.191406 15.722656 C 18.789063 15.324219 18.070313 15.363281 17.347656 15.738281 M 8.5 0 C 3.804688 0 0 3.804688 0 8.5 C 0 13.195313 3.804688 17 8.5 17 C 13.195313 17 17 13.195313 17 8.5 C 17 3.804688 13.195313 0 8.5 0 Z M 8.5 15 C 4.910156 15 2 12.089844 2 8.5 C 2 4.910156 4.910156 2 8.5 2 C 12.089844 2 15 4.910156 15 8.5 C 15 12.089844 12.089844 15 8.5 15 Z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 1.1 KiB |
@ -194,6 +194,24 @@ public:
|
||||
#else
|
||||
sizer->Add(m_grid_sizer, 0, wxEXPAND | wxALL, wxOSX||!staticbox ? 0: 5);
|
||||
#endif /* __WXGTK__ */
|
||||
|
||||
|
||||
|
||||
if (stb)
|
||||
stb->Bind(wxEVT_PAINT, [this](wxPaintEvent& evt) {
|
||||
evt.Skip();
|
||||
const wxSize sz = stb->GetSize();
|
||||
wxPaintDC dc(stb);
|
||||
const wxPen pen = wxPen(wxColour(250, 10, 10), 2, wxPENSTYLE_SOLID);
|
||||
dc.SetPen(pen);
|
||||
dc.SetBrush(wxBrush(wxColour(250, 0, 0), wxBRUSHSTYLE_SOLID));
|
||||
dc.DrawRectangle(5, 5, sz.x - 5, sz.y - 5);
|
||||
|
||||
HDC hdc = GetHdcOf(dc);
|
||||
RECT dim = { 5, 5, sz.x - 5, sz.y - 5 };
|
||||
::FillRect(hdc, &dim, GetHbrushOf(wxBrush(wxColour( 0, 250,0), wxBRUSHSTYLE_SOLID)));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
wxGridSizer* get_grid_sizer() { return m_grid_sizer; }
|
||||
|
@ -354,7 +354,7 @@ void SearchComboBox::append_items(const wxString& search)
|
||||
//------------------------------------------
|
||||
|
||||
PopupSearchList::PopupSearchList(wxWindow* parent) :
|
||||
wxPopupTransientWindow(parent)
|
||||
wxPopupTransientWindow(parent, wxSTAY_ON_TOP| wxBORDER_NONE)
|
||||
{
|
||||
panel = new wxPanel(this, wxID_ANY);
|
||||
|
||||
@ -367,6 +367,19 @@ PopupSearchList::PopupSearchList(wxWindow* parent) :
|
||||
|
||||
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
wxTextCtrl *text = new wxTextCtrl(panel, wxID_ANY, "Brrrr");
|
||||
text->Bind(wxEVT_ACTIVATE, [](wxEvent& e) {
|
||||
int i=0; });
|
||||
text->Bind(wxEVT_MOUSE_CAPTURE_CHANGED, [](wxEvent& e) {
|
||||
int i = 0; });
|
||||
text->Bind(wxEVT_LEFT_DOWN, [text](wxEvent& e) {
|
||||
text->SetValue("mrrrrrty"); });
|
||||
text->Bind(wxEVT_TEXT, [text](wxCommandEvent& e) {
|
||||
text->SetSelection(2, 3); });
|
||||
text->Bind(wxEVT_CHAR, [text](wxKeyEvent& e) {
|
||||
text->SetFocus(); });
|
||||
|
||||
topSizer->Add(text, 0, wxEXPAND | wxALL, 2);
|
||||
topSizer->Add(search_ctrl, 0, wxEXPAND | wxALL, 2);
|
||||
|
||||
panel->SetSizer(topSizer);
|
||||
@ -432,9 +445,9 @@ void PopupSearchList::update_list(std::vector<SearchOptions::Filter>& filters)
|
||||
|
||||
SearchCtrl::SearchCtrl(wxWindow* parent)
|
||||
{
|
||||
popup_win = new PopupSearchList(parent);
|
||||
// popup_win = new PopupSearchList(parent);
|
||||
box_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
/*
|
||||
search_line = new wxTextCtrl(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(25 * wxGetApp().em_unit(), -1), wxTE_PROCESS_ENTER);
|
||||
search_line->Bind(wxEVT_TEXT, &SearchCtrl::OnInputText, this);
|
||||
search_line->Bind(wxEVT_TEXT_ENTER, &SearchCtrl::PopupList, this);
|
||||
@ -445,6 +458,28 @@ SearchCtrl::SearchCtrl(wxWindow* parent)
|
||||
box_sizer->Add(search_line, 0, wxALIGN_CENTER_VERTICAL);
|
||||
box_sizer->AddSpacer(5);
|
||||
box_sizer->Add(search_btn, 0, wxALIGN_CENTER_VERTICAL);
|
||||
|
||||
*/
|
||||
default_string = _L("Type here to search");
|
||||
|
||||
comboCtrl = new wxComboCtrl(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(25 * wxGetApp().em_unit(), -1), wxTE_PROCESS_ENTER);
|
||||
comboCtrl->UseAltPopupWindow();
|
||||
popupCtrl = new SearchComboPopup();
|
||||
|
||||
// It is important to call SetPopupControl() as soon as possible
|
||||
comboCtrl->SetPopupControl(popupCtrl);
|
||||
wxBitmap bmp_norm = create_scaled_bitmap("search_gray");
|
||||
wxBitmap bmp_hov = create_scaled_bitmap("search");
|
||||
comboCtrl->SetButtonBitmaps(bmp_norm, true, bmp_hov, bmp_hov, bmp_norm);
|
||||
box_sizer->Add(comboCtrl, 0, wxALIGN_CENTER_VERTICAL);
|
||||
|
||||
popupCtrl->Bind(wxEVT_LISTBOX, &SearchCtrl::OnSelect, this);
|
||||
|
||||
comboCtrl->Bind(wxEVT_TEXT, &SearchCtrl::OnInputText, this);
|
||||
comboCtrl->Bind(wxEVT_TEXT_ENTER, &SearchCtrl::PopupList, this);
|
||||
comboCtrl->Bind(wxEVT_COMBOBOX_DROPDOWN, &SearchCtrl::PopupList, this);
|
||||
|
||||
comboCtrl->GetTextCtrl()->Bind(wxEVT_LEFT_DOWN, &SearchCtrl::OnLeftDown, this);
|
||||
}
|
||||
|
||||
SearchCtrl::~SearchCtrl()
|
||||
@ -461,16 +496,20 @@ void SearchCtrl::OnInputText(wxCommandEvent& )
|
||||
{
|
||||
if (prevent_update)
|
||||
return;
|
||||
|
||||
std::string& search_str = wxGetApp().sidebar().get_search_line();
|
||||
search_str = into_u8(search_line->GetValue());
|
||||
// search_str = into_u8(search_line->GetValue());
|
||||
search_str = into_u8(comboCtrl->GetValue());
|
||||
wxGetApp().sidebar().apply_search_filter();
|
||||
|
||||
popup_win->update_list(wxGetApp().sidebar().get_search_list().filters);
|
||||
// popup_win->update_list(wxGetApp().sidebar().get_search_list().filters);
|
||||
|
||||
// update_list(wxGetApp().sidebar().get_search_list().filters);
|
||||
}
|
||||
|
||||
void SearchCtrl::PopupList(wxCommandEvent& )
|
||||
void SearchCtrl::PopupList(wxCommandEvent& e)
|
||||
{
|
||||
popup_win->update_list(wxGetApp().sidebar().get_search_list().filters);
|
||||
/* popup_win->update_list(wxGetApp().sidebar().get_search_list().filters);
|
||||
|
||||
wxPoint pos = search_line->ClientToScreen(wxPoint(0, 0));
|
||||
wxSize sz = search_line->GetSize();
|
||||
@ -478,13 +517,18 @@ void SearchCtrl::PopupList(wxCommandEvent& )
|
||||
popup_win->Position(pos, sz);
|
||||
|
||||
popup_win->Popup();
|
||||
*/
|
||||
update_list(wxGetApp().sidebar().get_search_list().filters);
|
||||
e.Skip();
|
||||
}
|
||||
|
||||
void SearchCtrl::set_search_line(const std::string& line)
|
||||
{
|
||||
prevent_update = true;
|
||||
search_line->SetValue(line.empty() ? _L("Type here to search") : from_u8(line));
|
||||
// search_line->SetValue(line.empty() ? _L("Type here to search") : from_u8(line));
|
||||
comboCtrl->SetText(line.empty() ? default_string : from_u8(line));
|
||||
prevent_update = false;
|
||||
|
||||
}
|
||||
|
||||
void SearchCtrl::msw_rescale()
|
||||
@ -494,7 +538,41 @@ void SearchCtrl::msw_rescale()
|
||||
search_line->SetMinSize(size);
|
||||
// Set rescaled size
|
||||
search_btn->msw_rescale();
|
||||
|
||||
|
||||
comboCtrl->SetButtonBitmaps(create_scaled_bitmap("search"));
|
||||
}
|
||||
|
||||
|
||||
void SearchCtrl::OnSelect(wxCommandEvent& event)
|
||||
{
|
||||
prevent_update = true;
|
||||
|
||||
int selection = event.GetSelection();
|
||||
if (selection >= 0)
|
||||
wxGetApp().sidebar().jump_to_option(selection);
|
||||
|
||||
prevent_update = false;
|
||||
|
||||
comboCtrl->Dismiss();
|
||||
}
|
||||
|
||||
void SearchCtrl::update_list(std::vector<SearchOptions::Filter>& filters)
|
||||
{
|
||||
popupCtrl->Clear();
|
||||
for (const SearchOptions::Filter& item : filters)
|
||||
popupCtrl->Append(item.label);
|
||||
}
|
||||
|
||||
void SearchCtrl::OnLeftDown(wxEvent &event)
|
||||
{
|
||||
const wxString& str = comboCtrl->GetValue();
|
||||
if (!str.IsEmpty() && str == default_string) {
|
||||
prevent_update = true;
|
||||
comboCtrl->SetValue("");
|
||||
prevent_update = false;
|
||||
}
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
}} // namespace Slic3r::GUI
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include <wx/popupwin.h>
|
||||
#include <wx/listctrl.h>
|
||||
|
||||
#include <wx/combo.h>
|
||||
|
||||
#include "Preset.hpp"
|
||||
#include "wxExtensions.hpp"
|
||||
|
||||
@ -147,19 +149,75 @@ private:
|
||||
void OnSelect(wxListEvent& event);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class SearchComboPopup : public wxListBox, public wxComboPopup
|
||||
{
|
||||
public:
|
||||
// Initialize member variables
|
||||
virtual void Init(){}
|
||||
|
||||
// Create popup control
|
||||
virtual bool Create(wxWindow* parent)
|
||||
{
|
||||
return wxListBox::Create(parent, 1, wxPoint(0, 0), wxDefaultSize);
|
||||
}
|
||||
// Return pointer to the created control
|
||||
virtual wxWindow* GetControl() { return this; }
|
||||
// Translate string into a list selection
|
||||
virtual void SetStringValue(const wxString& s)
|
||||
{
|
||||
int n = wxListBox::FindString(s);
|
||||
if (n >= 0 && n < wxListBox::GetCount())
|
||||
wxListBox::Select(n);
|
||||
|
||||
// save a combo control's string
|
||||
m_input_string = s;
|
||||
}
|
||||
// Get list selection as a string
|
||||
virtual wxString GetStringValue() const
|
||||
{
|
||||
// we shouldn't change a combo control's string
|
||||
return m_input_string;
|
||||
}
|
||||
// Do mouse hot-tracking (which is typical in list popups)
|
||||
void OnMouseMove(wxMouseEvent& event)
|
||||
{
|
||||
// TODO: Move selection to cursor
|
||||
}
|
||||
// On mouse left up, set the value and close the popup
|
||||
void OnMouseClick(wxMouseEvent& WXUNUSED(event))
|
||||
{
|
||||
// TODO: Send event as well
|
||||
Dismiss();
|
||||
}
|
||||
protected:
|
||||
wxString m_input_string;
|
||||
};
|
||||
|
||||
|
||||
class SearchCtrl
|
||||
{
|
||||
// wxWindow* parent {nullptr};
|
||||
wxBoxSizer* box_sizer {nullptr};
|
||||
wxTextCtrl* search_line {nullptr};
|
||||
ScalableButton* search_btn {nullptr};
|
||||
PopupSearchList* popup_win {nullptr};
|
||||
|
||||
|
||||
bool prevent_update{ false };
|
||||
wxString default_string;
|
||||
|
||||
void PopupList(wxCommandEvent& event);
|
||||
void OnInputText(wxCommandEvent& event);
|
||||
|
||||
wxComboCtrl* comboCtrl {nullptr};
|
||||
SearchComboPopup* popupCtrl {nullptr};
|
||||
|
||||
void OnSelect(wxCommandEvent& event);
|
||||
void OnLeftDown(wxEvent& event);
|
||||
|
||||
public:
|
||||
SearchCtrl(wxWindow* parent);
|
||||
~SearchCtrl();
|
||||
@ -168,8 +226,12 @@ public:
|
||||
|
||||
void set_search_line(const std::string& search_line);
|
||||
void msw_rescale();
|
||||
|
||||
void update_list(std::vector<SearchOptions::Filter>& filters);
|
||||
};
|
||||
|
||||
|
||||
|
||||
}}
|
||||
|
||||
#endif //slic3r_SearchComboBox_hpp_
|
||||
|
Loading…
Reference in New Issue
Block a user