This commit is contained in:
MihailRis 2025-11-14 20:56:11 +03:00
parent 95721a6864
commit 5f76e72748
18 changed files with 44 additions and 44 deletions

View File

@ -30,14 +30,14 @@ namespace gui {
glm::vec2 size, glm::vec2 size,
glm::vec4 padding = glm::vec4(0.0f), glm::vec4 padding = glm::vec4(0.0f),
float interval = 2.0f, float interval = 2.0f,
Orientation orientation = Orientation::vertical Orientation orientation = Orientation::VERTICAL
) )
: Container(gui, std::move(size)), : Container(gui, std::move(size)),
padding(std::move(padding)), padding(std::move(padding)),
interval(interval) { interval(interval) {
} }
Orientation orientation = Orientation::vertical; Orientation orientation = Orientation::VERTICAL;
glm::vec4 padding; glm::vec4 padding;
float interval = 2.0f; float interval = 2.0f;
}; };

View File

@ -20,7 +20,7 @@ void gui::Canvas::draw(const DrawContext& pctx, const Assets& assets) {
batch->rect(pos.x, pos.y, size.x, size.y, 0, 0, 0, {}, false, false, col); batch->rect(pos.x, pos.y, size.x, size.y, 0, 0, 0, {}, false, false, col);
} }
void gui::Canvas::setSize(glm::vec2 size) { void gui::Canvas::setSize(const glm::vec2& size) {
UINode::setSize(size); UINode::setSize(size);
data->extend(size.x, size.y); data->extend(size.x, size.y);
texture->reload(*data); texture->reload(*data);

View File

@ -15,7 +15,7 @@ namespace gui {
void draw(const DrawContext& pctx, const Assets& assets) override; void draw(const DrawContext& pctx, const Assets& assets) override;
void setSize(glm::vec2 size) override; void setSize(const glm::vec2& size) override;
[[nodiscard]] auto getTexture() const { [[nodiscard]] auto getTexture() const {
return texture; return texture;

View File

@ -52,7 +52,7 @@ FullCheckBox::FullCheckBox(
checkbox(std::make_shared<CheckBox>(gui, checked)), checkbox(std::make_shared<CheckBox>(gui, checked)),
label(std::make_shared<Label>(gui, text)) { label(std::make_shared<Label>(gui, text)) {
setColor(glm::vec4(0.0f)); setColor(glm::vec4(0.0f));
setOrientation(Orientation::horizontal); setOrientation(Orientation::HORIZONTAL);
add(checkbox); add(checkbox);

View File

@ -64,7 +64,7 @@ namespace gui {
checkbox->setTooltip(text); checkbox->setTooltip(text);
} }
virtual void setSize(glm::vec2 new_size) override { virtual void setSize(const glm::vec2& new_size) override {
Panel::setSize(new_size); Panel::setSize(new_size);
checkbox->setSize(glm::vec2(size.y, size.y)); checkbox->setSize(glm::vec2(size.y, size.y));
} }

View File

@ -210,11 +210,11 @@ void Container::clear() {
refresh(); refresh();
} }
void Container::listenInterval(float interval, ontimeout callback, int repeat) { void Container::listenInterval(float interval, OnTimeOut callback, int repeat) {
intervalEvents.push_back({std::move(callback), interval, 0.0f, repeat}); intervalEvents.push_back({std::move(callback), interval, 0.0f, repeat});
} }
void Container::setSize(glm::vec2 size) { void Container::setSize(const glm::vec2& size) {
if (size == getSize()) { if (size == getSize()) {
return; return;
} }

View File

@ -36,9 +36,9 @@ namespace gui {
virtual void remove(const std::string& id); virtual void remove(const std::string& id);
virtual void scrolled(int value) override; virtual void scrolled(int value) override;
virtual void setScrollable(bool flag); virtual void setScrollable(bool flag);
void listenInterval(float interval, ontimeout callback, int repeat=-1); void listenInterval(float interval, OnTimeOut callback, int repeat=-1);
virtual glm::vec2 getContentOffset() override {return glm::vec2(0.0f, scroll);}; virtual glm::vec2 getContentOffset() override {return glm::vec2(0.0f, scroll);};
virtual void setSize(glm::vec2 size) override; virtual void setSize(const glm::vec2& size) override;
virtual int getScrollStep() const; virtual int getScrollStep() const;
virtual void setScrollStep(int step); virtual void setScrollStep(int step);
virtual void refresh() override; virtual void refresh() override;

View File

@ -44,7 +44,7 @@ void InlineFrame::act(float delta) {
setDocument(assets.getShared<UiDocument>(src)); setDocument(assets.getShared<UiDocument>(src));
} }
void InlineFrame::setSize(glm::vec2 size) { void InlineFrame::setSize(const glm::vec2& size) {
Container::setSize(size); Container::setSize(size);
if (root) { if (root) {
root->setSize(size); root->setSize(size);

View File

@ -5,7 +5,7 @@
class UiDocument; class UiDocument;
namespace gui { namespace gui {
class InlineFrame : public Container { class InlineFrame final : public Container {
public: public:
explicit InlineFrame(GUI& gui); explicit InlineFrame(GUI& gui);
virtual ~InlineFrame(); virtual ~InlineFrame();
@ -14,7 +14,7 @@ namespace gui {
void setDocument(const std::shared_ptr<UiDocument>& document); void setDocument(const std::shared_ptr<UiDocument>& document);
void act(float delta) override; void act(float delta) override;
void setSize(glm::vec2 size) override; void setSize(const glm::vec2& size) override;
const std::string& getSrc() const; const std::string& getSrc() const;
private: private:

View File

@ -5,7 +5,7 @@
namespace gui { namespace gui {
class Label; class Label;
class InputBindBox : public Panel { class InputBindBox final : public Panel {
protected: protected:
Binding& binding; Binding& binding;
glm::vec4 focusedColor {0.1f, 0.15f, 0.35f, 0.75f}; glm::vec4 focusedColor {0.1f, 0.15f, 0.35f, 0.75f};
@ -15,13 +15,13 @@ namespace gui {
GUI& gui, Binding& binding, glm::vec4 padding = glm::vec4(6.0f) GUI& gui, Binding& binding, glm::vec4 padding = glm::vec4(6.0f)
); );
virtual void drawBackground( void drawBackground(
const DrawContext& pctx, const Assets& assets const DrawContext& pctx, const Assets& assets
) override; ) override;
virtual void clicked(Mousecode button) override; void clicked(Mousecode button) override;
virtual void keyPressed(Keycode key) override; void keyPressed(Keycode key) override;
virtual bool isFocuskeeper() const override { bool isFocuskeeper() const override {
return true; return true;
} }
}; };

View File

@ -528,14 +528,14 @@ void InventoryView::setSelected(int index) {
} }
} }
void InventoryView::setPos(glm::vec2 pos) { void InventoryView::setPos(const glm::vec2& pos) {
Container::setPos(pos - origin); Container::setPos(pos - origin);
} }
void InventoryView::setOrigin(glm::vec2 origin) { void InventoryView::setOrigin(const glm::vec2& origin) {
this->origin = origin; this->origin = origin;
} }
glm::vec2 InventoryView::getOrigin() const { const glm::vec2& InventoryView::getOrigin() const {
return origin; return origin;
} }

View File

@ -109,7 +109,7 @@ namespace gui {
static inline std::string EXCHANGE_SLOT_NAME = "exchange-slot"; static inline std::string EXCHANGE_SLOT_NAME = "exchange-slot";
}; };
class InventoryView : public gui::Container { class InventoryView final : public gui::Container {
const Content* content = nullptr; const Content* content = nullptr;
std::shared_ptr<Inventory> inventory; std::shared_ptr<Inventory> inventory;
@ -120,10 +120,10 @@ namespace gui {
InventoryView(GUI& gui); InventoryView(GUI& gui);
virtual ~InventoryView(); virtual ~InventoryView();
virtual void setPos(glm::vec2 pos) override; void setPos(const glm::vec2& pos) override;
void setOrigin(glm::vec2 origin); void setOrigin(const glm::vec2& origin);
glm::vec2 getOrigin() const; const glm::vec2& getOrigin() const;
void setSelected(int index); void setSelected(int index);

View File

@ -72,7 +72,7 @@ void Panel::refresh() {
float x = padding.x; float x = padding.x;
float y = padding.y; float y = padding.y;
glm::vec2 size = getSize(); glm::vec2 size = getSize();
if (orientation == Orientation::vertical) { if (orientation == Orientation::VERTICAL) {
float maxw = size.x; float maxw = size.x;
for (auto& node : nodes) { for (auto& node : nodes) {
const glm::vec4 margin = node->getMargin(); const glm::vec4 margin = node->getMargin();

View File

@ -7,7 +7,7 @@ using namespace gui;
SplitBox::SplitBox(GUI& gui, const glm::vec2& size, float splitPos, Orientation orientation) SplitBox::SplitBox(GUI& gui, const glm::vec2& size, float splitPos, Orientation orientation)
: BasePanel(gui, size, glm::vec4(), 4.0f, orientation), splitPos(splitPos) { : BasePanel(gui, size, glm::vec4(), 4.0f, orientation), splitPos(splitPos) {
setCursor( setCursor(
orientation == Orientation::vertical ? CursorShape::NS_RESIZE orientation == Orientation::VERTICAL ? CursorShape::NS_RESIZE
: CursorShape::EW_RESIZE : CursorShape::EW_RESIZE
); );
} }
@ -17,7 +17,7 @@ void SplitBox::mouseMove(int x, int y) {
auto size = getSize(); auto size = getSize();
glm::ivec2 cursor(x - pos.x, y - pos.y); glm::ivec2 cursor(x - pos.x, y - pos.y);
int axis = orientation == Orientation::vertical; int axis = orientation == Orientation::VERTICAL;
int v = cursor[axis]; int v = cursor[axis];
v = std::max(std::min(static_cast<int>(size[axis]) - 10, v), 10); v = std::max(std::min(static_cast<int>(size[axis]) - 10, v), 10);
@ -61,7 +61,7 @@ void SplitBox::refresh() {
nodeA->setPos(glm::vec2(padding)); nodeA->setPos(glm::vec2(padding));
const auto& p = padding; const auto& p = padding;
if (orientation == Orientation::vertical) { if (orientation == Orientation::VERTICAL) {
float splitPos = this->splitPos * size.y; float splitPos = this->splitPos * size.y;
nodeA->setSize({size.x-p.x-p.z, splitPos - sepRadius - p.y}); nodeA->setSize({size.x-p.x-p.z, splitPos - sepRadius - p.y});
nodeB->setSize({size.x-p.x-p.z, size.y - splitPos - sepRadius - p.w}); nodeB->setSize({size.x-p.x-p.z, size.y - splitPos - sepRadius - p.w});

View File

@ -193,7 +193,7 @@ glm::vec4 UINode::calcColor() const {
return color; return color;
} }
void UINode::setPos(glm::vec2 pos) { void UINode::setPos(const glm::vec2& pos) {
this->pos = pos; this->pos = pos;
} }
@ -205,7 +205,7 @@ glm::vec2 UINode::getSize() const {
return size; return size;
} }
void UINode::setSize(glm::vec2 size) { void UINode::setSize(const glm::vec2& size) {
this->size = glm::vec2( this->size = glm::vec2(
glm::max(minSize.x, glm::min(maxSize.x, size.x)), glm::max(minSize.x, glm::min(maxSize.x, size.x)),
glm::max(minSize.y, glm::min(maxSize.y, size.y)) glm::max(minSize.y, glm::min(maxSize.y, size.y))
@ -216,7 +216,7 @@ glm::vec2 UINode::getMinSize() const {
return minSize; return minSize;
} }
void UINode::setMinSize(glm::vec2 minSize) { void UINode::setMinSize(const glm::vec2& minSize) {
this->minSize = minSize; this->minSize = minSize;
setSize(getSize()); setSize(getSize());
} }
@ -225,7 +225,7 @@ glm::vec2 UINode::getMaxSize() const {
return maxSize; return maxSize;
} }
void UINode::setMaxSize(glm::vec2 maxSize) { void UINode::setMaxSize(const glm::vec2& maxSize) {
this->maxSize = maxSize; this->maxSize = maxSize;
setSize(getSize()); setSize(getSize());
} }

View File

@ -269,14 +269,14 @@ namespace gui {
virtual glm::vec2 getContentOffset() {return glm::vec2(0.0f);}; virtual glm::vec2 getContentOffset() {return glm::vec2(0.0f);};
/// @brief Calculate screen position of the element /// @brief Calculate screen position of the element
virtual glm::vec2 calcPos() const; virtual glm::vec2 calcPos() const;
virtual void setPos(glm::vec2 pos); virtual void setPos(const glm::vec2& pos);
virtual glm::vec2 getPos() const; virtual glm::vec2 getPos() const;
glm::vec2 getSize() const; glm::vec2 getSize() const;
virtual void setSize(glm::vec2 size); virtual void setSize(const glm::vec2& size);
glm::vec2 getMinSize() const; glm::vec2 getMinSize() const;
virtual void setMinSize(glm::vec2 size); virtual void setMinSize(const glm::vec2& size);
glm::vec2 getMaxSize() const; glm::vec2 getMaxSize() const;
virtual void setMaxSize(glm::vec2 size); virtual void setMaxSize(const glm::vec2& size);
/// @brief Called in containers when new element added /// @brief Called in containers when new element added
virtual void refresh() {}; virtual void refresh() {};
virtual void fullRefresh() { virtual void fullRefresh() {

View File

@ -3,12 +3,12 @@
#include <functional> #include <functional>
namespace gui { namespace gui {
enum class Orientation { vertical, horizontal }; enum class Orientation { VERTICAL, HORIZONTAL };
using ontimeout = std::function<void()>; using OnTimeOut = std::function<void()>;
struct IntervalEvent { struct IntervalEvent {
ontimeout callback; OnTimeOut callback;
float interval; float interval;
float timer; float timer;
// -1 - infinity, 1 - one time event // -1 - infinity, 1 - one time event

View File

@ -248,7 +248,7 @@ static void read_base_panel_impl(
if (element.has("orientation")) { if (element.has("orientation")) {
auto& oname = element.attr("orientation").getText(); auto& oname = element.attr("orientation").getText();
if (oname == "horizontal") { if (oname == "horizontal") {
panel.setOrientation(Orientation::horizontal); panel.setOrientation(Orientation::HORIZONTAL);
} }
} }
} }
@ -273,7 +273,7 @@ static void read_panel_impl(
if (element.has("orientation")) { if (element.has("orientation")) {
auto& oname = element.attr("orientation").getText(); auto& oname = element.attr("orientation").getText();
if (oname == "horizontal") { if (oname == "horizontal") {
panel.setOrientation(Orientation::horizontal); panel.setOrientation(Orientation::HORIZONTAL);
} }
} }
if (subnodes) { if (subnodes) {
@ -360,8 +360,8 @@ static std::shared_ptr<UINode> read_split_box(
float splitPos = element.attr("split-pos", "0.5").asFloat(); float splitPos = element.attr("split-pos", "0.5").asFloat();
Orientation orientation = Orientation orientation =
element.attr("orientation", "vertical").getText() == "horizontal" element.attr("orientation", "vertical").getText() == "horizontal"
? Orientation::horizontal ? Orientation::HORIZONTAL
: Orientation::vertical; : Orientation::VERTICAL;
auto splitBox = std::make_shared<SplitBox>( auto splitBox = std::make_shared<SplitBox>(
reader.getGUI(), glm::vec2(), splitPos, orientation reader.getGUI(), glm::vec2(), splitPos, orientation
); );