#include "../graphics/Font.hpp"
#include "../graphics/Viewport.hpp"
+#include <iomanip>
+#include <sstream>
#include <glm/gtx/transform.hpp>
}
void Label::Draw(app::Assets &assets, graphics::Viewport &viewport) noexcept {
+ if (text.empty()) return;
Update();
glm::vec2 size = Size();
}
void Label::Update() {
- if (!dirty) return;
+ if (!dirty || text.empty()) return;
font->Render(text, tex);
dirty = false;
}
Panel *Panel::Direction(Dir d) {
dir = d;
- Relayout();
+ Layout();
return this;
}
return (2.0f * padding) + space + size;
}
-void Panel::Relayout() {
+void Panel::Layout() {
size = glm::vec2(0.0f);
if (dir == HORIZONTAL) {
for (auto &w : widgets) {
}
void Panel::Draw(app::Assets &assets, graphics::Viewport &viewport) noexcept {
+ // TODO: separate draw and layout, it's inefficient and the wrong tree order anyway
+ Layout();
if (bg_color.a > 0.0f) {
assets.shaders.canvas.Activate();
assets.shaders.canvas.ZIndex(ZIndex());
assets.shaders.canvas.FillRect(Position(), Position() + Size());
}
- glm::vec2 cursor = Position();
- cursor.x += padding.x;
- cursor.y += padding.y;
+ glm::vec2 cursor = Position() + padding;
for (auto &w : widgets) {
w->Position(cursor)->ZIndex(ZIndex() + 1.0f);
w->Draw(assets, viewport);