82 lines
2.0 KiB
C++
82 lines
2.0 KiB
C++
#include "Widget.hpp"
|
|
#include "../Fonts.hpp"
|
|
|
|
Widget::Widget(const WidgetConfig& config)
|
|
: config_(config)
|
|
, obj_(nullptr)
|
|
{
|
|
}
|
|
|
|
Widget::~Widget() {
|
|
destroy();
|
|
}
|
|
|
|
void Widget::destroy() {
|
|
if (obj_ != nullptr) {
|
|
if (lv_obj_is_valid(obj_)) {
|
|
lv_obj_delete(obj_);
|
|
}
|
|
obj_ = nullptr;
|
|
}
|
|
}
|
|
|
|
void Widget::applyStyle() {
|
|
if (obj_ == nullptr) return;
|
|
applyCommonStyle();
|
|
}
|
|
|
|
void Widget::onKnxValue(float /*value*/) {
|
|
// Default: do nothing
|
|
}
|
|
|
|
void Widget::onKnxSwitch(bool /*value*/) {
|
|
// Default: do nothing
|
|
}
|
|
|
|
void Widget::onKnxText(const char* /*text*/) {
|
|
// Default: do nothing
|
|
}
|
|
|
|
void Widget::applyCommonStyle() {
|
|
if (obj_ == nullptr) return;
|
|
|
|
// Text color
|
|
lv_obj_set_style_text_color(obj_, lv_color_make(
|
|
config_.textColor.r, config_.textColor.g, config_.textColor.b), 0);
|
|
|
|
// Font
|
|
lv_obj_set_style_text_font(obj_, getFontBySize(config_.fontSize), 0);
|
|
|
|
// Background (for buttons and labels with bg)
|
|
if (config_.bgOpacity > 0) {
|
|
lv_obj_set_style_bg_color(obj_, lv_color_make(
|
|
config_.bgColor.r, config_.bgColor.g, config_.bgColor.b), 0);
|
|
lv_obj_set_style_bg_opa(obj_, config_.bgOpacity, 0);
|
|
}
|
|
|
|
// Border radius
|
|
if (config_.borderRadius > 0) {
|
|
lv_obj_set_style_radius(obj_, config_.borderRadius, 0);
|
|
}
|
|
|
|
// Shadow
|
|
applyShadowStyle();
|
|
}
|
|
|
|
void Widget::applyShadowStyle() {
|
|
|
|
if (obj_ == nullptr || !config_.shadow.enabled) return;
|
|
|
|
lv_obj_set_style_shadow_color(obj_, lv_color_make(
|
|
config_.shadow.color.r, config_.shadow.color.g, config_.shadow.color.b), 0);
|
|
lv_obj_set_style_shadow_opa(obj_, 180, 0);
|
|
lv_obj_set_style_shadow_width(obj_, config_.shadow.blur, 0);
|
|
lv_obj_set_style_shadow_spread(obj_, config_.shadow.spread, 0);
|
|
lv_obj_set_style_shadow_offset_x(obj_, config_.shadow.offsetX, 0);
|
|
lv_obj_set_style_shadow_offset_y(obj_, config_.shadow.offsetY, 0);
|
|
}
|
|
|
|
const lv_font_t* Widget::getFontBySize(uint8_t sizeIndex) {
|
|
return Fonts::bySizeIndex(sizeIndex);
|
|
}
|