knxdisplay/main/widgets/LabelWidget.cpp
2026-01-24 10:42:15 +01:00

43 lines
1.0 KiB
C++

#include "LabelWidget.hpp"
#include <cstdio>
LabelWidget::LabelWidget(const WidgetConfig& config)
: Widget(config)
{
}
lv_obj_t* LabelWidget::create(lv_obj_t* parent) {
obj_ = lv_label_create(parent);
lv_label_set_text(obj_, config_.text);
lv_obj_set_pos(obj_, config_.x, config_.y);
if (config_.width > 0 && config_.height > 0) {
lv_obj_set_size(obj_, config_.width, config_.height);
}
return obj_;
}
void LabelWidget::onKnxValue(float value) {
if (obj_ == nullptr) return;
if (config_.textSource != TextSource::KNX_DPT_TEMP) return;
char buf[32];
snprintf(buf, sizeof(buf), config_.text, value);
lv_label_set_text(obj_, buf);
}
void LabelWidget::onKnxSwitch(bool value) {
if (obj_ == nullptr) return;
if (config_.textSource != TextSource::KNX_DPT_SWITCH) return;
lv_label_set_text(obj_, value ? "EIN" : "AUS");
}
void LabelWidget::onKnxText(const char* text) {
if (obj_ == nullptr) return;
if (config_.textSource != TextSource::KNX_DPT_TEXT) return;
lv_label_set_text(obj_, text);
}