mirror of
https://git.mirrors.martin98.com/https://github.com/bambulab/BambuStudio.git
synced 2025-09-28 18:23:14 +08:00
ENH: support DD_ITEM_STYLE_SPLIT_ITEM
jira: [STUDIO-12103] Change-Id: Ic69b5076543066ad00bb0d13ffb4d13b57873d3a
This commit is contained in:
parent
18a09d3614
commit
de14cfbac6
@ -188,21 +188,23 @@ bool ComboBox::SetFont(wxFont const& font)
|
|||||||
return TextInput::SetFont(font);
|
return TextInput::SetFont(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ComboBox::Append(const wxString &item, const wxBitmap &bitmap)
|
int ComboBox::Append(const wxString &item, const wxBitmap &bitmap, int style)
|
||||||
{
|
{
|
||||||
return Append(item, bitmap, nullptr);
|
return Append(item, bitmap, nullptr, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ComboBox::Append(const wxString &text,
|
int ComboBox::Append(const wxString &text,
|
||||||
const wxBitmap &bitmap,
|
const wxBitmap &bitmap,
|
||||||
void * clientData)
|
void * clientData,
|
||||||
|
int style)
|
||||||
{
|
{
|
||||||
return Append(text, bitmap, wxString{}, clientData);
|
return Append(text, bitmap, wxString{}, clientData, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ComboBox::Append(const wxString &text, const wxBitmap &bitmap, const wxString &group, void *clientData)
|
int ComboBox::Append(const wxString &text, const wxBitmap &bitmap, const wxString &group, void *clientData, int style)
|
||||||
{
|
{
|
||||||
Item item{text, wxEmptyString, bitmap, bitmap, clientData, group};
|
Item item{text, wxEmptyString, bitmap, bitmap, clientData, group };
|
||||||
|
item.style = style;
|
||||||
items.push_back(item);
|
items.push_back(item);
|
||||||
SetClientDataType(wxClientData_Void);
|
SetClientDataType(wxClientData_Void);
|
||||||
drop.Invalidate();
|
drop.Invalidate();
|
||||||
|
@ -34,11 +34,9 @@ public:
|
|||||||
virtual bool SetFont(wxFont const & font) override;
|
virtual bool SetFont(wxFont const & font) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int Append(const wxString &item, const wxBitmap &bitmap = wxNullBitmap);
|
int Append(const wxString &item, const wxBitmap &bitmap = wxNullBitmap, int item_style = 0);
|
||||||
|
int Append(const wxString &item, const wxBitmap &bitmap, void *clientData, int item_style = 0);
|
||||||
int Append(const wxString &item, const wxBitmap &bitmap, void *clientData);
|
int Append(const wxString &item, const wxBitmap &bitmap, const wxString &group, void *clientData = nullptr, int item_style = 0);
|
||||||
|
|
||||||
int Append(const wxString &item, const wxBitmap &bitmap, const wxString &group, void *clientData = nullptr);
|
|
||||||
|
|
||||||
int SetItems(const std::vector<DropDown::Item>& the_items);
|
int SetItems(const std::vector<DropDown::Item>& the_items);
|
||||||
|
|
||||||
|
@ -197,6 +197,54 @@ static wxSize GetBmpSize(wxBitmap & bmp)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _DrawSplitItem(const wxWindow* w, wxDC& dc, wxString split_text, wxPoint start_pt, int item_width, int item_height)
|
||||||
|
{
|
||||||
|
// save dc
|
||||||
|
auto pre_clr = dc.GetTextForeground();
|
||||||
|
auto pre_pen = dc.GetPen();
|
||||||
|
dc.SetTextForeground(wxColour(144, 144, 144));
|
||||||
|
dc.SetPen(wxColour(144, 144, 144));
|
||||||
|
|
||||||
|
// miner font
|
||||||
|
auto font = w->GetFont();
|
||||||
|
font.SetPointSize(font.GetPointSize() - 1);
|
||||||
|
dc.SetFont(font);
|
||||||
|
|
||||||
|
int spacing = w->FromDIP(8);
|
||||||
|
int line_y = start_pt.y + (item_height) / 2;
|
||||||
|
if (!split_text.empty())// Paiting: spacing + line + spacing + text + spacing + line + spacing
|
||||||
|
{
|
||||||
|
int max_content_width = item_width - start_pt.x - 4 * spacing;
|
||||||
|
wxSize tSize = dc.GetMultiLineTextExtent(split_text);
|
||||||
|
if (tSize.x > max_content_width)
|
||||||
|
{
|
||||||
|
split_text = wxControl::Ellipsize(split_text, dc, wxELLIPSIZE_END, max_content_width);
|
||||||
|
tSize = dc.GetMultiLineTextExtent(split_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
int line_width = (item_width - start_pt.x - tSize.x - 4 * spacing) / 2;
|
||||||
|
dc.DrawLine(start_pt.x + spacing, line_y, start_pt.x + line_width + spacing, line_y);// draw left line
|
||||||
|
dc.DrawLine(start_pt.x + tSize.x + line_width + 3 * spacing, line_y, start_pt.x + tSize.x + 2 * line_width + 3 * spacing, line_y);// draw right line
|
||||||
|
|
||||||
|
start_pt.x += (line_width + 2 * spacing);
|
||||||
|
start_pt.y += (item_height - tSize.y) / 2;
|
||||||
|
|
||||||
|
dc.SetFont(font);
|
||||||
|
dc.DrawText(split_text, start_pt);
|
||||||
|
}
|
||||||
|
else// Paiting: spacing + line + spacing
|
||||||
|
{
|
||||||
|
int line_y = start_pt.y + (item_height) / 2;
|
||||||
|
int line_width = item_width - start_pt.x - 2 * spacing;
|
||||||
|
dc.DrawLine(start_pt.x + spacing, line_y, start_pt.x + spacing + line_width, line_y);// draw line
|
||||||
|
}
|
||||||
|
|
||||||
|
// restore dc
|
||||||
|
dc.SetTextForeground(pre_clr);
|
||||||
|
dc.SetPen(pre_pen);
|
||||||
|
dc.SetFont(w->GetFont());
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Here we do the actual rendering. I put it in a separate
|
* Here we do the actual rendering. I put it in a separate
|
||||||
* method so that it can work no matter what type of DC
|
* method so that it can work no matter what type of DC
|
||||||
@ -224,7 +272,7 @@ void DropDown::render(wxDC &dc)
|
|||||||
|
|
||||||
// draw hover rectangle
|
// draw hover rectangle
|
||||||
wxRect rcContent = {{0, offset.y}, rowSize};
|
wxRect rcContent = {{0, offset.y}, rowSize};
|
||||||
if (hover_item >= 0 && (states & StateColor::Hovered)) {
|
if (hover_item >= 0 && (states & StateColor::Hovered) && !(items[hover_item].style & DD_ITEM_STYLE_SPLIT_ITEM)) {
|
||||||
rcContent.y += rowSize.y * hover_item;
|
rcContent.y += rowSize.y * hover_item;
|
||||||
if (rcContent.GetBottom() > 0 && rcContent.y < size.y) {
|
if (rcContent.GetBottom() > 0 && rcContent.y < size.y) {
|
||||||
if (selected_item == hover_item)
|
if (selected_item == hover_item)
|
||||||
@ -307,6 +355,16 @@ void DropDown::render(wxDC &dc)
|
|||||||
}
|
}
|
||||||
if (rcContent.y > size.y) break;
|
if (rcContent.y > size.y) break;
|
||||||
wxPoint pt = rcContent.GetLeftTop();
|
wxPoint pt = rcContent.GetLeftTop();
|
||||||
|
|
||||||
|
if (item.style & DD_ITEM_STYLE_SPLIT_ITEM) {
|
||||||
|
wxPoint start_pt = {0 , pt.y};
|
||||||
|
int item_width = GetSize().GetWidth();
|
||||||
|
int item_height = rowSize.GetHeight();
|
||||||
|
_DrawSplitItem(this, dc, item.text, start_pt, item_width, item_height);
|
||||||
|
rcContent.y += item_height;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
auto & icon = item.icon;
|
auto & icon = item.icon;
|
||||||
auto size2 = GetBmpSize(icon);
|
auto size2 = GetBmpSize(icon);
|
||||||
if (iconSize.x > 0) {
|
if (iconSize.x > 0) {
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#define DD_NO_TEXT 0x0002
|
#define DD_NO_TEXT 0x0002
|
||||||
#define DD_STYLE_MASK 0x0003
|
#define DD_STYLE_MASK 0x0003
|
||||||
|
|
||||||
|
#define DD_ITEM_STYLE_SPLIT_ITEM 0x0001 // ----text----, text with horizontal line arounds
|
||||||
|
|
||||||
wxDECLARE_EVENT(EVT_DISMISS, wxCommandEvent);
|
wxDECLARE_EVENT(EVT_DISMISS, wxCommandEvent);
|
||||||
|
|
||||||
class DropDown : public PopupWindow
|
class DropDown : public PopupWindow
|
||||||
@ -27,6 +29,7 @@ public:
|
|||||||
wxString alias{};
|
wxString alias{};
|
||||||
wxString tip{};
|
wxString tip{};
|
||||||
int flag{0};
|
int flag{0};
|
||||||
|
int style{ 0 };// the style of item
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user