FIX: [STUDIO-169] handle text baseline on Mac
Change-Id: I13bde2dcd6d19107f5fe6fb66aa35d2aa55ab03d
This commit is contained in:
parent
cc994a3492
commit
0f152c635c
|
@ -65,6 +65,14 @@ void Button::SetLabel(const wxString& label)
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Button::SetFont(const wxFont& font)
|
||||||
|
{
|
||||||
|
wxWindow::SetFont(font);
|
||||||
|
messureSize();
|
||||||
|
Refresh();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Button::SetIcon(const wxString& icon)
|
void Button::SetIcon(const wxString& icon)
|
||||||
{
|
{
|
||||||
if (!icon.IsEmpty()) {
|
if (!icon.IsEmpty()) {
|
||||||
|
@ -166,7 +174,7 @@ void Button::render(wxDC& dc)
|
||||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
||||||
// calc content size
|
// calc content size
|
||||||
wxSize szIcon;
|
wxSize szIcon;
|
||||||
wxSize szContent = textSize;
|
wxSize szContent = textSize.GetSize();
|
||||||
|
|
||||||
ScalableBitmap icon;
|
ScalableBitmap icon;
|
||||||
if (m_selected || ((states & (int)StateColor::State::Hovered) != 0))
|
if (m_selected || ((states & (int)StateColor::State::Hovered) != 0))
|
||||||
|
@ -205,11 +213,18 @@ void Button::render(wxDC& dc)
|
||||||
}
|
}
|
||||||
auto text = GetLabel();
|
auto text = GetLabel();
|
||||||
if (!text.IsEmpty()) {
|
if (!text.IsEmpty()) {
|
||||||
if (pt.x + textSize.x > size.x)
|
if (pt.x + textSize.width > size.x)
|
||||||
text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, size.x - pt.x);
|
text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, size.x - pt.x);
|
||||||
pt.y += (rcContent.height - textSize.y) / 2;
|
pt.y += (rcContent.height - textSize.height) / 2;
|
||||||
dc.SetFont(GetFont());
|
|
||||||
dc.SetTextForeground(text_color.colorForStates(states));
|
dc.SetTextForeground(text_color.colorForStates(states));
|
||||||
|
#if 0
|
||||||
|
dc.SetBrush(*wxLIGHT_GREY);
|
||||||
|
dc.SetPen(wxPen(*wxLIGHT_GREY));
|
||||||
|
dc.DrawRectangle(pt, textSize.GetSize());
|
||||||
|
#endif
|
||||||
|
#ifdef __WXOSX__
|
||||||
|
pt.y -= textSize.x / 2;
|
||||||
|
#endif
|
||||||
dc.DrawText(text, pt);
|
dc.DrawText(text, pt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,12 +232,12 @@ void Button::render(wxDC& dc)
|
||||||
void Button::messureSize()
|
void Button::messureSize()
|
||||||
{
|
{
|
||||||
wxClientDC dc(this);
|
wxClientDC dc(this);
|
||||||
textSize = dc.GetTextExtent(GetLabel());
|
dc.GetTextExtent(GetLabel(), &textSize.width, &textSize.height, &textSize.x, &textSize.y);
|
||||||
if (minSize.GetWidth() > 0) {
|
if (minSize.GetWidth() > 0) {
|
||||||
wxWindow::SetMinSize(minSize);
|
wxWindow::SetMinSize(minSize);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
wxSize szContent = textSize;
|
wxSize szContent = textSize.GetSize();
|
||||||
if (this->active_icon.bmp().IsOk()) {
|
if (this->active_icon.bmp().IsOk()) {
|
||||||
if (szContent.y > 0) {
|
if (szContent.y > 0) {
|
||||||
//BBS norrow size between text and icon
|
//BBS norrow size between text and icon
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
class Button : public StaticBox
|
class Button : public StaticBox
|
||||||
{
|
{
|
||||||
wxSize textSize;
|
wxRect textSize;
|
||||||
wxSize minSize; // set by outer
|
wxSize minSize; // set by outer
|
||||||
wxSize paddingSize;
|
wxSize paddingSize;
|
||||||
ScalableBitmap active_icon;
|
ScalableBitmap active_icon;
|
||||||
|
@ -30,6 +30,8 @@ public:
|
||||||
|
|
||||||
void SetLabel(const wxString& label) override;
|
void SetLabel(const wxString& label) override;
|
||||||
|
|
||||||
|
bool SetFont(const wxFont& font) override;
|
||||||
|
|
||||||
void SetIcon(const wxString& icon);
|
void SetIcon(const wxString& icon);
|
||||||
|
|
||||||
void SetInactiveIcon(const wxString& icon);
|
void SetInactiveIcon(const wxString& icon);
|
||||||
|
|
Loading…
Reference in New Issue