[EGD-7612] Add alarm popup

Added alarm popup window. Added ImageBoxWithText
widget.
This commit is contained in:
Wojtek Rzepecki
2021-09-16 16:50:23 +02:00
committed by Wojciech Rzepecki
parent b82c29fa39
commit 4c19fa16b3
34 changed files with 470 additions and 33 deletions

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

Binary file not shown.

View File

Binary file not shown.

View File

@@ -256,6 +256,9 @@
"app_popup_music_volume_text": "MUSIC VOLUME",
"app_popup_call_volume_text": "CALL VOLUME",
"app_popup_muted_text": "MUTED",
"app_popup_snooze_text": "SNOOZE",
"app_popup_alarm_text": "alarm",
"app_popup_alarm_snoozed_till": "snoozed till",
"app_call_call": "CALL",
"app_call_clear": "CLEAR",
"app_call_reject": "REJECT",

View File

@@ -99,8 +99,11 @@ namespace app
return std::make_unique<gui::DialogYesNo>(app, name);
});
attachPopups(
{gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock});
attachPopups({gui::popup::ID::Volume,
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::Alarm});
}
void ApplicationAlarmClock::destroyUserInterface()

View File

@@ -161,8 +161,11 @@ namespace app
return std::make_unique<gui::AlgoParamsWindow>(app);
});
attachPopups(
{gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock});
attachPopups({gui::popup::ID::Volume,
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::Alarm});
}
void ApplicationAntenna::destroyUserInterface()

View File

@@ -38,8 +38,11 @@ namespace app
return std::make_unique<gui::CalculatorMainWindow>(app, name);
});
attachPopups(
{gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock});
attachPopups({gui::popup::ID::Volume,
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::Alarm});
}
void ApplicationCalculator::destroyUserInterface()

View File

@@ -44,8 +44,11 @@ namespace app
return std::make_unique<gui::CalendarMainWindow>(app, name);
});
attachPopups(
{gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock});
attachPopups({gui::popup::ID::Volume,
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::Alarm});
}
void ApplicationCalendar::destroyUserInterface()

View File

@@ -96,8 +96,11 @@ namespace app
return std::make_unique<gui::DialogYesNo>(app, name);
});
attachPopups(
{gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock});
attachPopups({gui::popup::ID::Volume,
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::Alarm});
}
void ApplicationCallLog::destroyUserInterface()

View File

@@ -87,8 +87,11 @@ namespace app
return std::make_unique<gui::ClockMainWindow>(app, name);
});
attachPopups(
{gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock});
attachPopups({gui::popup::ID::Volume,
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::Alarm});
}
void ApplicationClock::destroyUserInterface()

View File

@@ -197,7 +197,8 @@ namespace app
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::SimLock});
gui::popup::ID::SimLock,
gui::popup::ID::Alarm});
}
void ApplicationDesktop::destroyUserInterface()

View File

@@ -58,8 +58,11 @@ namespace app
return std::make_unique<gui::PreparationTimeWindow>(app);
});
attachPopups(
{gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock});
attachPopups({gui::popup::ID::Volume,
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::Alarm});
}
void ApplicationMeditation::destroyUserInterface()

View File

@@ -149,8 +149,11 @@ namespace app
return std::make_unique<gui::SearchResults>(app);
});
attachPopups(
{gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock});
attachPopups({gui::popup::ID::Volume,
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::Alarm});
}
void ApplicationMessages::destroyUserInterface()

View File

@@ -137,8 +137,11 @@ namespace app
return std::make_unique<gui::MusicPlayerAllSongsWindow>(app, priv->songsPresenter);
});
attachPopups(
{gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock});
attachPopups({gui::popup::ID::Volume,
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::Alarm});
}
void ApplicationMusicPlayer::destroyUserInterface()

View File

@@ -128,8 +128,11 @@ namespace app
return std::make_unique<gui::OptionWindow>(app, name);
});
attachPopups(
{gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock});
attachPopups({gui::popup::ID::Volume,
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::Alarm});
}
void ApplicationNotes::destroyUserInterface()

View File

@@ -174,7 +174,8 @@ namespace app
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::SimLock});
gui::popup::ID::SimLock,
gui::popup::ID::Alarm});
}
void ApplicationOnBoarding::destroyUserInterface()

View File

@@ -136,8 +136,11 @@ namespace app
return std::make_unique<gui::PhonebookNewContact>(app);
});
attachPopups(
{gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock});
attachPopups({gui::popup::ID::Volume,
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::Alarm});
}
void ApplicationPhonebook::destroyUserInterface()

