a huge pile of boilerplate code

This commit is contained in:
MihailRis
2024-02-19 14:13:06 +03:00
parent 164d6400d9
commit 7792c1a6f4
5 changed files with 179 additions and 2 deletions
+58
View File
@@ -150,6 +150,14 @@ std::wstring Button::getText() const {
return L"";
}
glm::vec4 Button::getPressedColor() const {
return pressedColor;
}
void Button::setPressedColor(glm::vec4 color) {
pressedColor = color;
}
Button* Button::textSupplier(wstringsupplier supplier) {
if (label) {
label->textSupplier(supplier);
@@ -402,6 +410,7 @@ TrackBar::TrackBar(double min,
step(step),
trackWidth(trackWidth) {
setColor(glm::vec4(0.f, 0.f, 0.f, 0.4f));
setHoverColor(glm::vec4(0.01f, 0.02f, 0.03f, 0.5f));
}
void TrackBar::draw(const GfxContext* pctx, Assets* assets) {
@@ -444,6 +453,55 @@ void TrackBar::mouseMove(GUI*, int x, int y) {
}
}
double TrackBar::getValue() const {
return value;
}
double TrackBar::getMin() const {
return min;
}
double TrackBar::getMax() const {
return max;
}
double TrackBar::getStep() const {
return step;
}
int TrackBar::getTrackWidth() const {
return trackWidth;
}
glm::vec4 TrackBar::getTrackColor() const {
return trackColor;
}
void TrackBar::setValue(double x) {
value = x;
}
void TrackBar::setMin(double x) {
min = x;
}
void TrackBar::setMax(double x) {
max = x;
}
void TrackBar::setStep(double x) {
step = x;
}
void TrackBar::setTrackWidth(int width) {
trackWidth = width;
}
void TrackBar::setTrackColor(glm::vec4 color) {
trackColor = color;
}
// ================================ CheckBox ==================================
CheckBox::CheckBox(bool checked) : UINode(glm::vec2(), glm::vec2(32.0f)), checked(checked) {
setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
+17 -1
View File
@@ -72,6 +72,9 @@ namespace gui {
virtual void setText(std::wstring text);
virtual std::wstring getText() const;
virtual glm::vec4 getPressedColor() const;
virtual void setPressedColor(glm::vec4 color);
virtual Button* textSupplier(wstringsupplier supplier);
virtual void refresh() override;
@@ -144,7 +147,6 @@ namespace gui {
class TrackBar : public UINode {
protected:
glm::vec4 hoverColor {0.01f, 0.02f, 0.03f, 0.5f};
glm::vec4 trackColor {1.0f, 1.0f, 1.0f, 0.4f};
doublesupplier supplier = nullptr;
doubleconsumer consumer = nullptr;
@@ -165,6 +167,20 @@ namespace gui {
virtual void setConsumer(doubleconsumer consumer);
virtual void mouseMove(GUI*, int x, int y) override;
virtual double getValue() const;
virtual double getMin() const;
virtual double getMax() const;
virtual double getStep() const;
virtual int getTrackWidth() const;
virtual glm::vec4 getTrackColor() const;
virtual void setValue(double);
virtual void setMin(double);
virtual void setMax(double);
virtual void setStep(double);
virtual void setTrackWidth(int);
virtual void setTrackColor(glm::vec4);
};
class CheckBox : public UINode {
+16 -1
View File
@@ -32,7 +32,13 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no
node.setSize(element->attr("size").asVec2());
}
if (element->has("color")) {
node.setColor(element->attr("color").asColor());
glm::vec4 color = element->attr("color").asColor();
glm::vec4 hoverColor = color;
if (element->has("hover-color")) {
hoverColor = node.getHoverColor();
}
node.setColor(color);
node.setHoverColor(hoverColor);
}
if (element->has("margin")) {
node.setMargin(element->attr("margin").asVec4());
@@ -54,6 +60,9 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no
);
node.setPositionFunc(supplier);
}
if (element->has("hover-color")) {
node.setHoverColor(element->attr("hover-color").asColor());
}
std::string alignName = element->attr("align", "").getText();
node.setAlign(align_from_string(alignName, node.getAlign()));
}
@@ -163,6 +172,9 @@ static std::shared_ptr<UINode> readButton(UiXmlReader& reader, xml::xmlelement e
if (element->has("text-align")) {
button->setTextAlign(align_from_string(element->attr("text-align").getText(), button->getTextAlign()));
}
if (element->has("pressed-color")) {
button->setPressedColor(element->attr("pressed-color").asColor());
}
return button;
}
@@ -216,6 +228,9 @@ static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, xml::xmlelement
);
bar->setSupplier(supplier);
}
if (element->has("track-color")) {
bar->setTrackColor(element->attr("track-color").asColor());
}
return bar;
}