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

@@ -186,6 +186,7 @@ AMSControl::AMSControl(wxWindow *parent, wxWindowID id, const wxPoint &pos, cons
m_button_extruder_feed->SetTextColor(btn_text_green);
m_button_extruder_feed->SetMinSize(wxSize(FromDIP(80),FromDIP(34)));
m_button_extruder_feed->SetMaxSize(wxSize(FromDIP(80),FromDIP(34)));
m_button_extruder_feed->EnableTooltipEvenDisabled();
if (wxGetApp().app_config->get("language") == "de_DE") m_button_extruder_feed->SetFont(Label::Body_9);
@@ -206,6 +207,7 @@ AMSControl::AMSControl(wxWindow *parent, wxWindowID id, const wxPoint &pos, cons
m_button_extruder_back->SetFont(Label::Body_13);
m_button_extruder_back->SetMinSize(wxSize(FromDIP(80), FromDIP(34)));
m_button_extruder_back->SetMaxSize(wxSize(FromDIP(80), FromDIP(34)));
m_button_extruder_back->EnableTooltipEvenDisabled();
if (wxGetApp().app_config->get("language") == "de_DE") m_button_extruder_back->SetFont(Label::Body_9);
if (wxGetApp().app_config->get("language") == "fr_FR") m_button_extruder_back->SetFont(Label::Body_9);
@@ -406,13 +408,22 @@ wxColour AMSControl::GetCanColour(std::string amsid, std::string canid)
return col;
}
void AMSControl::SetActionState(bool button_status[])
void AMSControl::EnableLoadFilamentBtn(bool enable, const std::string& ams_id, const std::string& can_id,const wxString& tips)
{
if (button_status[ActionButton::ACTION_BTN_LOAD]) m_button_extruder_feed->Enable();
else m_button_extruder_feed->Disable();
m_button_extruder_feed->Enable(enable);
if (m_button_extruder_feed->GetToolTipText() != tips) {
BOOST_LOG_TRIVIAL(info) << "ams_id=" << ams_id << ", can_id=" << can_id << " Set Load Filament Button ToolTip : " << tips.ToUTF8();
m_button_extruder_feed->SetToolTip(tips);
}
}
if (button_status[ActionButton::ACTION_BTN_UNLOAD]) m_button_extruder_back->Enable();
else m_button_extruder_back->Disable();
void AMSControl::EnableUnLoadFilamentBtn(bool enable, const std::string& ams_id, const std::string& can_id,const wxString& tips)
{
m_button_extruder_back->Enable(enable);
if (m_button_extruder_back->GetToolTipText() != tips) {
BOOST_LOG_TRIVIAL(info) << "ams_id=" << ams_id << ", can_id=" << can_id << " Set Unload Filament Button ToolTip : " << tips.ToUTF8();
m_button_extruder_back->SetToolTip(tips);
}
}
void AMSControl::EnterNoneAMSMode()

View File

@@ -138,7 +138,9 @@ public:
void SetAmsModel(AMSModel mode, AMSModel ext_mode) {m_ams_model = mode; m_ext_model = ext_mode;};
void AmsSelectedSwitch(wxCommandEvent& event);
void SetActionState(bool button_status[]);
void EnableLoadFilamentBtn(bool enable, const std::string& ams_id, const std::string& can_id, const wxString& tips);
void EnableUnLoadFilamentBtn(bool enable, const std::string& ams_id, const std::string& can_id,const wxString& tips);
void EnterNoneAMSMode();
void EnterGenericAMSMode();
void EnterExtraAMSMode();

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

View File

@@ -26,6 +26,7 @@ enum class ButtonType{
Expanded , // Font14 Semi-Rounded For full length buttons. ex. buttons in static box
};
class wxTipWindow;
class Button : public StaticBox
{
wxRect textSize;
@@ -42,6 +43,8 @@ class Button : public StaticBox
bool isCenter = true;
bool vertical = false;
wxTipWindow* tipWindow = nullptr;
static const int buttonWidth = 200;
static const int buttonHeight = 50;
@@ -74,6 +77,7 @@ public:
void SetSelected(bool selected = true) { m_selected = selected; }
bool Enable(bool enable = true) override;
void EnableTooltipEvenDisabled();// The tip will be shown even if the button is disabled
void SetCanFocus(bool canFocus) override;
@@ -111,8 +115,13 @@ private:
void mouseCaptureLost(wxMouseCaptureLostEvent &event);
void keyDownUp(wxKeyEvent &event);
//
void sendButtonEvent();
// parent motion
void OnParentMotion(wxMouseEvent& event);
void OnParentLeave(wxMouseEvent& event);
DECLARE_EVENT_TABLE()
};