Files
MuditaOS/module-gui/gui/widgets/CheckBoxWithLabel.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

52 lines
1.7 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 "CheckBoxWithLabel.hpp"
namespace gui
{
CheckBoxWithLabel::CheckBoxWithLabel(
Item *parent, int x, int y, UTF8 description, std::function<void(CheckBoxWithLabel &)> clickCallback)
{
auto body = new gui::HBox(nullptr, x, y, style::window::default_body_width, style::window::label::big_h);
body->setEdges(gui::RectangleEdge::None);
label =
new gui::Label(nullptr, 0, 0, style::checkbox::description_width, style::window::label::big_h, description);
check = new gui::CheckBox(nullptr,
style::checkbox::check_x,
style::checkbox::check_y,
style::checkbox::check_width,
style::window::label::small_h);
check->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
label->activatedCallback = [=](Item &item) {
setChecked(!check->isChecked());
if (clickCallback) {
clickCallback(*this);
}
return true;
};
style::window::decorateOption(label);
style::window::decorate(check);
/*
* We need to add widgets after decorate to correctly redraw them
*/
parent->addWidget(body);
body->addWidget(label);
body->addWidget(check);
}
bool CheckBoxWithLabel::isChecked() const
{
return check->isChecked();
}
void CheckBoxWithLabel::setChecked(bool state)
{
check->setImageVisible(state);
}
} // namespace gui