Added CheckBox

This commit is contained in:
MihailRis
2023-11-18 23:19:15 +03:00
parent 9cd8870bd6
commit dda9c40c41
5 changed files with 93 additions and 6 deletions
+34
View File
@@ -192,4 +192,38 @@ void TrackBar::mouseMove(GUI*, int x, int y) {
if (consumer_) {
consumer_(value);
}
}
CheckBox::CheckBox(bool checked) : UINode(vec2(), vec2(32.0f)), checked_(checked) {
color(vec4(0.0f, 0.0f, 0.0f, 0.5f));
}
void CheckBox::draw(Batch2D* batch, Assets* assets) {
if (supplier_) {
checked_ = supplier_();
}
vec2 coord = calcCoord();
batch->texture(nullptr);
batch->color = checked_ ? checkColor : (hover_ ? hoverColor : color_);
batch->rect(coord.x, coord.y, size_.x, size_.y);
}
void CheckBox::mouseRelease(GUI*, int x, int y) {
checked_ = !checked_;
if (consumer_) {
consumer_(checked_);
}
}
void CheckBox::supplier(boolsupplier supplier) {
supplier_ = supplier;
}
void CheckBox::consumer(boolconsumer consumer) {
consumer_ = consumer;
}
CheckBox* CheckBox::checked(bool flag) {
checked_ = flag;
return this;
}