Files
MuditaOS/module-apps/application-settings-new/windows/DisplayLightWindow.cpp
Tomek Sobkowiak 4bc7df5f4a [EDG-4049] Add locked screen settings window with ON/OFF (#900)
* [EDG-4206] Add locked screen and integrate with ON/OFF widget
2020-11-02 18:24:00 +01:00

70 lines
2.4 KiB
C++

// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "DisplayLightWindow.hpp"
#include "application-settings-new/ApplicationSettings.hpp"
#include "windows/OptionSetting.hpp"
#include <i18/i18.hpp>
namespace gui
{
DisplayLightWindow::DisplayLightWindow(app::Application *app) : BaseSettingsWindow(app, window::name::display_light)
{
setTitle(utils::localize.get("app_settings_display_display_light"));
}
void DisplayLightWindow::switchHandler(bool &onOffSwitch)
{
onOffSwitch = !onOffSwitch;
rebuildOptionList();
}
auto DisplayLightWindow::buildOptionsList() -> std::list<gui::Option>
{
std::list<gui::Option> optionsList;
auto addOnOffOoption = [&](UTF8 text, bool &toggle) {
optionsList.emplace_back(std::make_unique<gui::OptionSettings>(
text,
[&](gui::Item &item) mutable {
switchHandler(toggle);
return true;
},
[=](gui::Item &item) {
if (item.focus) {
this->setBottomBarText(utils::translateI18(style::strings::common::Switch),
BottomBar::Side::CENTER);
}
return true;
},
this,
toggle ? RightItem::On : RightItem::Off));
};
addOnOffOoption(utils::translateI18("app_settings_display_light_main"), isDisplayLightSwitchOn);
if (isDisplayLightSwitchOn) {
addOnOffOoption(utils::translateI18("app_settings_display_light_auto"), isAutoLightSwitchOn);
}
if (isDisplayLightSwitchOn && !isAutoLightSwitchOn) {
optionsList.emplace_back(std::make_unique<gui::OptionSettings>(
utils::translateI18("app_settings_display_light_brightness"),
[=](gui::Item &item) { return true; },
[=](gui::Item &item) {
if (item.focus) {
this->setBottomBarText(utils::translateI18(style::strings::common::set),
BottomBar::Side::CENTER);
}
return true;
},
this,
RightItem::ArrowWhite));
}
return optionsList;
}
} // namespace gui