Skip to content

Commit

Permalink
fix: proper locking for widget read methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasssadar committed Jan 19, 2025
1 parent 09573aa commit b5f50a2
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 92 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"maintainer": true
}
],
"version": "5.3.3",
"version": "5.4.0",
"frameworks": ["espidf", "arduino"],
"platforms": "espressif32",
"dependencies": [
Expand Down
2 changes: 1 addition & 1 deletion src/gridui_version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma once

#define RB_GRIDUI_VERSION 0x050303
#define RB_GRIDUI_VERSION 0x050400
4 changes: 2 additions & 2 deletions src/widgets/arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class Arm : public Widget {

public:
double x() const {
return data().getDouble("armX");
return m_state->getDouble("armX");
}

double y() const {
return data().getDouble("armY");
return m_state->getDouble("armY");
}
};

Expand Down
12 changes: 6 additions & 6 deletions src/widgets/bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,47 @@ class Bar : public Widget {
}

std::string color() const {
return data().getString("color");
return m_state->getString("color");
}

void setFontSize(float fontSize) {
m_state->set("fontSize", new rbjson::Number(fontSize));
}

float fontSize() const {
return data().getDouble("fontSize");
return m_state->getDouble("fontSize");
}

void setMin(float min) {
m_state->set("min", new rbjson::Number(min));
}

float min() const {
return data().getDouble("min");
return m_state->getDouble("min");
}

void setMax(float max) {
m_state->set("max", new rbjson::Number(max));
}

float max() const {
return data().getDouble("max");
return m_state->getDouble("max");
}

void setValue(float value) {
m_state->set("value", new rbjson::Number(value));
}

float value() const {
return data().getDouble("value");
return m_state->getDouble("value");
}

void setShowValue(bool showValue) {
m_state->set("showValue", new rbjson::Bool(showValue));
}

bool showValue() const {
return data().getBool("showValue");
return m_state->getBool("showValue");
}
};

Expand Down
16 changes: 8 additions & 8 deletions src/widgets/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,47 @@ class Button : public Widget {
}

std::string text() const {
return data().getString("text");
return m_state->getString("text");
}

void setFontSize(float fontSize) {
m_state->set("fontSize", new rbjson::Number(fontSize));
}

float fontSize() const {
return data().getDouble("fontSize");
return m_state->getDouble("fontSize");
}

void setColor(const std::string& color) {
m_state->set("color", new rbjson::String(color));
}

std::string color() const {
return data().getString("color");
return m_state->getString("color");
}

void setBackground(const std::string& background) {
m_state->set("background", new rbjson::String(background));
}

std::string background() const {
return data().getString("background");
return m_state->getString("background");
}

void setAlign(const std::string& align) {
m_state->set("align", new rbjson::String(align));
}

std::string align() const {
return data().getString("align");
return m_state->getString("align");
}

void setValign(const std::string& valign) {
m_state->set("valign", new rbjson::String(valign));
}

std::string valign() const {
return data().getString("valign");
return m_state->getString("valign");
}

void setNumber(float number) {
Expand All @@ -67,15 +67,15 @@ class Button : public Widget {
}

bool pressed() const {
return data().getBool("pressed");
return m_state->getBool("pressed");
}

void setDisabled(bool disabled) {
m_state->set("disabled", new rbjson::Bool(disabled));
}

bool disabled() const {
return data().getBool("disabled");
return m_state->getBool("disabled");
}
};

Expand Down
12 changes: 7 additions & 5 deletions src/widgets/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,31 @@ class Camera : public Widget {
}

float rotation() const {
return data().getDouble("rotation");
return m_state->getDouble("rotation");
}

void setClip(bool clip) {
m_state->set("clip", new rbjson::Bool(clip));
}

bool clip() const {
return data().getBool("clip");
return m_state->getBool("clip");
}

