mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-19 03:13:39 +00:00
simplify solution
This commit is contained in:
@@ -48,31 +48,19 @@ CenteredTitle::CenteredTitle(wxWindow* parent)
|
|||||||
|
|
||||||
dc.SetTextForeground(*wxWHITE);
|
dc.SetTextForeground(*wxWHITE);
|
||||||
|
|
||||||
wxRect rect = GetClientRect();
|
wxFontMetrics fm = dc.GetFontMetrics();
|
||||||
int clientW = rect.GetWidth();
|
int textHeight = fm.ascent + fm.descent;
|
||||||
|
|
||||||
wxFontMetrics fm = dc.GetFontMetrics();
|
wxRect rect = GetClientRect();
|
||||||
int textHeight = fm.ascent + fm.descent;
|
|
||||||
int y = rect.y + (rect.height - textHeight) / 2;
|
|
||||||
|
|
||||||
int fullW = dc.GetTextExtent(m_title).GetWidth();
|
wxString ellipsized = wxControl::Ellipsize(m_title, dc, wxELLIPSIZE_END, rect.GetWidth() - FromDIP(8));
|
||||||
int naturalX = rect.x + (clientW - fullW) / 2;
|
|
||||||
|
|
||||||
// Only update cached x if the shift exceeds 3px threshold to fix shaky text while resizing window and ellipsizing end
|
int y = rect.y + (rect.height - textHeight) / 2;
|
||||||
if (m_cachedX == -1 || std::abs(naturalX - m_cachedX) > FromDIP(3)) {
|
int x = rect.x + (ellipsized != m_title)
|
||||||
m_cachedX = wxMax(rect.x, naturalX);
|
? FromDIP(4) // fixed left when clipped
|
||||||
m_cachedWidth = fullW;
|
: (rect.width - dc.GetTextExtent(m_title).GetWidth()) / 2; // centered when full
|
||||||
}
|
|
||||||
|
|
||||||
wxString text = m_title;
|
dc.DrawText(ellipsized, x, y);
|
||||||
int availW = clientW - FromDIP(8);
|
|
||||||
|
|
||||||
if (fullW > availW) {
|
|
||||||
int availFromCached = rect.x + clientW - m_cachedX - FromDIP(4);
|
|
||||||
text = wxControl::Ellipsize(m_title, dc, wxELLIPSIZE_END, wxMax(availFromCached, FromDIP(20)));
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.DrawText(text, m_cachedX, y);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// repaint for Ellipsize
|
// repaint for Ellipsize
|
||||||
@@ -94,8 +82,6 @@ CenteredTitle::CenteredTitle(wxWindow* parent)
|
|||||||
|
|
||||||
void CenteredTitle::SetTitle(const wxString& title) {
|
void CenteredTitle::SetTitle(const wxString& title) {
|
||||||
m_title = title;
|
m_title = title;
|
||||||
m_cachedX = -1;
|
|
||||||
m_cachedWidth = -1;
|
|
||||||
RefreshRect(GetClientRect());
|
RefreshRect(GetClientRect());
|
||||||
Update();
|
Update();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
wxString m_title;
|
wxString m_title;
|
||||||
mutable int m_cachedX = -1;
|
|
||||||
mutable int m_cachedWidth = -1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class BBLTopbar : public wxAuiToolBar
|
class BBLTopbar : public wxAuiToolBar
|
||||||
|
|||||||
Reference in New Issue
Block a user