mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-28 11:21:30 +00:00
Rounded corner for the dialog
This commit is contained in:
@@ -21,6 +21,7 @@ body {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
background: var(--panel, var(--orca-bg, #fff));
|
background: var(--panel, var(--orca-bg, #fff));
|
||||||
border: 1px solid var(--border, var(--orca-border, #ddd));
|
border: 1px solid var(--border, var(--orca-border, #ddd));
|
||||||
|
border-radius: 7px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
/* why: no height cap here - the launcher reports its true natural height to C++, which
|
/* why: no height cap here - the launcher reports its true natural height to C++, which
|
||||||
sizes the popup to match (HTML is source of truth). The list's own max-height is what
|
sizes the popup to match (HTML is source of truth). The list's own max-height is what
|
||||||
|
|||||||
@@ -11,7 +11,9 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <wx/dcmemory.h>
|
||||||
#include <wx/display.h>
|
#include <wx/display.h>
|
||||||
|
#include <wx/region.h>
|
||||||
#include <wx/sizer.h>
|
#include <wx/sizer.h>
|
||||||
#include <wx/stattext.h>
|
#include <wx/stattext.h>
|
||||||
#include <wx/utils.h>
|
#include <wx/utils.h>
|
||||||
@@ -142,6 +144,7 @@ SpeedDialWebDialog::SpeedDialWebDialog(wxWindow* parent)
|
|||||||
SetSizer(sizer);
|
SetSizer(sizer);
|
||||||
SetClientSize(FromDIP(wxSize(kPopupWidth, kPopupMinHeight)));
|
SetClientSize(FromDIP(wxSize(kPopupWidth, kPopupMinHeight)));
|
||||||
}
|
}
|
||||||
|
apply_rounded_shape();
|
||||||
}
|
}
|
||||||
|
|
||||||
SpeedDialWebDialog::~SpeedDialWebDialog() { m_alive->store(false, std::memory_order_release); }
|
SpeedDialWebDialog::~SpeedDialWebDialog() { m_alive->store(false, std::memory_order_release); }
|
||||||
@@ -168,6 +171,7 @@ void SpeedDialWebDialog::request_show()
|
|||||||
|
|
||||||
Show();
|
Show();
|
||||||
Raise();
|
Raise();
|
||||||
|
apply_rounded_shape();
|
||||||
if (m_page_ready)
|
if (m_page_ready)
|
||||||
send_actions();
|
send_actions();
|
||||||
// Grab focus now and again on wxEVT_ACTIVATE; grabbing directly on the WebKit widget is
|
// Grab focus now and again on wxEVT_ACTIVATE; grabbing directly on the WebKit widget is
|
||||||
@@ -245,6 +249,39 @@ void SpeedDialWebDialog::resize_to_content(int height)
|
|||||||
const int height_dip = std::max(kPopupMinHeight, std::min(height, max_dip));
|
const int height_dip = std::max(kPopupMinHeight, std::min(height, max_dip));
|
||||||
SetClientSize(FromDIP(wxSize(kPopupWidth, height_dip)));
|
SetClientSize(FromDIP(wxSize(kPopupWidth, height_dip)));
|
||||||
Layout();
|
Layout();
|
||||||
|
apply_rounded_shape();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rounded corners: the webview paints an opaque rectangle, so round the whole top-level window
|
||||||
|
// with a shape region (same mask trick as FilamentPickerDialog). Binary edges, no anti-aliasing.
|
||||||
|
void SpeedDialWebDialog::apply_rounded_shape()
|
||||||
|
{
|
||||||
|
const wxSize size = GetSize();
|
||||||
|
if (size.GetWidth() <= 0 || size.GetHeight() <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_shape_bmp.Create(size.GetWidth(), size.GetHeight(), 32);
|
||||||
|
if (!m_shape_bmp.IsOk())
|
||||||
|
return;
|
||||||
|
|
||||||
|
wxMemoryDC dc;
|
||||||
|
dc.SelectObject(m_shape_bmp);
|
||||||
|
dc.SetBackground(wxBrush(wxColour(0, 0, 0)));
|
||||||
|
dc.Clear();
|
||||||
|
dc.SetBrush(wxBrush(wxColour(255, 255, 255, 255)));
|
||||||
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||||
|
dc.DrawRoundedRectangle(0, 0, size.GetWidth(), size.GetHeight(), FromDIP(m_corner_radius));
|
||||||
|
dc.SelectObject(wxNullBitmap);
|
||||||
|
|
||||||
|
wxRegion region(m_shape_bmp, wxColour(0, 0, 0));
|
||||||
|
if (region.IsOk())
|
||||||
|
SetShape(region);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SpeedDialWebDialog::on_dpi_changed(const wxRect&)
|
||||||
|
{
|
||||||
|
apply_rounded_shape();
|
||||||
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpeedDialWebDialog::run_action(const std::string& id, const std::string& title, const std::string& param)
|
void SpeedDialWebDialog::run_action(const std::string& id, const std::string& title, const std::string& param)
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <wx/bitmap.h>
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
class SpeedDialWebDialog : public WebViewHostDialog
|
class SpeedDialWebDialog : public WebViewHostDialog
|
||||||
@@ -25,8 +27,13 @@ private:
|
|||||||
void open_wiki(const std::string& id);
|
void open_wiki(const std::string& id);
|
||||||
void send_actions();
|
void send_actions();
|
||||||
void search_tabs();
|
void search_tabs();
|
||||||
|
void apply_rounded_shape();
|
||||||
|
void on_dpi_changed(const wxRect& suggested_rect) override;
|
||||||
|
|
||||||
bool m_page_ready{false};
|
bool m_page_ready{false};
|
||||||
|
// Rounded corners via a window shape region, since the webview itself is opaque.
|
||||||
|
int m_corner_radius{7};
|
||||||
|
wxBitmap m_shape_bmp;
|
||||||
// Guards the CallAfter in on_script_message across dialog destruction, same as
|
// Guards the CallAfter in on_script_message across dialog destruction, same as
|
||||||
// PluginsDialog::m_alive (PluginsDialog.hpp:249).
|
// PluginsDialog::m_alive (PluginsDialog.hpp:249).
|
||||||
std::shared_ptr<std::atomic<bool>> m_alive = std::make_shared<std::atomic<bool>>(true);
|
std::shared_ptr<std::atomic<bool>> m_alive = std::make_shared<std::atomic<bool>>(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user