Skip to content

Commit 9684d5e

Browse files
[EGD-3993] Integrate ButtonOnOff with OptionSetting (#931)
1 parent e3fd0eb commit 9684d5e

File tree

10 files changed

+87
-71
lines changed

10 files changed

+87
-71
lines changed

module-apps/application-settings-new/windows/AddDeviceWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace gui
4141
},
4242
nullptr,
4343
nullptr,
44-
RightIcon::Bt));
44+
RightItem::Bt));
4545
}
4646

4747
sys::Bus::SendUnicast(

module-apps/application-settings-new/windows/AllDevicesWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace gui
6363
},
6464
nullptr,
6565
nullptr,
66-
RightIcon::Bt));
66+
RightItem::Bt));
6767
}
6868

6969
topBar->setActive(TopBar::Elements::SIGNAL, false);

module-apps/application-settings-new/windows/BluetoothWindow.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ namespace gui
3535
},
3636
[=](gui::Item &item) {
3737
if (item.focus) {
38-
this->setBottomBarText(utils::localize.get(style::strings::common::Switch),
38+
this->setBottomBarText(utils::translateI18(style::strings::common::Switch),
3939
BottomBar::Side::CENTER);
4040
}
4141
return true;
4242
},
43-
this));
43+
this,
44+
isBluetoothSwitchOn ? RightItem::On : RightItem::Off));
45+
4446
if (isBluetoothSwitchOn) {
4547
optionsList.emplace_back(std::make_unique<gui::OptionSettings>(
4648
utils::translateI18("app_settings_bluetooth_all_devices_indent"),
@@ -50,13 +52,13 @@ namespace gui
5052
},
5153
[=](gui::Item &item) {
5254
if (item.focus) {
53-
this->setBottomBarText(utils::localize.get(style::strings::common::select),
55+
this->setBottomBarText(utils::translateI18(style::strings::common::select),
5456
BottomBar::Side::CENTER);
5557
}
5658
return true;
5759
},
5860
nullptr,
59-
RightIcon::Border));
61+
RightItem::ArrowWhite));
6062
optionsList.emplace_back(std::make_unique<gui::OptionSettings>(
6163
utils::translateI18("app_settings_bluetooth_phone_visibility"),
6264
[=](gui::Item &item) {
@@ -65,12 +67,13 @@ namespace gui
6567
},
6668
[=](gui::Item &item) {
6769
if (item.focus) {
68-
this->setBottomBarText(utils::localize.get(style::strings::common::Switch),
70+
this->setBottomBarText(utils::translateI18(style::strings::common::Switch),
6971
BottomBar::Side::CENTER);
7072
}
7173
return true;
7274
},
73-
this));
75+
this,
76+
isPhoneVisibilitySwitchOn ? RightItem::On : RightItem::Off));
7477
if (isPhoneVisibilitySwitchOn) {
7578
optionsList.emplace_back(std::make_unique<gui::OptionSettings>(
7679
utils::translateI18("app_settings_bluetooth_phone_name_indent"),
@@ -80,13 +83,13 @@ namespace gui
8083
},
8184
[=](gui::Item &item) {
8285
if (item.focus) {
83-
this->setBottomBarText(utils::localize.get(style::strings::common::select),
86+
this->setBottomBarText(utils::translateI18(style::strings::common::select),
8487
BottomBar::Side::CENTER);
8588
}
8689
return true;
8790
},
8891
nullptr,
89-
RightIcon::Border));
92+
RightItem::ArrowWhite));
9093
}
9194
}
9295

module-apps/application-settings-new/windows/MessagesWindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace gui
4444
return true;
4545
},
4646
nullptr,
47-
showUnreadMessagesFirst ? RightIcon::On : RightIcon::Off));
47+
showUnreadMessagesFirst ? RightItem::On : RightItem::Off));
4848
};
4949

5050
auto addMenu = [&](UTF8 name, std::string window) {
@@ -60,7 +60,7 @@ namespace gui
6060
},
6161
nullptr,
6262
nullptr,
63-
RightIcon::Border));
63+
RightItem::ArrowWhite));
6464
};
6565

