Skip to content

Commit

Permalink
Added more details while fetching the results using Widget::toJson()
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeriiKoniushenko committed Jul 27, 2023
1 parent ddffd93 commit 7ffa626
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/core/shapes/include/LineText.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class LineText : public Widget
_NODISCARD const std::string& getText() const;
void setText(const std::string& text);

_NODISCARD float getTextWidth();
_NODISCARD float getTextWidth() const;
_NODISCARD float getFontSize() const;
void setFontSize(float size);

Expand All @@ -63,6 +63,9 @@ class LineText : public Widget

void draw(ShaderPack& shader) override;

_NODISCARD boost::property_tree::ptree toJson() const override;
_NODISCARD std::string getComponentName() const override;

private:
void updateCache();
float getHeightOfTheBiggestLetter();
Expand All @@ -74,7 +77,7 @@ class LineText : public Widget
Font* font_;
std::string text_;
std::string lastSavedText_;
float textWidth_ = -1.f;
mutable float textWidth_ = -1.f;
Vbo vbo_;
Vao vao_;
float fontSize_ = 24.f;
Expand Down
30 changes: 29 additions & 1 deletion lib/core/shapes/source/LineText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ float LineText::getHeightOfTheBiggestLetter()
return maxSize;
}

float LineText::getTextWidth()
float LineText::getTextWidth() const
{
if (lastSavedText_ == text_)
{
Expand Down Expand Up @@ -261,3 +261,31 @@ const Color& LineText::getColor() const
{
return color_;
}

boost::property_tree::ptree LineText::toJson() const
{
auto tree = Widget::toJson();

boost::property_tree::ptree text;
text.put("color", std::format("{} {} {} {}", color_.r, color_.g, color_.b, color_.a));
text.put("text", text_);
text.put("text-width", getTextWidth());
text.put("font-size", fontSize_);
text.put("vbo", vbo_.getId());
text.put("vao", vao_.getId());
if (font_)
{
boost::property_tree::ptree font;

font.put("default-render-size", Font::defaultRenderSize);

text.put_child("font", font);
}
tree.put_child("text", text);
return tree;
}

std::string LineText::getComponentName() const
{
return "line-text";
}

0 comments on commit 7ffa626

Please sign in to comment.