View File

@@ -573,7 +573,8 @@ namespace app
gui::popup::ID::Tethering,
gui::popup::ID::PhoneModes,
gui::popup::ID::PhoneLock,
gui::popup::ID::SimLock});
gui::popup::ID::SimLock,
gui::popup::ID::Alarm});
}
void ApplicationSettings::destroyUserInterface()

View File

@@ -40,6 +40,7 @@
#include <service-db/agents/settings/SystemSettings.hpp>
#include <service-audio/AudioServiceAPI.hpp> // for GetOutputVolume
#include <popups/AlarmPopup.hpp>
#include <popups/VolumeWindow.hpp>
#include <popups/HomeModesWindow.hpp>
#include <popups/TetheringPhoneModePopup.hpp>
@@ -57,6 +58,7 @@
#include <popups/data/PopupRequestParams.hpp>
#include <popups/data/PhoneModeParams.hpp>
#include <popups/data/BluetoothModeParams.hpp>
#include <popups/data/AlarmPopupParams.hpp>
#include <locks/data/LockData.hpp>
namespace gui
@@ -859,6 +861,10 @@ namespace app
return std::make_unique<gui::SimNotReadyWindow>(app, window::sim_not_ready_window);
});
break;
case ID::Alarm:
windowsFactory.attach(window::alarm_window, [](ApplicationCommon *app, const std::string &name) {
return std::make_unique<gui::AlarmPopup>(app, window::alarm_window);
});
default:
break;
}
@@ -898,6 +904,13 @@ namespace app
popupParams->getSimInputTypeAction(),
popupParams->getErrorCode()));
}
else if (id == ID::Alarm) {
auto popupParams = static_cast<const gui::AlarmPopupRequestParams *>(params);
switchWindow(gui::popup::resolveWindowName(id),
std::make_unique<gui::AlarmPopupParams>(popupParams->getPopupType(),
popupParams->getAlarmTimeString(),
popupParams->getSnoozeTimeString()));
}
else {
switchWindow(gui::popup::resolveWindowName(id));
}

View File

