mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-14 00:52:04 +00:00
Support longer project names on title and fix window buttons not visible on minimum window size (#12730)
fixes https://github.com/OrcaSlicer/OrcaSlicer/issues/12723 tested on windows, ubuntu ## CHANGES • Created a painted control because AddLabel method has fixed size. **new control expands and uses all available space** • removed invisible publish button to get perfect center. i assume this feature already not in use on orca ## WINDOW BUTTONS NOT VISIBLE ON MINIMUM WINDOW WIDTH • This issue only exist on windows **Before**- causes window buttons not fitting to frame. **After** - all fits to frame <img width="759" height="203" alt="Screenshot-20260311141345" src="https://github.com/user-attachments/assets/99da00ea-48f9-449b-9dd0-0bd023e041d8" /> ## ADDS SUPPORT FOR LONGER PROJECT NAMES **Before** - title not showing all name because it has a fixed size with 300px **After** - shows all name because it uses all available space <img width="1263" height="216" alt="Screenshot-20260311141612" src="https://github.com/user-attachments/assets/f0b4d16a-882f-46c0-8918-d0b8a7c34007" /> ## ELLIPSIZES LONG NAMES WHEN REQURIED **Before** - method was static  **After** - supports longer names and ellipsizes end dynamically  ## FIXES THIN TITLEBAR ON LINUX Left windows Right one Linux **Before - Linux titlebar uses less height for titlebar** <img width="806" height="84" alt="Screenshot-20260312013547" src="https://github.com/user-attachments/assets/3507016c-e46b-4fb1-86de-29978ee48e2b" /> **After- Heights almost matches** <img width="819" height="110" alt="Screenshot-20260312013531" src="https://github.com/user-attachments/assets/3b28d32b-d054-406e-85bc-939609ba1aef" />
This commit is contained in:
@@ -36,42 +36,67 @@ enum CUSTOM_ID
|
||||
ID_AMS_NOTEBOOK,
|
||||
};
|
||||
|
||||
CenteredTitle::CenteredTitle(wxWindow* parent)
|
||||
: wxControl()
|
||||
{
|
||||
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
||||
Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
|
||||
Bind(wxEVT_PAINT, [this](wxPaintEvent&) {
|
||||
wxBufferedPaintDC dc(this);
|
||||
dc.SetBackground(wxBrush(wxColour(38, 46, 48)));
|
||||
dc.Clear();
|
||||
|
||||
dc.SetTextForeground(*wxWHITE);
|
||||
|
||||
wxFontMetrics fm = dc.GetFontMetrics();
|
||||
int textHeight = fm.ascent + fm.descent;
|
||||
|
||||
wxRect rect = GetClientRect();
|
||||
wxString ellipsized = wxControl::Ellipsize(m_title, dc, wxELLIPSIZE_END, wxMax(0, rect.GetWidth() - FromDIP(8)));
|
||||
|
||||
int y = rect.y + (rect.height - textHeight) / 2;
|
||||
int x = rect.x + (ellipsized != m_title) // is ellipsized
|
||||
? FromDIP(4) // align to left when clipped
|
||||
: (rect.width - dc.GetTextExtent(m_title).GetWidth()) / 2; // centered when has available space
|
||||
|
||||
dc.DrawText(ellipsized, x, y);
|
||||
});
|
||||
|
||||
// repaint for Ellipsize
|
||||
Bind(wxEVT_SIZE, [this](wxSizeEvent& e) {
|
||||
Refresh();
|
||||
e.Skip();
|
||||
});
|
||||
|
||||
auto forwardMouseEvent = [this](wxMouseEvent& e) {
|
||||
if (e.LeftDown() && e.GetClickCount() > 1) return; // prevent duplicate event
|
||||
e.SetPosition(GetParent()->ScreenToClient(ClientToScreen(e.GetPosition())));
|
||||
GetParent()->GetEventHandler()->ProcessEvent(e);
|
||||
};
|
||||
|
||||
Bind(wxEVT_LEFT_DOWN, forwardMouseEvent);
|
||||
Bind(wxEVT_LEFT_DCLICK, forwardMouseEvent);
|
||||
}
|
||||
|
||||
void CenteredTitle::SetTitle(const wxString& title) {
|
||||
m_title = title;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
// required for proper height
|
||||
wxSize CenteredTitle::DoGetBestSize() const
|
||||
{
|
||||
return wxSize(10, FromDIP(30));
|
||||
}
|
||||
|
||||
|
||||
class BBLTopbarArt : public wxAuiDefaultToolBarArt
|
||||
{
|
||||
public:
|
||||
virtual void DrawLabel(wxDC& dc, wxWindow* wnd, const wxAuiToolBarItem& item, const wxRect& rect) wxOVERRIDE;
|
||||
virtual void DrawBackground(wxDC& dc, wxWindow* wnd, const wxRect& rect) wxOVERRIDE;
|
||||
virtual void DrawButton(wxDC& dc, wxWindow* wnd, const wxAuiToolBarItem& item, const wxRect& rect) wxOVERRIDE;
|
||||
};
|
||||
|
||||
void BBLTopbarArt::DrawLabel(wxDC& dc, wxWindow* wnd, const wxAuiToolBarItem& item, const wxRect& rect)
|
||||
{
|
||||
dc.SetFont(m_font);
|
||||
#ifdef __WINDOWS__
|
||||
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
|
||||
#else
|
||||
dc.SetTextForeground(*wxWHITE);
|
||||
#endif
|
||||
|
||||
int textWidth = 0, textHeight = 0;
|
||||
dc.GetTextExtent(item.GetLabel(), &textWidth, &textHeight);
|
||||
|
||||
wxRect clipRect = rect;
|
||||
clipRect.width -= 1;
|
||||
dc.SetClippingRegion(clipRect);
|
||||
|
||||
int textX, textY;
|
||||
if (textWidth < rect.GetWidth()) {
|
||||
textX = rect.x + 1 + (rect.width - textWidth) / 2;
|
||||
}
|
||||
else {
|
||||
textX = rect.x + 1;
|
||||
}
|
||||
textY = rect.y + (rect.height - textHeight) / 2;
|
||||
dc.DrawText(item.GetLabel(), textX, textY);
|
||||
dc.DestroyClippingRegion();
|
||||
}
|
||||
|
||||
void BBLTopbarArt::DrawBackground(wxDC& dc, wxWindow* wnd, const wxRect& rect)
|
||||
{
|
||||
dc.SetBrush(wxBrush(wxColour(38, 46, 48)));
|
||||
@@ -257,21 +282,22 @@ void BBLTopbar::Init(wxFrame* parent)
|
||||
m_calib_item = this->AddTool(ID_CALIB, _L("Calibration"), calib_bitmap);
|
||||
m_calib_item->SetDisabledBitmap(calib_bitmap_inactive);
|
||||
|
||||
this->AddSpacer(FromDIP(10));
|
||||
this->AddStretchSpacer(1);
|
||||
this->AddSpacer(FromDIP(25));
|
||||
//this->AddStretchSpacer(1);
|
||||
|
||||
m_title_item = this->AddLabel(ID_TITLE, "", FromDIP(TOPBAR_TITLE_WIDTH));
|
||||
m_title_item->SetAlignment(wxALIGN_CENTRE);
|
||||
m_title_ctrl = new CenteredTitle(this);
|
||||
wxAuiToolBarItem* title_item = this->AddControl(m_title_ctrl, "");
|
||||
title_item->SetProportion(1);
|
||||
|
||||
this->AddSpacer(FromDIP(10));
|
||||
this->AddStretchSpacer(1);
|
||||
this->AddSpacer(FromDIP(25));
|
||||
//this->AddStretchSpacer(1);
|
||||
|
||||
m_publish_bitmap = create_scaled_bitmap("topbar_publish", nullptr, TOPBAR_ICON_SIZE);
|
||||
m_publish_item = this->AddTool(ID_PUBLISH, "", m_publish_bitmap);
|
||||
m_publish_disable_bitmap = create_scaled_bitmap("topbar_publish_disable", nullptr, TOPBAR_ICON_SIZE);
|
||||
m_publish_item->SetDisabledBitmap(m_publish_disable_bitmap);
|
||||
this->EnableTool(m_publish_item->GetId(), false);
|
||||
this->AddSpacer(FromDIP(4));
|
||||
//m_publish_bitmap = create_scaled_bitmap("topbar_publish", nullptr, TOPBAR_ICON_SIZE);
|
||||
//m_publish_item = this->AddTool(ID_PUBLISH, "", m_publish_bitmap);
|
||||
//m_publish_disable_bitmap = create_scaled_bitmap("topbar_publish_disable", nullptr, TOPBAR_ICON_SIZE);
|
||||
//m_publish_item->SetDisabledBitmap(m_publish_disable_bitmap);
|
||||
//this->EnableTool(m_publish_item->GetId(), false);
|
||||
//this->AddSpacer(FromDIP(4));
|
||||
|
||||
/*wxBitmap model_store_bitmap = create_scaled_bitmap("topbar_store", nullptr, TOPBAR_ICON_SIZE);
|
||||
m_model_store_item = this->AddTool(ID_MODEL_STORE, "", model_store_bitmap);
|
||||
@@ -279,7 +305,7 @@ void BBLTopbar::Init(wxFrame* parent)
|
||||
*/
|
||||
|
||||
//this->AddSeparator();
|
||||
this->AddSpacer(FromDIP(4));
|
||||
//this->AddSpacer(FromDIP(4));
|
||||
|
||||
wxBitmap iconize_bitmap = create_scaled_bitmap("topbar_min", nullptr, TOPBAR_ICON_SIZE);
|
||||
wxAuiToolBarItem* iconize_btn = this->AddTool(wxID_ICONIZE_FRAME, "", iconize_bitmap);
|
||||
@@ -324,7 +350,7 @@ void BBLTopbar::Init(wxFrame* parent)
|
||||
this->Bind(wxEVT_AUITOOLBAR_TOOL_DROPDOWN, &BBLTopbar::OnRedo, this, wxID_REDO);
|
||||
this->Bind(wxEVT_AUITOOLBAR_TOOL_DROPDOWN, &BBLTopbar::OnUndo, this, wxID_UNDO);
|
||||
//this->Bind(wxEVT_AUITOOLBAR_TOOL_DROPDOWN, &BBLTopbar::OnModelStoreClicked, this, ID_MODEL_STORE);
|
||||
this->Bind(wxEVT_AUITOOLBAR_TOOL_DROPDOWN, &BBLTopbar::OnPublishClicked, this, ID_PUBLISH);
|
||||
//this->Bind(wxEVT_AUITOOLBAR_TOOL_DROPDOWN, &BBLTopbar::OnPublishClicked, this, ID_PUBLISH);
|
||||
}
|
||||
|
||||
BBLTopbar::~BBLTopbar()
|
||||
@@ -341,11 +367,11 @@ void BBLTopbar::OnOpenProject(wxAuiToolBarEvent& event)
|
||||
plater->load_project();
|
||||
}
|
||||
|
||||
void BBLTopbar::show_publish_button(bool show)
|
||||
{
|
||||
this->EnableTool(m_publish_item->GetId(), show);
|
||||
Refresh();
|
||||
}
|
||||
//void BBLTopbar::show_publish_button(bool show)
|
||||
//{
|
||||
// this->EnableTool(m_publish_item->GetId(), show);
|
||||
// Refresh();
|
||||
//}
|
||||
|
||||
void BBLTopbar::OnSaveProject(wxAuiToolBarEvent& event)
|
||||
{
|
||||
@@ -446,12 +472,9 @@ wxMenu* BBLTopbar::GetCalibMenu()
|
||||
|
||||
void BBLTopbar::SetTitle(wxString title)
|
||||
{
|
||||
wxGCDC dc(this);
|
||||
title = wxControl::Ellipsize(title, dc, wxELLIPSIZE_END, FromDIP(TOPBAR_TITLE_WIDTH));
|
||||
|
||||
m_title_item->SetLabel(title);
|
||||
m_title_item->SetAlignment(wxALIGN_CENTRE);
|
||||
this->Refresh();
|
||||
m_titleText = title;
|
||||
if (m_title_ctrl)
|
||||
m_title_ctrl->SetTitle(title);
|
||||
}
|
||||
|
||||
void BBLTopbar::SetMaximizedSize()
|
||||
@@ -500,7 +523,8 @@ void BBLTopbar::Rescale() {
|
||||
item->SetBitmap(create_scaled_bitmap("calib_sf", this, TOPBAR_ICON_SIZE));
|
||||
item->SetDisabledBitmap(create_scaled_bitmap("calib_sf_inactive", this, TOPBAR_ICON_SIZE));
|
||||
|
||||
item = this->FindTool(ID_TITLE);
|
||||
if (m_title_ctrl)
|
||||
m_title_ctrl->SetTitle(m_titleText);
|
||||
|
||||
/*item = this->FindTool(ID_PUBLISH);
|
||||
item->SetBitmap(create_scaled_bitmap("topbar_publish", this, TOPBAR_ICON_SIZE));
|
||||
@@ -565,9 +589,9 @@ void BBLTopbar::OnCloseFrame(wxAuiToolBarEvent& event)
|
||||
void BBLTopbar::OnMouseLeftDClock(wxMouseEvent& mouse)
|
||||
{
|
||||
wxPoint mouse_pos = ::wxGetMousePosition();
|
||||
wxAuiToolBarItem* item = this->FindToolByCurrentPosition();
|
||||
// check whether mouse is not on any tool item
|
||||
if (this->FindToolByCurrentPosition() != NULL &&
|
||||
this->FindToolByCurrentPosition() != m_title_item) {
|
||||
if (item != NULL && item->GetWindow() != m_title_ctrl) {
|
||||
mouse.Skip();
|
||||
return;
|
||||
}
|
||||
@@ -635,10 +659,10 @@ void BBLTopbar::OnMouseLeftDown(wxMouseEvent& event)
|
||||
{
|
||||
wxPoint mouse_pos = ::wxGetMousePosition();
|
||||
wxPoint frame_pos = m_frame->GetScreenPosition();
|
||||
wxAuiToolBarItem* item = this->FindToolByCurrentPosition();
|
||||
m_delta = mouse_pos - frame_pos;
|
||||
|
||||
if (FindToolByCurrentPosition() == NULL
|
||||
|| this->FindToolByCurrentPosition() == m_title_item)
|
||||
if (item == NULL || item->GetWindow() == m_title_ctrl)
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
CaptureMouse();
|
||||
@@ -728,8 +752,8 @@ WXLRESULT BBLTopbar::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam
|
||||
{
|
||||
switch (nMsg) {
|
||||
case WM_NCHITTEST: {
|
||||
const wxAuiToolBarItem* current_item = this->FindToolByCurrentPosition();
|
||||
if (current_item != nullptr && current_item != m_title_item) {
|
||||
wxAuiToolBarItem* item = this->FindToolByCurrentPosition();
|
||||
if (item != NULL && item->GetWindow() != m_title_ctrl) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,22 @@
|
||||
#include "SelectMachine.hpp"
|
||||
#include "DeviceManager.hpp"
|
||||
|
||||
#include <wx/control.h>
|
||||
|
||||
using namespace Slic3r::GUI;
|
||||
|
||||
class CenteredTitle : public wxControl
|
||||
{
|
||||
public:
|
||||
CenteredTitle(wxWindow* parent);
|
||||
void SetTitle(const wxString& title);
|
||||
|
||||
wxSize DoGetBestSize() const override;
|
||||
|
||||
private:
|
||||
wxString m_title;
|
||||
};
|
||||
|
||||
class BBLTopbar : public wxAuiToolBar
|
||||
{
|
||||
public:
|
||||
@@ -31,7 +44,7 @@ public:
|
||||
void OnMouseCaptureLost(wxMouseCaptureLostEvent& event);
|
||||
void OnMenuClose(wxMenuEvent& event);
|
||||
void OnOpenProject(wxAuiToolBarEvent& event);
|
||||
void show_publish_button(bool show);
|
||||
//void show_publish_button(bool show);
|
||||
void OnSaveProject(wxAuiToolBarEvent& event);
|
||||
void OnUndo(wxAuiToolBarEvent& event);
|
||||
void OnRedo(wxAuiToolBarEvent& event);
|
||||
@@ -70,11 +83,14 @@ private:
|
||||
wxMenu m_top_menu;
|
||||
wxMenu* m_file_menu;
|
||||
wxMenu m_calib_menu;
|
||||
wxAuiToolBarItem* m_title_item;
|
||||
|
||||
CenteredTitle* m_title_ctrl { nullptr };
|
||||
wxString m_titleText;
|
||||
|
||||
wxAuiToolBarItem* m_account_item;
|
||||
wxAuiToolBarItem* m_model_store_item;
|
||||
|
||||
wxAuiToolBarItem *m_publish_item;
|
||||
//wxAuiToolBarItem *m_publish_item;
|
||||
wxAuiToolBarItem* m_undo_item;
|
||||
wxAuiToolBarItem* m_redo_item;
|
||||
wxAuiToolBarItem* m_calib_item;
|
||||
|
||||
Reference in New Issue
Block a user