void addTag(const Tag& t) {
auto* tagsArray = data().getArray("tags");
auto lock = m_state->uniqueStateLock();

auto* tagsArray = m_state->dataLocked().getArray("tags");
const bool existedBefore = tagsArray != NULL;
if (!existedBefore) {
tagsArray = new rbjson::Array;
}
tagsArray->push_back(buildTagObject(t));

lock.unlock();

if (!existedBefore) {
m_state->set("tags", tagsArray);
}
{
m_state->markChanged("tags");
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/widgets/checkbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ class Checkbox : public Widget {
}

float fontSize() const {
return data().getDouble("fontSize");
return m_state->getDouble("fontSize");
}

void setChecked(bool checked) {
m_state->set("checked", new rbjson::Bool(checked));
}

bool checked() const {
return data().getBool("checked");
return m_state->getBool("checked");
}

void setColor(const std::string& color) {
m_state->set("color", new rbjson::String(color));
}

std::string color() const {
return data().getString("color");
return m_state->getString("color");
}

void setText(const std::string& text) {
m_state->set("text", new rbjson::String(text));
}

std::string text() const {
return data().getString("text");
return m_state->getString("text");
}
};

Expand Down
16 changes: 8 additions & 8 deletions src/widgets/circle.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,63 +18,63 @@ class Circle : public Widget {
}

std::string color() const {
return data().getString("color");
return m_state->getString("color");
}

void setFontSize(float fontSize) {
m_state->set("fontSize", new rbjson::Number(fontSize));
}

float fontSize() const {
return data().getDouble("fontSize");
return m_state->getDouble("fontSize");
}

void setMin(float min) {
m_state->set("min", new rbjson::Number(min));
}

float min() const {
return data().getDouble("min");
return m_state->getDouble("min");
}

void setMax(float max) {
m_state->set("max", new rbjson::Number(max));
}

float max() const {
return data().getDouble("max");
return m_state->getDouble("max");
}

void setLineWidth(float lineWidth) {
m_state->set("lineWidth", new rbjson::Number(lineWidth));
}

float lineWidth() const {
return data().getDouble("lineWidth");
return m_state->getDouble("lineWidth");
}

void setValueStart(float valueStart) {
m_state->set("valueStart", new rbjson::Number(valueStart));
}

float valueStart() const {
return data().getDouble("valueStart");
return m_state->getDouble("valueStart");
}

void setValue(float value) {
m_state->set("value", new rbjson::Number(value));
}

float value() const {
return data().getDouble("value");
return m_state->getDouble("value");
}

void setShowValue(bool showValue) {
m_state->set("showValue", new rbjson::Bool(showValue));
}

bool showValue() const {
return data().getBool("showValue");
return m_state->getBool("showValue");
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/widgets/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ class Input : public Widget {
}

std::string text() const {
return data().getString("text");
return m_state->getString("text");
}

void setColor(const std::string& color) {
m_state->set("color", new rbjson::String(color));
}

std::string color() const {
return data().getString("color");
return m_state->getString("color");
}

void setType(const std::string& type) {
m_state->set("type", new rbjson::String(type));
}

std::string type() const {
return data().getString("type");
return m_state->getString("type");
}

void setDisabled(bool disabled) {
m_state->set("disabled", new rbjson::Bool(disabled));
}

bool disabled() const {
return data().getBool("disabled");
return m_state->getBool("disabled");
}
};

Expand Down
10 changes: 5 additions & 5 deletions src/widgets/joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ class Joystick : public Widget {
}

std::string color() const {
return data().getString("color");
return m_state->getString("color");
}

void setKeys(const std::string& keys) {
m_state->set("keys", new rbjson::String(keys));
}

std::string keys() const {
return data().getString("keys");
return m_state->getString("keys");
}

void setText(const std::string& text) {
m_state->set("text", new rbjson::String(text));
}

std::string text() const {
return data().getString("text");
return m_state->getString("text");
}

int32_t x() const {
return data().getInt("jx");
return m_state->getInt("jx");
}

int32_t y() const {
return data().getInt("jy");
return m_state->getInt("jy");
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/widgets/led.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class Led : public Widget {
}

std::string color() const {
return data().getString("color");
return m_state->getString("color");
}

void setOn(bool on) {
m_state->set("on", new rbjson::Bool(on));
}

bool on() const {
return data().getBool("on");
return m_state->getBool("on");
}
};

Expand Down
Loading

0 comments on commit b5f50a2

Please sign in to comment.