@@ -0,0 +1,151 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "AlarmPopup.hpp"
#include "data/AlarmPopupParams.hpp"
#include <InputEvent.hpp>
#include <i18n/i18n.hpp>
#include <ImageBox.hpp>
#include <TextFixedSize.hpp>
#include <ImageBoxWithText.hpp>
using namespace style::popup::alarm;
namespace gui
{
AlarmPopup::AlarmPopup(app::ApplicationCommon *app, const std::string &name) : AppWindow(app, name)
{
buildInterface();
}
void AlarmPopup::buildInterface()
{
AppWindow::buildInterface();
addArcOverlay();
createMainLayout();
}
void AlarmPopup::onBeforeShow(ShowMode mode, SwitchData *data)
{
/// Use AlarmPopupType to determine popup origin
if (auto params = dynamic_cast<AlarmPopupParams *>(data); params && mode == ShowMode::GUI_SHOW_INIT) {
bottomBar->setActive(BottomBar::Side::RIGHT, true);
bottomBar->setText(BottomBar::Side::RIGHT, utils::translate(style::strings::common::stop));
addAlarmLabels(params->getAlarmTimeString());
/// Apply snooze button visibility based on Event records (snooze interval != 0);
bottomBar->setActive(BottomBar::Side::CENTER, true);
bottomBar->setText(BottomBar::Side::CENTER, utils::translate(style::strings::common::select));
addSnoozeLabel(params->getSnoozeTimeString());
auto snoozeIcon = new ImageBoxWithText(
body, new Image("snooze_icon", ImageTypeSpecifier::W_G), utils::translate("app_popup_snooze_text"));
snoozeIcon->activatedCallback = [=](gui::Item &item) {
LOG_DEBUG("TODO: Add SNOOZE action");
return true;
};
setFocusItem(snoozeIcon);
body->resizeItems();
}
}
status_bar::Configuration AlarmPopup::configureStatusBar(status_bar::Configuration appConfiguration)
{
appConfiguration.enable(status_bar::Indicator::Time);
appConfiguration.enable(status_bar::Indicator::PhoneMode);
appConfiguration.enable(status_bar::Indicator::Battery);
appConfiguration.enable(status_bar::Indicator::Signal);
appConfiguration.enable(status_bar::Indicator::SimCard);
appConfiguration.enable(status_bar::Indicator::Bluetooth);
return appConfiguration;
}
bool AlarmPopup::onInput(const InputEvent &inputEvent)
{
if (inputEvent.isShortRelease() && inputEvent.is(KeyCode::KEY_RF)) {
LOG_DEBUG("TODO: Add STOP action");
return true;
}
if (AppWindow::onInput(inputEvent)) {
return true;
}
return false;
}
void AlarmPopup::addArcOverlay()
{
auto arcOverlay = new gui::ImageBox(this,
style::window::default_left_margin,
style::popup::alarm::window::y,
style::window::default_body_width,
style::window::default_body_width,
new Image(ImageCircle::name, ImageTypeSpecifier::W_G));
arcOverlay->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top));
arcOverlay->setEdges(RectangleEdge::None);
}
void AlarmPopup::createMainLayout()
{
body = new VBox(this,
style::window::default_left_margin,
style::popup::alarm::window::y,
style::window::default_body_width,
style::window::default_body_width);
body->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top));
body->setEdges(RectangleEdge::None);
}
void AlarmPopup::addAlarmLabels(std::string timeString)
{
auto alarmTimeLabel = new gui::TextFixedSize(body);
alarmTimeLabel->drawUnderline(false);
alarmTimeLabel->setFont(style::window::font::largelight);
alarmTimeLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top));
alarmTimeLabel->setText(timeString);
alarmTimeLabel->setMinimumWidthToFitText(alarmTimeLabel->getText());
alarmTimeLabel->setMinimumHeightToFitText();
alarmTimeLabel->setMargins(Margins(
0, style::popup::alarm::AlarmTimeLabel::top_margin, 0, style::popup::alarm::AlarmTimeLabel::bottom_margin));
auto alarmLabel = new gui::TextFixedSize(body);
alarmLabel->drawUnderline(false);
alarmLabel->setFont(style::window::font::mediumlight);
alarmLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top));
alarmLabel->setText(utils::translate("app_popup_alarm_text"));
alarmLabel->setMinimumWidthToFitText(alarmLabel->getText());
alarmLabel->setMinimumHeightToFitText();
}
void AlarmPopup::addSnoozeLabel(std::string timeString)
{
auto snoozeLabelBox = new VBox(body);
snoozeLabelBox->setMinimumSize(style::window::default_body_width, style::popup::alarm::SnoozeLabel::h);
snoozeLabelBox->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top));
snoozeLabelBox->setMargins(Margins(0, style::popup::alarm::SnoozeLabel::top_margin, 0, 0));
snoozeLabelBox->setEdges(RectangleEdge::None);
if (!timeString.empty()) {
auto snoozeLabel = new gui::TextFixedSize(snoozeLabelBox);
snoozeLabel->drawUnderline(false);
snoozeLabel->setFont(style::window::font::mediumlight);
snoozeLabel->setAlignment(
gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Bottom));
snoozeLabel->setText(utils::translate("app_popup_alarm_snoozed_till") + std::string{" "} + timeString);
snoozeLabel->setMinimumWidthToFitText(snoozeLabel->getText());
snoozeLabel->setMinimumHeightToFitText();
}
}
} // namespace gui

View File

@@ -0,0 +1,55 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
#include <AppWindow.hpp>
#include <string>
namespace style::popup::alarm
{
namespace window
{
inline constexpr auto y = 76U;
}
namespace ImageCircle
{
inline constexpr auto name = "vertical_arcs";
} // namespace ImageCircle
namespace AlarmTimeLabel
{
inline constexpr auto top_margin = 82U;
inline constexpr auto bottom_margin = 10U;
} // namespace AlarmTimeLabel
namespace SnoozeLabel
{
inline constexpr auto h = 58U;
inline constexpr auto top_margin = 104U;
} // namespace SnoozeLabel
} // namespace style::popup::alarm
namespace gui
{
class AlarmPopup : public AppWindow
{
public:
AlarmPopup(app::ApplicationCommon *app, const std::string &name);
void buildInterface() override;
void onBeforeShow(ShowMode mode, SwitchData *data) override;
bool onInput(const InputEvent &inputEvent) override;
status_bar::Configuration configureStatusBar(status_bar::Configuration appConfiguration) override;
private:
VBox *body = nullptr;
void addArcOverlay();
void createMainLayout();
void addAlarmLabels(std::string timeString);
void addSnoozeLabel(std::string timeString);
};
}; // namespace gui

View File

