Skip to content

Commit

Permalink
gauge min, max, threshold, styles
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jul 27, 2021
1 parent db321d2 commit bb25dde
Show file tree
Hide file tree
Showing 5 changed files with 321 additions and 43 deletions.
16 changes: 10 additions & 6 deletions src/eez/gui/assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,21 @@ const PageAsset* getPageAsset(int pageId, WidgetCursor& widgetCursor) {
}

const Style *getStyle(int styleID) {
if (styleID <= 0) {
return nullptr;
if (styleID > 0) {
return g_mainAssets->styles.item(g_mainAssets, styleID - 1);
} else if (styleID < 0) {
return g_externalAssets->styles.item(g_externalAssets, -styleID - 1);
}
return g_mainAssets->styles.item(g_mainAssets, styleID - 1);
return nullptr;
}

const FontData *getFontData(int fontID) {
if (fontID <= 0) {
return nullptr;
if (fontID > 0) {
return g_mainAssets->fonts.item(g_mainAssets, fontID - 1);
} else if (fontID < 0) {
return g_externalAssets->fonts.item(g_externalAssets, -fontID - 1);
}
return g_mainAssets->fonts.item(g_mainAssets, fontID - 1);
return nullptr;
}

const Bitmap *getBitmap(int bitmapID) {
Expand Down
27 changes: 16 additions & 11 deletions src/eez/gui/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ struct PairOfInt16Value {
#define FLOAT_OPTIONS_SET_NUM_FIXED_DECIMALS(n) (FLOAT_OPTIONS_FIXED_DECIMALS | ((n & 0b111) << 2))

struct RefString {
uint32_t refCounter;
char *str;
uint32_t refCounter{0};
char *str{nullptr};
};

struct Value {
Expand Down Expand Up @@ -199,7 +199,10 @@ struct Value {
}

Value(const Value& value) {
memcpy(this, &value, sizeof(Value));
type_ = value.type_;
unit_ = value.unit_;
options_ = value.options_;
int64_ = value.int64_;
if (type_ == VALUE_TYPE_STRING_REF) {
refString_.refCounter++;
}
Expand All @@ -208,7 +211,9 @@ struct Value {
~Value() {
if (type_ == VALUE_TYPE_STRING_REF) {
if (--refString_.refCounter == 0) {
free((char *)refString_.str);
if (refString_.str) {
free((char *)refString_.str);
}
}
}
}
Expand All @@ -224,7 +229,7 @@ struct Value {
}

bool isInt32OrLess() const {
return type_ >= VALUE_TYPE_INT8 && type_ <= VALUE_TYPE_UINT32 || type_ == VALUE_TYPE_BOOLEAN;
return (type_ >= VALUE_TYPE_INT8 && type_ <= VALUE_TYPE_UINT32) || type_ == VALUE_TYPE_BOOLEAN;
}

bool isInt64() const {
Expand Down Expand Up @@ -382,7 +387,7 @@ struct Value {
if (type_ == VALUE_TYPE_FLOAT) {
return float_;
}
if (type_ >= VALUE_TYPE_INT8 && type_ <= VALUE_TYPE_INT32 || type_ == VALUE_TYPE_BOOLEAN) {
if ((type_ >= VALUE_TYPE_INT8 && type_ <= VALUE_TYPE_INT32) || type_ == VALUE_TYPE_BOOLEAN) {
return int32_;
}
if (type_ == VALUE_TYPE_UINT32) {
Expand All @@ -407,7 +412,7 @@ struct Value {
if (type_ == VALUE_TYPE_FLOAT) {
return float_;
}
if (type_ >= VALUE_TYPE_INT8 && type_ <= VALUE_TYPE_INT32 || type_ == VALUE_TYPE_BOOLEAN) {
if ((type_ >= VALUE_TYPE_INT8 && type_ <= VALUE_TYPE_INT32) || type_ == VALUE_TYPE_BOOLEAN) {
return (float)int32_;
}
if (type_ == VALUE_TYPE_UINT32) {
Expand All @@ -432,7 +437,7 @@ struct Value {
if (type_ == VALUE_TYPE_FLOAT) {
return (int32_t)float_;
}
if (type_ >= VALUE_TYPE_INT8 && type_ <= VALUE_TYPE_INT32 || type_ == VALUE_TYPE_BOOLEAN) {
if ((type_ >= VALUE_TYPE_INT8 && type_ <= VALUE_TYPE_INT32) || type_ == VALUE_TYPE_BOOLEAN) {
return (int32_t)int32_;
}
if (type_ == VALUE_TYPE_UINT32) {
Expand All @@ -447,7 +452,7 @@ struct Value {
if (type_ == VALUE_TYPE_STRING_REF) {
return (int64_t)atoi(refString_.str);
}
return NAN;
return 0;
}

int64_t toInt64() const {
Expand All @@ -457,7 +462,7 @@ struct Value {
if (type_ == VALUE_TYPE_FLOAT) {
return (int64_t)float_;
}
if (type_ >= VALUE_TYPE_INT8 && type_ <= VALUE_TYPE_INT32 || type_ == VALUE_TYPE_BOOLEAN) {
if ((type_ >= VALUE_TYPE_INT8 && type_ <= VALUE_TYPE_INT32) || type_ == VALUE_TYPE_BOOLEAN) {
return (int64_t)int32_;
}
if (type_ == VALUE_TYPE_UINT32) {
Expand All @@ -472,7 +477,7 @@ struct Value {
if (type_ == VALUE_TYPE_STRING_REF) {
return (int64_t)atoi(refString_.str);
}
return NAN;
return 0;
}

//////////
Expand Down
Loading

0 comments on commit bb25dde

Please sign in to comment.