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:
xin.zhang
2025-07-01 16:50:21 +08:00
committed by Noisyfox
parent d4115e0837
commit 0bbd563a79
5 changed files with 120 additions and 25 deletions

View File

@@ -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();
}