mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-06-22 19:50:44 +00:00
ENH: vertical layout button
Change-Id: I0b205298688c9df88dcfe6eb6e72cc887a9ed5be Jira: none (cherry picked from commit 56ed912c3ee12fb0ee39f1dad191c4d379aa3015)
This commit is contained in:
@@ -29,10 +29,10 @@ Button::Button()
|
||||
std::make_pair(0xF0F0F1, (int) StateColor::Disabled),
|
||||
std::make_pair(0x52c7b8, (int) StateColor::Hovered | StateColor::Checked),
|
||||
std::make_pair(0x009688, (int) StateColor::Checked),
|
||||
std::make_pair(*wxLIGHT_GREY, (int) StateColor::Hovered),
|
||||
std::make_pair(*wxLIGHT_GREY, (int) StateColor::Hovered),
|
||||
std::make_pair(*wxWHITE, (int) StateColor::Normal));
|
||||
text_color = StateColor(
|
||||
std::make_pair(*wxLIGHT_GREY, (int) StateColor::Disabled),
|
||||
std::make_pair(*wxLIGHT_GREY, (int) StateColor::Disabled),
|
||||
std::make_pair(*wxBLACK, (int) StateColor::Normal));
|
||||
}
|
||||
|
||||
@@ -148,7 +148,12 @@ bool Button::GetValue() const { return state_handler.states() & StateHandler::Ch
|
||||
|
||||
void Button::SetCenter(bool isCenter)
|
||||
{
|
||||
this->isCenter = isCenter;
|
||||
this->isCenter = isCenter; }
|
||||
|
||||
void Button::SetVertical(bool vertical)
|
||||
{
|
||||
this->vertical = vertical;
|
||||
messureSize();
|
||||
}
|
||||
|
||||
// Background Foreground Border on focus
|
||||
@@ -258,26 +263,45 @@ void Button::render(wxDC& dc)
|
||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||
// calc content size
|
||||
wxSize szIcon;
|
||||
wxSize szContent = textSize.GetSize();
|
||||
wxSize textSize = this->textSize.GetSize();
|
||||
|
||||
ScalableBitmap icon;
|
||||
if (m_selected || ((states & (int)StateColor::State::Hovered) != 0))
|
||||
icon = active_icon;
|
||||
else
|
||||
icon = inactive_icon;
|
||||
int padding = 5;
|
||||
wxSize padding = this->paddingSize;
|
||||
int spacing = 5;
|
||||
// Wrap text
|
||||
auto text = GetLabel();
|
||||
if (vertical && textSize.x + padding.x * 2 > size.x) {
|
||||
Label::split_lines(dc, size.x - padding.x * 2, text, text, 2);
|
||||
textSize = dc.GetMultiLineTextExtent(text);
|
||||
if (padding.x * 2 + textSize.x > size.x) {
|
||||
text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, size.x - padding.x * 2);
|
||||
textSize = dc.GetMultiLineTextExtent(text);
|
||||
}
|
||||
}
|
||||
auto szContent = textSize;
|
||||
if (icon.bmp().IsOk()) {
|
||||
if (szContent.y > 0) {
|
||||
//BBS norrow size between text and icon
|
||||
szContent.x += padding;
|
||||
if (vertical)
|
||||
szContent.y += spacing;
|
||||
else
|
||||
szContent.x += spacing;
|
||||
}
|
||||
szIcon = icon.GetBmpSize();
|
||||
szContent.x += szIcon.x;
|
||||
if (szIcon.y > szContent.y)
|
||||
szContent.y = szIcon.y;
|
||||
if (vertical) {
|
||||
szContent.y += szIcon.y;
|
||||
if (szIcon.x > szContent.x) szContent.x = szIcon.x;
|
||||
} else {
|
||||
szContent.x += szIcon.x;
|
||||
if (szIcon.y > szContent.y) szContent.y = szIcon.y;
|
||||
}
|
||||
if (szContent.x > size.x) {
|
||||
int d = std::min(padding, szContent.x - size.x);
|
||||
padding -= d;
|
||||
int d = std::min(padding.x, (szContent.x - size.x) / 2);
|
||||
padding.x -= d;
|
||||
szContent.x -= d;
|
||||
}
|
||||
}
|
||||
@@ -291,17 +315,28 @@ void Button::render(wxDC& dc)
|
||||
// start draw
|
||||
wxPoint pt = rcContent.GetLeftTop();
|
||||
if (icon.bmp().IsOk()) {
|
||||
pt.y += (rcContent.height - szIcon.y) / 2;
|
||||
if (vertical)
|
||||
pt.x += (rcContent.width - szIcon.x) / 2;
|
||||
else
|
||||
pt.y += (rcContent.height - szIcon.y) / 2;
|
||||
dc.DrawBitmap(icon.bmp(), pt);
|
||||
//BBS norrow size between text and icon
|
||||
pt.x += szIcon.x + padding;
|
||||
pt.y = rcContent.y;
|
||||
if (vertical) {
|
||||
pt.y += szIcon.y + spacing;
|
||||
pt.x = rcContent.x;
|
||||
} else {
|
||||
pt.x += szIcon.x + spacing;
|
||||
pt.y = rcContent.y;
|
||||
}
|
||||
}
|
||||
auto text = GetLabel();
|
||||
if (!text.IsEmpty()) {
|
||||
if (pt.x + textSize.width > size.x)
|
||||
text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, size.x - pt.x);
|
||||
pt.y += (rcContent.height - textSize.height) / 2;
|
||||
if (vertical) {
|
||||
pt.x += (rcContent.width - textSize.x) / 2;
|
||||
} else {
|
||||
if (pt.x + textSize.x > size.x)
|
||||
text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, size.x - pt.x);
|
||||
pt.y += (rcContent.height - textSize.y) / 2;
|
||||
}
|
||||
dc.SetTextForeground(text_color.colorForStates(states));
|
||||
#if 0
|
||||
dc.SetBrush(*wxLIGHT_GREY);
|
||||
@@ -323,17 +358,27 @@ void Button::messureSize()
|
||||
if (this->active_icon.bmp().IsOk()) {
|
||||
if (szContent.y > 0) {
|
||||
//BBS norrow size between text and icon
|
||||
szContent.x += 5;
|
||||
if (vertical)
|
||||
szContent.y += 5;
|
||||
else
|
||||
szContent.x += 5;
|
||||
}
|
||||
wxSize szIcon = this->active_icon.GetBmpSize();
|
||||
szContent.x += szIcon.x;
|
||||
if (szIcon.y > szContent.y)
|
||||
szContent.y = szIcon.y;
|
||||
if (vertical) {
|
||||
szContent.y += szIcon.y;
|
||||
if (szIcon.x > szContent.x) szContent.x = szIcon.x;
|
||||
} else {
|
||||
szContent.x += szIcon.x;
|
||||
if (szIcon.y > szContent.y) szContent.y = szIcon.y;
|
||||
}
|
||||
}
|
||||
wxSize size = szContent + paddingSize * 2;
|
||||
if (minSize.GetHeight() > 0)
|
||||
size.SetHeight(minSize.GetHeight());
|
||||
|
||||
if (auto w = GetMaxWidth(); w > 0 && size.GetWidth() > w)
|
||||
size.SetWidth(GetMaxWidth());
|
||||
|
||||
if (minSize.GetWidth() > size.GetWidth())
|
||||
wxWindow::SetMinSize(minSize);
|
||||
else
|
||||
@@ -377,7 +422,7 @@ void Button::keyDownUp(wxKeyEvent &event)
|
||||
return;
|
||||
}
|
||||
if (event.GetEventType() == wxEVT_KEY_DOWN &&
|
||||
(event.GetKeyCode() == WXK_TAB || event.GetKeyCode() == WXK_LEFT || event.GetKeyCode() == WXK_RIGHT
|
||||
(event.GetKeyCode() == WXK_TAB || event.GetKeyCode() == WXK_LEFT || event.GetKeyCode() == WXK_RIGHT
|
||||
|| event.GetKeyCode() == WXK_UP || event.GetKeyCode() == WXK_DOWN))
|
||||
HandleAsNavigationKey(event);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user