Skip to content

Commit 28c023c

Browse files
[EGD-3722] Add ButtonOnOff widget (#911)
1 parent 3b137f2 commit 28c023c

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Added
66
* `[settings][bluetooth]` Add "Phone name" window.
7+
* `[gui]` Add "ButtonOnOff" widget.
78

89
### Changed
910

image/assets/lang/lang_en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@
280280
"app_settings_network_import_contacts_from_sim_card": "Import contacts from SIM card",
281281
"app_settings_network_sim1": "Sim1",
282282
"app_settings_network_sim2": "Sim2",
283-
"app_settings_toggle_on": "On",
284-
"app_settings_toggle_off": "Off",
283+
"app_settings_toggle_on": "ON",
284+
"app_settings_toggle_off": "OFF",
285285

286286
"app_phonebook_title_main": "Contacts",
287287
"app_phonebook_search_win_contacts": "Contacts",

module-apps/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ set( SOURCES
2222
"windows/OptionsWindowOption.cpp"
2323
"windows/Dialog.cpp"
2424
"windows/NoEvents.cpp"
25-
"widgets/InputBox.cpp"
2625
"windows/OptionSetting.cpp"
26+
"widgets/ButtonOnOff.cpp"
27+
"widgets/InputBox.cpp"
2728
)
2829

2930
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${BOARD_SOURCES})

module-apps/widgets/ButtonOnOff.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
2+
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
3+
4+
#include "ButtonOnOff.hpp"
5+
6+
#include <Style.hpp>
7+
#include <i18/i18.hpp>
8+
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+
18+
namespace gui
19+
{
20+
ButtonOnOff::ButtonOnOff(Item *parent, ButtonType buttonType) : Label{parent}
21+
{
22+
setMinimumSize(style::buttonOnOff::w, style::buttonOnOff::h);
23+
24+
setEdges(RectangleEdge::All);
25+
setCorners(RectangleRoundedCorner::All);
26+
setRadius(4);
27+
setPenWidth(2);
28+
setFilled(true);
29+
setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
30+
if (buttonType == ButtonType::On) {
31+
setFillColor(ColorFullBlack);
32+
setText(utils::translateI18("app_settings_toggle_on"));
33+
setTextColor(ColorFullWhite);
34+
}
35+
else if (buttonType == ButtonType::Off) {
36+
setFillColor(ColorFullWhite);
37+
setText(utils::translateI18("app_settings_toggle_off"));
38+
setTextColor(ColorFullBlack);
39+
}
40+
}
41+
42+
} /* namespace gui */

module-apps/widgets/ButtonOnOff.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
2+
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
3+
4+
#pragma once
5+
6+
#include "Label.hpp"
7+
8+
namespace gui
9+
{
10+
enum class ButtonType
11+
{
12+
On,
13+
Off
14+
};
15+
16+
class ButtonOnOff : public Label
17+
{
18+
public:
19+
ButtonOnOff(Item *parent, ButtonType buttonType);
20+
};
21+
22+
} /* namespace gui */

0 commit comments

Comments
 (0)