@@ -10,6 +10,7 @@ target_sources(apps-common
HomeModesWindow.cpp
Popups.cpp
PowerOffWindow.cpp
AlarmPopup.cpp
TetheringConfirmationPopup.cpp
TetheringNotificationPopup.cpp
TetheringPhoneModePopup.cpp
@@ -29,6 +30,7 @@ target_sources(apps-common
HomeModesWindow.hpp
Popups.hpp
PowerOffWindow.hpp
AlarmPopup.hpp
TetheringConfirmationPopup.hpp
TetheringNotificationPopup.hpp
TetheringPhoneModePopup.hpp
@@ -44,4 +46,5 @@ target_sources(apps-common
lock-popups/SimInfoWindow.hpp
lock-popups/SimNotReadyWindow.hpp
presenter/PowerOffPresenter.hpp
)

View File

@@ -36,6 +36,8 @@ namespace gui::popup
return gui::popup::window::alarm_activated_window;
case ID::AlarmDeactivated:
return gui::popup::window::alarm_deactivated_window;
case ID::Alarm:
return gui::popup::window::alarm_window;
}
return {};

View File

@@ -24,7 +24,8 @@ namespace gui
SimInfo,
SimNotReady,
AlarmActivated,
AlarmDeactivated
AlarmDeactivated,
Alarm
};
namespace window
@@ -45,6 +46,7 @@ namespace gui
inline constexpr auto sim_not_ready_window = "SimNotReadyPopup";
inline constexpr auto alarm_activated_window = "AlarmActivatedPopup";
inline constexpr auto alarm_deactivated_window = "AlarmDeactivatedPopup";
inline constexpr auto alarm_window = "AlarmPopup";
} // namespace window
std::string resolveWindowName(ID id);

View File

@@ -0,0 +1,48 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
#include "popups/Popups.hpp"
#include <service-appmgr/Actions.hpp>
#include <string>
namespace gui
{
enum class AlarmPopupType
{
AlarmRing,
SnoozeCheck
};
class AlarmPopupParams : public app::manager::actions::ActionParams
{
public:
explicit AlarmPopupParams(AlarmPopupType type, std::string alarmTime, std::string snoozeTime = std::string{})
: type{type}, alarmTime{alarmTime}, snoozeTime{snoozeTime}
{}
[[nodiscard]] AlarmPopupType getPopupType() const
{
return type;
}
[[nodiscard]] std::string getAlarmTimeString() const
{
return alarmTime;
}
[[nodiscard]] std::string getSnoozeTimeString() const
{
return snoozeTime;
}
private:
const AlarmPopupType type;
const std::string alarmTime;
const std::string snoozeTime;
};
} // namespace gui

View File

@@ -4,6 +4,7 @@
#pragma once
#include "popups/Popups.hpp"
#include "AlarmPopupParams.hpp"
#include <service-appmgr/Actions.hpp>
#include <PhoneModes/Common.hpp>
@@ -122,4 +123,35 @@ namespace gui
const audio::Volume volume;
const audio::Context audioContext;
};
class AlarmPopupRequestParams : public PopupRequestParams
{
public:
explicit AlarmPopupRequestParams(popup::ID popupId,
AlarmPopupType type,
std::string alarmTime,
std::string snoozeTime = std::string{})
: PopupRequestParams{popupId}, type{type}, alarmTime{alarmTime}, snoozeTime{snoozeTime}
{}
[[nodiscard]] AlarmPopupType getPopupType() const
{
return type;
}
[[nodiscard]] std::string getAlarmTimeString() const
{
return alarmTime;
}
[[nodiscard]] std::string getSnoozeTimeString() const
{
return snoozeTime;
}
private:
const AlarmPopupType type;
const std::string alarmTime;
const std::string snoozeTime;
};
} // namespace gui

View File

