mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-06-22 19:50:44 +00:00
ENH: Add label if the button can not be used
jira: [STUDIO-12929] Change-Id: Ia4026282a44fd1a83a4292d7a7d11d43ed035db6 (cherry picked from commit e65755a474bc36bee0f22b7a6fb9c7eb5f86be65)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "Label.hpp"
|
||||
|
||||
#include <wx/dcgraph.h>
|
||||
#include <wx/tipwin.h>
|
||||
#ifdef __APPLE__
|
||||
#include "libslic3r/MacUtils.hpp"
|
||||
#endif
|
||||
@@ -480,4 +481,72 @@ WXLRESULT Button::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
|
||||
|
||||
#endif
|
||||
|
||||
bool Button::AcceptsFocus() const { return canFocus; }
|
||||
bool Button::AcceptsFocus() const { return canFocus; }
|
||||
|
||||
void Button::EnableTooltipEvenDisabled()
|
||||
{
|
||||
auto parent = this->GetParent();
|
||||
if (parent)
|
||||
{
|
||||
parent->Bind(wxEVT_MOTION, &Button::OnParentMotion, this);
|
||||
parent->Bind(wxEVT_LEAVE_WINDOW, &Button::OnParentLeave, this);
|
||||
};
|
||||
};
|
||||
|
||||
void Button::OnParentMotion(wxMouseEvent& event)
|
||||
{
|
||||
auto parent = this->GetParent();
|
||||
if (!parent) return event.Skip();
|
||||
|
||||
wxPoint pos = parent->ClientToScreen(event.GetPosition());
|
||||
wxRect screen_rect = this->GetScreenRect();
|
||||
wxString tip = this->GetToolTipText();
|
||||
if (!tip.IsEmpty() && !this->IsEnabled() && screen_rect.Contains(pos))
|
||||
{
|
||||
if (!tipWindow)
|
||||
{
|
||||
tipWindow = new wxTipWindow(this, tip);
|
||||
tipWindow->Bind(wxEVT_DESTROY, [this](wxEvent& event) { this->tipWindow = nullptr;});
|
||||
tipWindow->Enable(false);
|
||||
}
|
||||
|
||||
if (tipWindow->GetLabel() != tip)
|
||||
{
|
||||
tipWindow->SetLabel(tip);
|
||||
}
|
||||
|
||||
tipWindow->Position(wxGetMousePosition(), wxSize(0, 0));
|
||||
tipWindow->Popup();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tipWindow)
|
||||
{
|
||||
delete tipWindow;
|
||||
tipWindow = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void Button::OnParentLeave(wxMouseEvent& event)
|
||||
{
|
||||
auto parent = this->GetParent();
|
||||
if (!parent) return event.Skip();
|
||||
|
||||
if (tipWindow)
|
||||
{
|
||||
wxPoint pos = parent->ClientToScreen(event.GetPosition());
|
||||
wxRect screen_rect = this->GetScreenRect();
|
||||
wxString tip = this->GetToolTipText();
|
||||
if (!screen_rect.Contains(pos))
|
||||
{
|
||||
tipWindow->Dismiss();
|
||||
delete tipWindow;
|
||||
tipWindow = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user