6666
bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::select));

module-apps/application-settings-new/windows/NetworkWindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace gui
5353
},
5454
nullptr,
5555
nullptr,
56-
operatorsOn ? RightIcon::On : RightIcon::Off));
56+
operatorsOn ? RightItem::On : RightItem::Off));
5757
if (operatorsOn) {
5858
optList.emplace_back(std::make_unique<gui::OptionSettings>(
5959
utils::translateI18("app_settings_network_all_operators"),
@@ -63,7 +63,7 @@ namespace gui
6363
},
6464
nullptr,
6565
nullptr,
66-
RightIcon::Border));
66+
RightItem::ArrowWhite));
6767
}
6868
optList.emplace_back(gui::Option{
6969
utils::translateI18("app_settings_network_import_contacts_from_sim_card"), [=](gui::Item &item) {

module-apps/widgets/ButtonOnOff.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,9 @@
66
#include <Style.hpp>
77
#include <i18/i18.hpp>
88

9-
namespace style
10-
{
11-
namespace buttonOnOff
12-
{
13-
constexpr uint32_t w = 56;
14-
constexpr uint32_t h = 32;
15-
} // namespace buttonOnOff
16-
} // namespace style
17-
189
namespace gui
1910
{
20-
ButtonOnOff::ButtonOnOff(Item *parent, ButtonType buttonType) : Label{parent}
11+
ButtonOnOff::ButtonOnOff(Item *parent, const ButtonState buttonState) : Label{parent}
2112
{
2213
setMinimumSize(style::buttonOnOff::w, style::buttonOnOff::h);
2314

@@ -27,16 +18,27 @@ namespace gui
2718
setPenWidth(2);
2819
setFilled(true);
2920
setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
30-
if (buttonType == ButtonType::On) {
21+
setFont(style::window::font::small);
22+
switchState(buttonState);
23+
}
24+
25+
void ButtonOnOff::switchState(const ButtonState newButtonState)
26+
{
27+
currentState = newButtonState;
28+
if (currentState == ButtonState::On) {
3129
setFillColor(ColorFullBlack);
3230
setText(utils::translateI18("app_settings_toggle_on"));
3331
setTextColor(ColorFullWhite);
3432
}
35-
else if (buttonType == ButtonType::Off) {
33+
else if (currentState == ButtonState::Off) {
3634
setFillColor(ColorFullWhite);
3735
setText(utils::translateI18("app_settings_toggle_off"));
3836
setTextColor(ColorFullBlack);
3937
}
4038
}
39+
void ButtonOnOff::toggleState()
40+
{
41+
switchState(static_cast<ButtonState>(!static_cast<bool>(currentState)));
42+
}
4143

4244
} /* namespace gui */

module-apps/widgets/ButtonOnOff.hpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,32 @@
55

66
#include "Label.hpp"
77

8+
namespace style
9+
{
10+
namespace buttonOnOff
11+
{
12+
constexpr uint32_t w = 56;
13+
constexpr uint32_t h = 32;
14+
} // namespace buttonOnOff
15+
} // namespace style
16+
817
namespace gui
918
{
10-
enum class ButtonType
19+
enum class ButtonState : bool
1120
{
12-
On,
13-
Off
21+
Off,
22+
On
1423
};
1524

1625
class ButtonOnOff : public Label
1726
{
1827
public:
19-
ButtonOnOff(Item *parent, ButtonType buttonType);
28+
ButtonOnOff(Item *parent, const ButtonState buttonState);
29+
void switchState(const ButtonState);
30+
void toggleState();
31+
32+
private:
33+
ButtonState currentState;
2034
};
2135

2236
} /* namespace gui */

module-apps/windows/OptionSetting.cpp

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,52 @@
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

44
#include "OptionSetting.hpp"
5-
#include "OptionsStyle.hpp"
5+
#include "widgets/ButtonOnOff.hpp"
66

77
namespace gui
88
{
99
auto OptionSettings::build() const -> Item *
1010
{
11-
auto *label = new gui::Label(nullptr,
12-
style::window::default_left_margin,
13-
0,
14-
style::window_width - 2 * style::window::default_left_margin,
15-
style::window::label::big_h,
16-
text);
17-
style::window::decorateOption(label);
18-
label->activatedCallback = activatedCallback;
19-
std::string img;
20-
switch (rIcon) {
21-
case RightIcon::Enabled:
22-
img = "right_label_arrow";
11+
auto optionBodyHBox = new HBox(nullptr, 0, 0, style::window::default_body_width, style::window::label::big_h);
12+
optionBodyHBox->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
13+
optionBodyHBox->activatedCallback = activatedCallback;
14+
optionBodyHBox->focusChangedCallback = focusCb;
15+
style::window::decorate(optionBodyHBox);
16+
17+
auto optionNameLabel = new Label(optionBodyHBox, 0, 0, 0, 0, text);
18+
optionNameLabel->setMinimumSize(style::window::default_body_width - style::buttonOnOff::w,
19+
style::window::label::big_h);
20+
optionNameLabel->setEdges(RectangleEdge::None);
21+
optionNameLabel->setAlignment(Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center));
22+
optionNameLabel->setFont(style::window::font::big);
23+
24+
std::string imageName;
25+
switch (rightItem) {
26+
case RightItem::ArrowBlack:
27+
imageName = "right_label_arrow";
2328
break;
24-
case RightIcon::Border:
25-
img = "right_label_arrow_border";
29+
case RightItem::ArrowWhite:
30+
imageName = "right_label_arrow_border";
2631
break;
27-
case RightIcon::On:
28-
img = "btn_on";
32+
case RightItem::On:
33+
new ButtonOnOff(optionBodyHBox, ButtonState::On);
2934
break;
30-
case RightIcon::Off:
31-
img = "btn_off";
35+
case RightItem::Off:
36+
new ButtonOnOff(optionBodyHBox, ButtonState::Off);
3237
break;
33-
case RightIcon::Bt:
34-
img = "bt";
38+
case RightItem::Bt:
39+
imageName = "bt";
3540
break;
3641
default:
3742
break;
3843
}
3944

40-
if (!img.empty()) {
41-
new gui::Image(label, style::option::arrow_position_x, style::option::arrow_positon_y, 0, 0, img);
45+
if (!imageName.empty()) {
46+
auto image = new gui::Image(optionBodyHBox, 0, 0, 0, 0, imageName);
47+
optionNameLabel->setMinimumSize(style::window::default_body_width - image->getWidth(),
48+
style::window::label::big_h);
4249
}
43-
label->focusChangedCallback = focusCb;
44-
return label;
50+
51+
return optionBodyHBox;
4552
}
4653
} // namespace gui

module-apps/windows/OptionSetting.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
namespace gui
1010
{
11-
enum class RightIcon : uint8_t
11+
enum class RightItem
1212
{
1313
Disabled,
14-
Enabled,
15-
Border,
14+
ArrowBlack,
15+
ArrowWhite,
1616
On,
1717
Off,
1818
Bt
@@ -25,15 +25,15 @@ namespace gui
2525
std::function<bool(Item &)> activatedCallback = nullptr;
2626
std::function<bool(Item &)> focusCb = nullptr;
2727
AppWindow *app = nullptr;
28-
RightIcon rIcon = RightIcon::Disabled;
28+
RightItem rightItem = RightItem::Disabled;
2929

3030
public:
3131
OptionSettings(const UTF8 text,
3232
std::function<bool(Item &)> cb,
3333
std::function<bool(Item &)> cbFocus,
3434
AppWindow *app,
35-
RightIcon rIcon = RightIcon::Disabled)
36-
: text(text), activatedCallback(std::move(cb)), focusCb(std::move(cbFocus)), app(app), rIcon(rIcon)
35+
RightItem rightItem = RightItem::Disabled)
36+
: text(text), activatedCallback(std::move(cb)), focusCb(std::move(cbFocus)), app(app), rightItem(rightItem)
3737
{}
3838
[[nodiscard]] auto build() const -> Item * override;
3939
};

module-apps/windows/OptionsStyle.hpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)