@@ -9,6 +9,7 @@ target_sources( ${PROJECT_NAME}
"${CMAKE_CURRENT_LIST_DIR}/Icon.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Image.cpp"
"${CMAKE_CURRENT_LIST_DIR}/ImageBox.cpp"
"${CMAKE_CURRENT_LIST_DIR}/ImageBoxWithText.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Item.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Label.cpp"
"${CMAKE_CURRENT_LIST_DIR}/ListItem.cpp"
@@ -67,6 +68,7 @@ target_sources( ${PROJECT_NAME}
"${CMAKE_CURRENT_LIST_DIR}/Circle.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Image.hpp"
"${CMAKE_CURRENT_LIST_DIR}/ImageBox.hpp"
"${CMAKE_CURRENT_LIST_DIR}/ImageBoxWithText.hpp"
"${CMAKE_CURRENT_LIST_DIR}/TextFixedSize.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Item.hpp"
"${CMAKE_CURRENT_LIST_DIR}/Label.hpp"

View File

@@ -32,10 +32,10 @@ namespace gui
set(imageName, specifier);
}
Image::Image(const UTF8 &imageName) : imageMap{nullptr}
Image::Image(const UTF8 &imageName, ImageTypeSpecifier specifier) : imageMap{nullptr}
{
type = ItemType::IMAGE;
set(imageName);
set(imageName, specifier);
}
bool Image::set(int id)

View File

@@ -23,7 +23,7 @@ namespace gui
public:
Image();
/// create new Image element and resize it to size needed by selected Image
Image(const UTF8 &);
Image(const UTF8 &imageName, ImageTypeSpecifier specifier = ImageTypeSpecifier::None);
Image(Item *parent, const UTF8 &imageName, ImageTypeSpecifier specifier = ImageTypeSpecifier::None);
/// Create new Image element on position x,y w&h will be *ignored*
Image(Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h, const UTF8 = UTF8{""});

View File

@@ -6,7 +6,7 @@
using namespace gui;
ImageBox::ImageBox(Item *parent, const Position &x, const Position &y, const Length &w, const Length &h, Image *image)
: HBox(parent, x, y, w, h), image(image)
: VBox(parent, x, y, w, h), image(image)
{
setEdges(RectangleEdge::None);
setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));

View File

@@ -8,7 +8,7 @@
namespace gui
{
class ImageBox : public HBox
class ImageBox : public VBox
{
public:
ImageBox(Item *parent, const Position &x, const Position &y, const Length &w, const Length &h, Image *image);
@@ -18,9 +18,9 @@ namespace gui
void showImage(bool show);
void setImage(const UTF8 &name);
void setMinimumSizeToFitImage();
virtual void setMinimumSizeToFitImage();
private:
protected:
Image *image;
};
}; // namespace gui

View File

@@ -0,0 +1,52 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "ImageBoxWithText.hpp"
using namespace gui;
ImageBoxWithText::ImageBoxWithText(Item *parent,
const Position &x,
const Position &y,
const Length &w,
const Length &h,
Image *image,
const UTF8 &description)
: ImageBox(parent, x, y, w, h, image)
{
setText(description);
setMinimumSize(imageBoxWithText::wh, imageBoxWithText::wh);
image->setEdges(RectangleEdge::All);
focusChangedCallback = [&](Item &item) {
if (focus) {
setEdges(RectangleEdge::Bottom | RectangleEdge::Top);
}
else {
setEdges(RectangleEdge::None);
}
return true;
};
}
ImageBoxWithText::ImageBoxWithText(Item *parent, Image *image, const UTF8 &description)
: ImageBoxWithText(parent, 0, 0, 0, 0, image, description)
{}
void ImageBoxWithText::setText(const UTF8 &description)
{
text = new TextFixedSize(this);
text->drawUnderline(false);
text->setMargins(Margins(0, imageBoxWithText::text_margin, 0, imageBoxWithText::text_margin));
text->setFont(imageBoxWithText::font);
text->setText(description);
text->setMinimumWidthToFitText(description);
text->setMinimumHeightToFitText();
}
void ImageBoxWithText::setMinimumSizeToFitImage()
{
auto minW = std::max(image->getWidth(), text->widgetMinimumArea.w);
auto minH = image->getHeight() + imageBoxWithText::text_margin + text->widgetMinimumArea.h;
setMinimumSize(minW, minH);
}

View File

@@ -0,0 +1,38 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
#include <ImageBox.hpp>
#include <TextFixedSize.hpp>
namespace gui
{
namespace imageBoxWithText
{
inline constexpr auto wh = 100;
inline constexpr auto text_margin = 5;
inline constexpr auto font = style::window::font::verysmall;
} // namespace imageBoxWithText
class ImageBoxWithText : public ImageBox
{
public:
ImageBoxWithText(Item *parent,
const Position &x,
const Position &y,
const Length &w,
const Length &h,
Image *image,
const UTF8 &description);
ImageBoxWithText(Item *parent, Image *image, const UTF8 &description);
~ImageBoxWithText() override = default;
void setText(const UTF8 &description);
void setMinimumSizeToFitImage() override;
protected:
TextFixedSize *text;
};
}; // namespace gui