This commit is contained in:
IlyaShurupov 2024-05-03 15:09:26 +03:00
parent 86a41c1876
commit e2072d257f
14 changed files with 594 additions and 341 deletions

View file

@ -6,14 +6,9 @@ namespace tp {
template <typename Events, typename Canvas>
class LabelWidget : public Widget<Events, Canvas> {
public:
LabelWidget() {
this->createConfig("Label");
this->addValue("Size", "FontSize");
this->addValue("Padding", "Padding");
this->addColor("Default", "Front");
}
LabelWidget() { this->mId = "Label"; }
void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) override {
void proc(const Events&, const tp::RectF& areaParent, const tp::RectF& aArea) override {
this->mArea = aArea;
this->mVisible = areaParent.isOverlap(aArea);
if (!this->mVisible) return;
@ -21,18 +16,28 @@ namespace tp {
void draw(Canvas& canvas) override {
if (!this->mVisible) return;
canvas.text(mLabel.c_str(), this->mArea, fontSize, Canvas::CC, padding, fontColor);
}
canvas.text(
mLabel.c_str(),
this->mArea,
this->getValue("Size"),
Canvas::CC,
this->getValue("Padding"),
this->getColor("Default")
);
public:
void setupConfig(WidgetManager& wm) {
if (!wm.createWidgetConfig(this->mId)) return;
wm.addReference(this->mId, "Size", "FontSize");
wm.addReference(this->mId, "Padding", "Padding");
wm.addReference(this->mId, "Default", "Front");
}
void updateConfigCache(const WidgetManager& wm) override {
fontSize = wm.getNumber(this->mId, "Size");
padding = wm.getNumber(this->mId, "Padding");
fontColor = wm.getColor(this->mId, "Default");
}
public:
std::string mLabel = "Label";
halnf fontSize = 10;
halnf padding = 0;
RGBA fontColor = { 1, 1, 1, 1 };
};
}