@@ -49,6 +49,39 @@ namespace util
4949 return button;
5050 };
5151
52+ auto operator ()(HKDevicePtr ptr, ScreenType screen) -> std::shared_ptr<UIButton>
53+ {
54+ auto button = std::make_shared<UIButton>(&(screen->mTft ), Frame (), ptr->groupId );
55+ button->setBackgroundColor (Color::InactiveBgColor ());
56+ button->setLabel (ptr->sceneName );
57+
58+ const auto icons = GetIconFileNames (ptr->iconName );
59+ const auto textColor = ptr->isActive () ? Color::ActiveBgColor () : Color::InactiveTextColor ();
60+ const auto imagePath = ptr->isActive () ? icons.first : icons.second ;
61+ button->setImage (imagePath);
62+ button->setTextColor (textColor);
63+ auto & context = screen->mpAppContext ;
64+ button->addTargetAction ([ptr, context](const uint16_t id) {
65+ const bool isActive = ptr->isActive ();
66+ ptr->setDeviceState (!isActive);
67+ });
68+
69+ auto & screenSaver = screen->mScreenSaver ;
70+ ptr->mSetNeedsUpdateCB = [ptr, weakBtn = std::weak_ptr<UIButton>(button), &screenSaver, icons](const bool state) {
71+ const auto textColor = state ? Color::ActiveBgColor () : Color::InactiveTextColor ();
72+ const auto imagePath = state ? icons.first : icons.second ;
73+ auto button = weakBtn.lock ();
74+ if (!button)
75+ {
76+ return ;
77+ }
78+ button->setTextColor (textColor);
79+ button->setImage (imagePath);
80+ screenSaver.activate ();
81+ };
82+ return button;
83+ };
84+
5285 auto operator ()(MQTTSensorGroupPtr ptr, ScreenType screen) -> std::shared_ptr<UIWidget>
5386 {
5487 auto button = std::make_shared<UISensorComboWidget>(&(screen->mTft ), Frame (), ptr->groupId );
@@ -127,4 +160,4 @@ namespace util
127160 }
128161 };
129162} // namespace util
130- } // namespace gfx
163+ } // namespace gfx
0 commit comments