mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 05:51:51 +00:00
commit
b3d7180b93
14 changed files with 229 additions and 196 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
#include "Panel.hpp"
|
#include "Panel.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class CheckBox : public UINode {
|
class CheckBox final : public UINode {
|
||||||
protected:
|
protected:
|
||||||
glm::vec4 checkColor {1.0f, 1.0f, 1.0f, 0.4f};
|
glm::vec4 checkColor {1.0f, 1.0f, 1.0f, 0.4f};
|
||||||
boolsupplier supplier = nullptr;
|
boolsupplier supplier = nullptr;
|
||||||
|
|
@ -15,23 +15,22 @@ namespace gui {
|
||||||
public:
|
public:
|
||||||
explicit CheckBox(GUI& gui, bool checked = false);
|
explicit CheckBox(GUI& gui, bool checked = false);
|
||||||
|
|
||||||
virtual void draw(const DrawContext& pctx, const Assets& assets)
|
void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
override;
|
|
||||||
|
|
||||||
virtual void mouseRelease(int x, int y) override;
|
void mouseRelease(int x, int y) override;
|
||||||
|
|
||||||
virtual void setSupplier(boolsupplier supplier);
|
void setSupplier(boolsupplier supplier);
|
||||||
virtual void setConsumer(boolconsumer consumer);
|
void setConsumer(boolconsumer consumer);
|
||||||
|
|
||||||
virtual CheckBox* setChecked(bool flag);
|
CheckBox* setChecked(bool flag);
|
||||||
|
|
||||||
virtual bool isChecked() const {
|
bool isChecked() const {
|
||||||
if (supplier) return supplier();
|
if (supplier) return supplier();
|
||||||
return checked;
|
return checked;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class FullCheckBox : public Panel {
|
class FullCheckBox final : public Panel {
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<CheckBox> checkbox;
|
std::shared_ptr<CheckBox> checkbox;
|
||||||
std::shared_ptr<Label> label;
|
std::shared_ptr<Label> label;
|
||||||
|
|
@ -43,28 +42,28 @@ namespace gui {
|
||||||
bool checked = false
|
bool checked = false
|
||||||
);
|
);
|
||||||
|
|
||||||
virtual void setSupplier(boolsupplier supplier) {
|
void setSupplier(boolsupplier supplier) {
|
||||||
checkbox->setSupplier(std::move(supplier));
|
checkbox->setSupplier(std::move(supplier));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void setConsumer(boolconsumer consumer) {
|
void setConsumer(boolconsumer consumer) {
|
||||||
checkbox->setConsumer(std::move(consumer));
|
checkbox->setConsumer(std::move(consumer));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void setChecked(bool flag) {
|
void setChecked(bool flag) {
|
||||||
checkbox->setChecked(flag);
|
checkbox->setChecked(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool isChecked() const {
|
bool isChecked() const {
|
||||||
return checkbox->isChecked();
|
return checkbox->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void setTooltip(const std::wstring& text) override {
|
void setTooltip(const std::wstring& text) override {
|
||||||
Panel::setTooltip(text);
|
Panel::setTooltip(text);
|
||||||
checkbox->setTooltip(text);
|
checkbox->setTooltip(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void setSize(const glm::vec2& new_size) override {
|
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));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
#include "Container.hpp"
|
#include "Container.hpp"
|
||||||
|
|
||||||
#include "graphics/core/DrawContext.hpp"
|
|
||||||
#include "graphics/core/Batch2D.hpp"
|
|
||||||
#include "window/Window.hpp"
|
|
||||||
#include "../GUI.hpp"
|
#include "../GUI.hpp"
|
||||||
|
#include "graphics/core/Batch2D.hpp"
|
||||||
|
#include "graphics/core/DrawContext.hpp"
|
||||||
|
#include "window/Window.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
using namespace gui;
|
using namespace gui;
|
||||||
|
|
||||||
Container::Container(GUI& gui, glm::vec2 size) : UINode(gui, size) {
|
Container::Container(GUI& gui, glm::vec2 size) : UINode(gui, size) {
|
||||||
actualLength = size.y;
|
actualLengthY = size.y;
|
||||||
setColor(glm::vec4());
|
setColor(glm::vec4());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -26,15 +26,15 @@ std::shared_ptr<UINode> Container::getAt(const glm::vec2& pos) {
|
||||||
if (!isInside(pos)) {
|
if (!isInside(pos)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
int diff = (actualLength-size.y);
|
int diff = (actualLengthY - size.y);
|
||||||
if (scrollable && diff > 0 && pos.x > calcPos().x + getSize().x - scrollBarWidth) {
|
if (scrollable && diff > 0 &&
|
||||||
|
pos.x > calcPos().x + getSize().x - scrollBarWidth) {
|
||||||
return UINode::getAt(pos);
|
return UINode::getAt(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = nodes.size()-1; i >= 0; i--) {
|
for (int i = nodes.size() - 1; i >= 0; i--) {
|
||||||
auto& node = nodes[i];
|
auto& node = nodes[i];
|
||||||
if (!node->isVisible())
|
if (!node->isVisible()) continue;
|
||||||
continue;
|
|
||||||
auto hover = node->getAt(pos);
|
auto hover = node->getAt(pos);
|
||||||
if (hover != nullptr) {
|
if (hover != nullptr) {
|
||||||
return hover;
|
return hover;
|
||||||
|
|
@ -65,11 +65,12 @@ void Container::mouseMove(int x, int y) {
|
||||||
auto pos = calcPos();
|
auto pos = calcPos();
|
||||||
x -= pos.x;
|
x -= pos.x;
|
||||||
y -= pos.y;
|
y -= pos.y;
|
||||||
int diff = (actualLength-size.y);
|
int diff = (actualLengthY - size.y);
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
scroll -= (y - prevScrollY) / static_cast<float>(size.y) * actualLength;
|
scrollY -=
|
||||||
scroll = -glm::min(
|
(y - prevScrollY) / static_cast<float>(size.y) * actualLengthY;
|
||||||
glm::max(static_cast<float>(-scroll), 0.0f), actualLength - size.y
|
scrollY = -glm::min(
|
||||||
|
glm::max(static_cast<float>(-scrollY), 0.0f), actualLengthY - size.y
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
prevScrollY = y;
|
prevScrollY = y;
|
||||||
|
|
@ -101,23 +102,28 @@ void Container::act(float delta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
intervalEvents.erase(std::remove_if(
|
intervalEvents.erase(
|
||||||
intervalEvents.begin(), intervalEvents.end(),
|
std::remove_if(
|
||||||
[](const IntervalEvent& event) {
|
intervalEvents.begin(),
|
||||||
return event.repeat == 0;
|
intervalEvents.end(),
|
||||||
}
|
[](const IntervalEvent& event) { return event.repeat == 0; }
|
||||||
), intervalEvents.end());
|
),
|
||||||
|
intervalEvents.end()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Container::scrolled(int value) {
|
void Container::scrolled(int value) {
|
||||||
int diff = (actualLength-getSize().y);
|
auto size = getSize();
|
||||||
|
bool isVertical = actualLengthY > size.y;
|
||||||
|
int diff = (isVertical ? actualLengthY - size.y : actualLengthX - size.x);
|
||||||
|
int& scroll = (isVertical ? scrollY : scrollX);
|
||||||
|
|
||||||
if (scroll < 0 && diff <= 0) {
|
if (scroll < 0 && diff <= 0) {
|
||||||
scroll = 0;
|
scroll = 0;
|
||||||
}
|
}
|
||||||
if (diff > 0 && scrollable) {
|
if (diff > 0 && scrollable) {
|
||||||
scroll += value * scrollStep;
|
scroll += value * scrollStep;
|
||||||
if (scroll > 0)
|
if (scroll > 0) scroll = 0;
|
||||||
scroll = 0;
|
|
||||||
if (-scroll > diff) {
|
if (-scroll > diff) {
|
||||||
scroll = -diff;
|
scroll = -diff;
|
||||||
}
|
}
|
||||||
|
|
@ -140,21 +146,25 @@ void Container::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
if (!nodes.empty()) {
|
if (!nodes.empty()) {
|
||||||
batch->flush();
|
batch->flush();
|
||||||
DrawContext ctx = pctx.sub();
|
DrawContext ctx = pctx.sub();
|
||||||
ctx.setScissors(glm::vec4(pos.x, pos.y, glm::ceil(size.x), glm::ceil(size.y)));
|
ctx.setScissors(
|
||||||
|
glm::vec4(pos.x, pos.y, glm::ceil(size.x), glm::ceil(size.y))
|
||||||
|
);
|
||||||
for (const auto& node : nodes) {
|
for (const auto& node : nodes) {
|
||||||
if (node->isVisible())
|
if (node->isVisible()) node->draw(pctx, assets);
|
||||||
node->draw(pctx, assets);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int diff = (actualLength-size.y);
|
int diff = (actualLengthY - size.y);
|
||||||
if (scrollable && diff > 0) {
|
if (scrollable && diff > 0) {
|
||||||
int h = glm::max(size.y / actualLength * size.y, scrollBarWidth / 2.0f);
|
int h = glm::max(
|
||||||
|
size.y / actualLengthY * size.y, scrollBarWidth / 2.0f
|
||||||
|
);
|
||||||
batch->untexture();
|
batch->untexture();
|
||||||
batch->setColor(glm::vec4(1, 1, 1, 0.3f));
|
batch->setColor(glm::vec4(1, 1, 1, 0.3f));
|
||||||
batch->rect(
|
batch->rect(
|
||||||
pos.x + size.x - scrollBarWidth,
|
pos.x + size.x - scrollBarWidth,
|
||||||
pos.y - scroll / static_cast<float>(diff) * (size.y - h),
|
pos.y - scrollY / static_cast<float>(diff) * (size.y - h),
|
||||||
scrollBarWidth, h
|
scrollBarWidth,
|
||||||
|
h
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
batch->flush();
|
batch->flush();
|
||||||
|
|
@ -163,8 +173,7 @@ void Container::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
|
|
||||||
void Container::drawBackground(const DrawContext& pctx, const Assets&) {
|
void Container::drawBackground(const DrawContext& pctx, const Assets&) {
|
||||||
glm::vec4 color = calcColor();
|
glm::vec4 color = calcColor();
|
||||||
if (color.a <= 0.001f)
|
if (color.a <= 0.001f) return;
|
||||||
return;
|
|
||||||
glm::vec2 pos = calcPos();
|
glm::vec2 pos = calcPos();
|
||||||
|
|
||||||
auto batch = pctx.getBatch2D();
|
auto batch = pctx.getBatch2D();
|
||||||
|
|
@ -194,11 +203,16 @@ void Container::add(const std::shared_ptr<UINode>& node, glm::vec2 pos) {
|
||||||
|
|
||||||
void Container::remove(UINode* selected) {
|
void Container::remove(UINode* selected) {
|
||||||
selected->setParent(nullptr);
|
selected->setParent(nullptr);
|
||||||
nodes.erase(std::remove_if(nodes.begin(), nodes.end(),
|
nodes.erase(
|
||||||
[selected](const std::shared_ptr<UINode>& node) {
|
std::remove_if(
|
||||||
return node.get() == selected;
|
nodes.begin(),
|
||||||
}
|
nodes.end(),
|
||||||
), nodes.end());
|
[selected](const std::shared_ptr<UINode>& node) {
|
||||||
|
return node.get() == selected;
|
||||||
|
}
|
||||||
|
),
|
||||||
|
nodes.end()
|
||||||
|
);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -242,13 +256,17 @@ void Container::setScrollStep(int step) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Container::refresh() {
|
void Container::refresh() {
|
||||||
std::stable_sort(nodes.begin(), nodes.end(), [](const auto& a, const auto& b) {
|
std::stable_sort(
|
||||||
return a->getZIndex() < b->getZIndex();
|
nodes.begin(),
|
||||||
});
|
nodes.end(),
|
||||||
|
[](const auto& a, const auto& b) {
|
||||||
|
return a->getZIndex() < b->getZIndex();
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Container::setScroll(int scroll) {
|
void Container::setScroll(int scroll) {
|
||||||
this->scroll = scroll;
|
this->scrollY = scroll;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::shared_ptr<UINode>>& Container::getNodes() const {
|
const std::vector<std::shared_ptr<UINode>>& Container::getNodes() const {
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,12 @@ namespace gui {
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::shared_ptr<UINode>> nodes;
|
std::vector<std::shared_ptr<UINode>> nodes;
|
||||||
std::vector<IntervalEvent> intervalEvents;
|
std::vector<IntervalEvent> intervalEvents;
|
||||||
int scroll = 0;
|
int scrollY = 0;
|
||||||
|
int scrollX = 0;
|
||||||
int scrollStep = 40;
|
int scrollStep = 40;
|
||||||
int scrollBarWidth = 10;
|
int scrollBarWidth = 10;
|
||||||
int actualLength = 0;
|
int actualLengthY = 0;
|
||||||
|
int actualLengthX = 0;
|
||||||
bool scrollable = true;
|
bool scrollable = true;
|
||||||
|
|
||||||
bool isScrolling() const {
|
bool isScrolling() const {
|
||||||
|
|
@ -40,7 +42,7 @@ namespace gui {
|
||||||
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() const override {
|
virtual glm::vec2 getContentOffset() const override {
|
||||||
return glm::vec2(0.0f, scroll);
|
return glm::vec2(scrollX, scrollY);
|
||||||
};
|
};
|
||||||
virtual void setSize(const glm::vec2& size) override;
|
virtual void setSize(const glm::vec2& size) override;
|
||||||
virtual int getScrollStep() const;
|
virtual int getScrollStep() const;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace gui {
|
||||||
class Frame final : public Container {
|
class Frame final : public Container {
|
||||||
public:
|
public:
|
||||||
Frame(GUI& gui, std::string id, std::string outputTexture);
|
Frame(GUI& gui, std::string id, std::string outputTexture);
|
||||||
virtual ~Frame();
|
~Frame();
|
||||||
|
|
||||||
void draw(const DrawContext& pctx, const Assets& assets) override;
|
void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ namespace gui {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SlotView : public gui::UINode {
|
class SlotView final : public gui::UINode {
|
||||||
struct {
|
struct {
|
||||||
ItemStack stack {};
|
ItemStack stack {};
|
||||||
std::wstring countStr;
|
std::wstring countStr;
|
||||||
|
|
@ -89,14 +89,14 @@ namespace gui {
|
||||||
public:
|
public:
|
||||||
SlotView(GUI& gui, SlotLayout layout);
|
SlotView(GUI& gui, SlotLayout layout);
|
||||||
|
|
||||||
virtual void draw(const DrawContext& pctx, const Assets& assets) override;
|
void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
|
|
||||||
void setHighlighted(bool flag);
|
void setHighlighted(bool flag);
|
||||||
bool isHighlighted() const;
|
bool isHighlighted() const;
|
||||||
|
|
||||||
virtual void clicked(Mousecode) override;
|
void clicked(Mousecode) override;
|
||||||
virtual void onFocus() override;
|
void onFocus() override;
|
||||||
virtual const std::wstring& getTooltip() const override;
|
const std::wstring& getTooltip() const override;
|
||||||
|
|
||||||
void bind(
|
void bind(
|
||||||
int64_t inventoryid,
|
int64_t inventoryid,
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace gui {
|
||||||
uint getLineByTextIndex(size_t index) const;
|
uint getLineByTextIndex(size_t index) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Label : public UINode {
|
class Label final : public UINode {
|
||||||
LabelCache cache;
|
LabelCache cache;
|
||||||
|
|
||||||
glm::vec2 calcSize();
|
glm::vec2 calcSize();
|
||||||
|
|
@ -69,64 +69,64 @@ namespace gui {
|
||||||
Label(GUI& gui, const std::string& text, std::string fontName="normal");
|
Label(GUI& gui, const std::string& text, std::string fontName="normal");
|
||||||
Label(GUI& gui, const std::wstring& text, std::string fontName="normal");
|
Label(GUI& gui, const std::wstring& text, std::string fontName="normal");
|
||||||
|
|
||||||
virtual ~Label();
|
~Label();
|
||||||
|
|
||||||
virtual void setText(std::wstring text);
|
void setText(std::wstring text);
|
||||||
const std::wstring& getText() const;
|
const std::wstring& getText() const;
|
||||||
|
|
||||||
virtual void setFontName(std::string name);
|
void setFontName(std::string name);
|
||||||
virtual const std::string& getFontName() const;
|
const std::string& getFontName() const;
|
||||||
|
|
||||||
/// @brief Set text vertical alignment (default value: center)
|
/// @brief Set text vertical alignment (default value: center)
|
||||||
/// @param align Align::top / Align::center / Align::bottom
|
/// @param align Align::top / Align::center / Align::bottom
|
||||||
virtual void setVerticalAlign(Align align);
|
void setVerticalAlign(Align align);
|
||||||
virtual Align getVerticalAlign() const;
|
Align getVerticalAlign() const;
|
||||||
|
|
||||||
/// @brief Get line height multiplier used for multiline labels
|
/// @brief Get line height multiplier used for multiline labels
|
||||||
/// (default value: 1.5)
|
/// (default value: 1.5)
|
||||||
virtual float getLineInterval() const;
|
float getLineInterval() const;
|
||||||
|
|
||||||
/// @brief Set line height multiplier used for multiline labels
|
/// @brief Set line height multiplier used for multiline labels
|
||||||
virtual void setLineInterval(float interval);
|
void setLineInterval(float interval);
|
||||||
|
|
||||||
/// @brief Get Y position of the text relative to label position
|
/// @brief Get Y position of the text relative to label position
|
||||||
/// @return Y offset
|
/// @return Y offset
|
||||||
virtual int getTextYOffset() const;
|
int getTextYOffset() const;
|
||||||
|
|
||||||
/// @brief Get Y position of the line relative to label position
|
/// @brief Get Y position of the line relative to label position
|
||||||
/// @param line target line index
|
/// @param line target line index
|
||||||
/// @return Y offset
|
/// @return Y offset
|
||||||
virtual int getLineYOffset(uint line) const;
|
int getLineYOffset(uint line) const;
|
||||||
|
|
||||||
/// @brief Get position of line start in the text
|
/// @brief Get position of line start in the text
|
||||||
/// @param line target line index
|
/// @param line target line index
|
||||||
/// @return position in the text [0..length]
|
/// @return position in the text [0..length]
|
||||||
virtual size_t getTextLineOffset(size_t line) const;
|
size_t getTextLineOffset(size_t line) const;
|
||||||
|
|
||||||
/// @brief Get line index by its Y offset relative to label position
|
/// @brief Get line index by its Y offset relative to label position
|
||||||
/// @param offset target Y offset
|
/// @param offset target Y offset
|
||||||
/// @return line index [0..+]
|
/// @return line index [0..+]
|
||||||
virtual uint getLineByYOffset(int offset) const;
|
uint getLineByYOffset(int offset) const;
|
||||||
virtual uint getLineByTextIndex(size_t index) const;
|
uint getLineByTextIndex(size_t index) const;
|
||||||
virtual uint getLinesNumber() const;
|
uint getLinesNumber() const;
|
||||||
virtual bool isFakeLine(size_t line) const;
|
bool isFakeLine(size_t line) const;
|
||||||
|
|
||||||
virtual void draw(const DrawContext& pctx, const Assets& assets) override;
|
void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
|
|
||||||
virtual void textSupplier(wstringsupplier supplier);
|
void textSupplier(wstringsupplier supplier);
|
||||||
|
|
||||||
virtual void setAutoResize(bool flag);
|
void setAutoResize(bool flag);
|
||||||
virtual bool isAutoResize() const;
|
bool isAutoResize() const;
|
||||||
|
|
||||||
virtual void setMultiline(bool multiline);
|
void setMultiline(bool multiline);
|
||||||
virtual bool isMultiline() const;
|
bool isMultiline() const;
|
||||||
|
|
||||||
virtual void setTextWrapping(bool flag);
|
void setTextWrapping(bool flag);
|
||||||
virtual bool isTextWrapping() const;
|
bool isTextWrapping() const;
|
||||||
|
|
||||||
virtual void setMarkup(std::string_view lang);
|
void setMarkup(std::string_view lang);
|
||||||
virtual const std::string& getMarkup() const;
|
const std::string& getMarkup() const;
|
||||||
|
|
||||||
virtual void setStyles(std::unique_ptr<FontStylesScheme> styles);
|
void setStyles(std::unique_ptr<FontStylesScheme> styles);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace gui {
|
||||||
|
|
||||||
using PageLoaderFunc = std::function<std::shared_ptr<UINode>(const std::string&)>;
|
using PageLoaderFunc = std::function<std::shared_ptr<UINode>(const std::string&)>;
|
||||||
|
|
||||||
class Menu : public Container {
|
class Menu final : public Container {
|
||||||
protected:
|
protected:
|
||||||
std::unordered_map<std::string, Page> pages;
|
std::unordered_map<std::string, Page> pages;
|
||||||
std::stack<Page> pageStack;
|
std::stack<Page> pageStack;
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Container.hpp"
|
||||||
|
#include "window/Camera.hpp"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Container.hpp"
|
|
||||||
#include "window/Camera.hpp"
|
|
||||||
|
|
||||||
class Batch3D;
|
class Batch3D;
|
||||||
class Framebuffer;
|
class Framebuffer;
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class ModelViewer : public Container {
|
class ModelViewer final : public Container {
|
||||||
private:
|
private:
|
||||||
std::string modelName;
|
std::string modelName;
|
||||||
Camera camera;
|
Camera camera;
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,14 @@ glm::vec2 Panel::getContentSize() const {
|
||||||
void Panel::cropToContent() {
|
void Panel::cropToContent() {
|
||||||
if (maxLength > 0.0f) {
|
if (maxLength > 0.0f) {
|
||||||
setSize(glm::vec2(
|
setSize(glm::vec2(
|
||||||
getSize().x, glm::max(minLength, glm::min(maxLength, actualLength))
|
glm::max(minLength, glm::min(maxLength, actualLengthX)),
|
||||||
|
glm::max(minLength, glm::min(maxLength, actualLengthY))
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
setSize(glm::vec2(getSize().x, glm::max(minLength, actualLength)));
|
setSize(glm::vec2(
|
||||||
|
glm::max(minLength, actualLengthX),
|
||||||
|
glm::max(minLength, actualLengthY)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,21 +97,30 @@ void Panel::refresh() {
|
||||||
y += nodeSize.y + margin.w + interval;
|
y += nodeSize.y + margin.w + interval;
|
||||||
maxw = fmax(maxw, ex + nodeSize.x + margin.z + padding.z);
|
maxw = fmax(maxw, ex + nodeSize.x + margin.z + padding.z);
|
||||||
}
|
}
|
||||||
actualLength = y + padding.w;
|
actualLengthX = size.x;
|
||||||
|
actualLengthY = y + padding.w;
|
||||||
} else {
|
} else {
|
||||||
float maxh = size.y;
|
float maxh = size.y;
|
||||||
for (auto& node : nodes) {
|
for (auto& node : nodes) {
|
||||||
glm::vec2 nodesize = node->getSize();
|
|
||||||
const glm::vec4 margin = node->getMargin();
|
const glm::vec4 margin = node->getMargin();
|
||||||
x += margin.x;
|
x += margin.x;
|
||||||
node->setPos(glm::vec2(x, y + margin.y));
|
|
||||||
x += nodesize.x + margin.z + interval;
|
|
||||||
|
|
||||||
node->refresh();
|
float ey = y + margin.y;
|
||||||
maxh = fmax(
|
node->setPos(glm::vec2(x, ey));
|
||||||
maxh, y + margin.y + node->getSize().y + margin.w + padding.w
|
|
||||||
|
int height = glm::floor(
|
||||||
|
size.y - padding.y - padding.w - margin.y - margin.w
|
||||||
);
|
);
|
||||||
|
if (node->isResizing()) {
|
||||||
|
node->setMaxSize({node->getMaxSize().x, height});
|
||||||
|
node->setSize(glm::vec2(node->getSize().x, height));
|
||||||
|
}
|
||||||
|
node->refresh();
|
||||||
|
glm::vec2 nodesize = node->getSize();
|
||||||
|
x += nodesize.x + margin.z + interval;
|
||||||
|
maxh = fmax(maxh, ey + nodesize.y + margin.w + padding.w);
|
||||||
}
|
}
|
||||||
actualLength = size.y;
|
actualLengthY = size.y;
|
||||||
|
actualLengthX = x + padding.z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class Assets;
|
||||||
class DrawContext;
|
class DrawContext;
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class Plotter : public UINode {
|
class Plotter final : public UINode {
|
||||||
std::unique_ptr<int[]> points;
|
std::unique_ptr<int[]> points;
|
||||||
float multiplier;
|
float multiplier;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
|
||||||
|
|
@ -452,7 +452,7 @@ void TextBox::refreshLabel() {
|
||||||
uint height = label->getLinesNumber() * rawTextCache.metrics.lineHeight *
|
uint height = label->getLinesNumber() * rawTextCache.metrics.lineHeight *
|
||||||
label->getLineInterval();
|
label->getLineInterval();
|
||||||
label->setSize(glm::vec2(label->getSize().x, height));
|
label->setSize(glm::vec2(label->getSize().x, height));
|
||||||
actualLength = height;
|
actualLengthY = height;
|
||||||
} else {
|
} else {
|
||||||
setScrollable(false);
|
setScrollable(false);
|
||||||
}
|
}
|
||||||
|
|
@ -1133,10 +1133,10 @@ void TextBox::setOnControlCombination(key_handler handler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::setFocusedColor(glm::vec4 color) {
|
void TextBox::setFocusedColor(glm::vec4 color) {
|
||||||
this->focusedColor = color;
|
this->focusedColor = std::move(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec4 TextBox::getFocusedColor() const {
|
const glm::vec4& TextBox::getFocusedColor() const {
|
||||||
return focusedColor;
|
return focusedColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1144,7 +1144,7 @@ void TextBox::setTextColor(glm::vec4 color) {
|
||||||
this->textColor = color;
|
this->textColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec4 TextBox::getTextColor() const {
|
const glm::vec4& TextBox::getTextColor() const {
|
||||||
return textColor;
|
return textColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1248,7 +1248,7 @@ void TextBox::setPadding(glm::vec4 padding) {
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec4 TextBox::getPadding() const {
|
const glm::vec4& TextBox::getPadding() const {
|
||||||
return padding;
|
return padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ class ActionsHistory;
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class TextBoxHistorian;
|
class TextBoxHistorian;
|
||||||
class TextBox : public Container {
|
class TextBox final : public Container {
|
||||||
const Input& inputEvents;
|
const Input& inputEvents;
|
||||||
LabelCache rawTextCache;
|
LabelCache rawTextCache;
|
||||||
std::shared_ptr<ActionsHistory> history;
|
std::shared_ptr<ActionsHistory> history;
|
||||||
|
|
@ -100,124 +100,124 @@ namespace gui {
|
||||||
glm::vec4 padding=glm::vec4(4.0f)
|
glm::vec4 padding=glm::vec4(4.0f)
|
||||||
);
|
);
|
||||||
|
|
||||||
virtual ~TextBox();
|
~TextBox();
|
||||||
|
|
||||||
void paste(const std::wstring& text, bool history=true);
|
void paste(const std::wstring& text, bool history=true);
|
||||||
void erase(size_t start, size_t length);
|
void erase(size_t start, size_t length);
|
||||||
void resetSelection();
|
void resetSelection();
|
||||||
|
|
||||||
virtual void setTextSupplier(wstringsupplier supplier);
|
void setTextSupplier(wstringsupplier supplier);
|
||||||
|
|
||||||
/// @brief Consumer called on stop editing text (textbox defocus)
|
/// @brief Consumer called on stop editing text (textbox defocus)
|
||||||
/// @param consumer std::wstring consumer function
|
/// @param consumer std::wstring consumer function
|
||||||
virtual void setTextConsumer(wstringconsumer consumer);
|
void setTextConsumer(wstringconsumer consumer);
|
||||||
|
|
||||||
/// @brief Sub-consumer called while editing text
|
/// @brief Sub-consumer called while editing text
|
||||||
/// @param consumer std::wstring consumer function
|
/// @param consumer std::wstring consumer function
|
||||||
virtual void setTextSubConsumer(wstringconsumer consumer);
|
void setTextSubConsumer(wstringconsumer consumer);
|
||||||
|
|
||||||
/// @brief Text validator called while text editing and returns true if
|
/// @brief Text validator called while text editing and returns true if
|
||||||
/// text is valid
|
/// text is valid
|
||||||
/// @param validator std::wstring consumer returning boolean
|
/// @param validator std::wstring consumer returning boolean
|
||||||
virtual void setTextValidator(wstringchecker validator);
|
void setTextValidator(wstringchecker validator);
|
||||||
|
|
||||||
virtual void setOnControlCombination(key_handler handler);
|
void setOnControlCombination(key_handler handler);
|
||||||
|
|
||||||
virtual void setFocusedColor(glm::vec4 color);
|
void setFocusedColor(glm::vec4 color);
|
||||||
virtual glm::vec4 getFocusedColor() const;
|
const glm::vec4& getFocusedColor() const;
|
||||||
|
|
||||||
virtual void setTextColor(glm::vec4 color);
|
void setTextColor(glm::vec4 color);
|
||||||
virtual glm::vec4 getTextColor() const;
|
const glm::vec4& getTextColor() const;
|
||||||
|
|
||||||
/// @brief Set color of textbox marked by validator as invalid
|
/// @brief Set color of textbox marked by validator as invalid
|
||||||
virtual void setErrorColor(glm::vec4 color);
|
void setErrorColor(glm::vec4 color);
|
||||||
|
|
||||||
/// @brief Get color of textbox marked by validator as invalid
|
/// @brief Get color of textbox marked by validator as invalid
|
||||||
virtual glm::vec4 getErrorColor() const;
|
glm::vec4 getErrorColor() const;
|
||||||
|
|
||||||
/// @brief Get TextBox content text or placeholder if empty
|
/// @brief Get TextBox content text or placeholder if empty
|
||||||
virtual const std::wstring& getText() const;
|
const std::wstring& getText() const;
|
||||||
|
|
||||||
/// @brief Set TextBox content text
|
/// @brief Set TextBox content text
|
||||||
virtual void setText(const std::wstring &value);
|
void setText(const std::wstring &value);
|
||||||
|
|
||||||
/// @brief Get text placeholder
|
/// @brief Get text placeholder
|
||||||
virtual const std::wstring& getPlaceholder() const;
|
const std::wstring& getPlaceholder() const;
|
||||||
|
|
||||||
/// @brief Set text placeholder
|
/// @brief Set text placeholder
|
||||||
/// @param text will be used instead of empty
|
/// @param text will be used instead of empty
|
||||||
virtual void setPlaceholder(const std::wstring& text);
|
void setPlaceholder(const std::wstring& text);
|
||||||
|
|
||||||
/// @brief Get textbox hint
|
/// @brief Get textbox hint
|
||||||
virtual const std::wstring& getHint() const;
|
const std::wstring& getHint() const;
|
||||||
|
|
||||||
/// @brief Set textbox hint
|
/// @brief Set textbox hint
|
||||||
/// @param text will be shown instead of empty
|
/// @param text will be shown instead of empty
|
||||||
virtual void setHint(const std::wstring& text);
|
void setHint(const std::wstring& text);
|
||||||
|
|
||||||
/// @brief Get selected text
|
/// @brief Get selected text
|
||||||
virtual std::wstring getSelection() const;
|
std::wstring getSelection() const;
|
||||||
|
|
||||||
/// @brief Get current caret position in text
|
/// @brief Get current caret position in text
|
||||||
/// @return integer in range [0, text.length()]
|
/// @return integer in range [0, text.length()]
|
||||||
virtual size_t getCaret() const;
|
size_t getCaret() const;
|
||||||
|
|
||||||
/// @brief Set caret position in the text
|
/// @brief Set caret position in the text
|
||||||
/// @param position integer in range [0, text.length()]
|
/// @param position integer in range [0, text.length()]
|
||||||
virtual void setCaret(size_t position);
|
void setCaret(size_t position);
|
||||||
|
|
||||||
/// @brief Set caret position in the text
|
/// @brief Set caret position in the text
|
||||||
/// @param position integer in range [-text.length(), text.length()]
|
/// @param position integer in range [-text.length(), text.length()]
|
||||||
virtual void setCaret(ptrdiff_t position);
|
void setCaret(ptrdiff_t position);
|
||||||
|
|
||||||
/// @brief Select part of the text
|
/// @brief Select part of the text
|
||||||
/// @param start index of the first selected character
|
/// @param start index of the first selected character
|
||||||
/// @param end index of the last selected character + 1
|
/// @param end index of the last selected character + 1
|
||||||
virtual void select(int start, int end);
|
void select(int start, int end);
|
||||||
|
|
||||||
/// @brief Get number of line at specific position in text
|
/// @brief Get number of line at specific position in text
|
||||||
/// @param position target position
|
/// @param position target position
|
||||||
/// @return line number
|
/// @return line number
|
||||||
virtual uint getLineAt(size_t position) const;
|
uint getLineAt(size_t position) const;
|
||||||
|
|
||||||
/// @brief Get specific line text position
|
/// @brief Get specific line text position
|
||||||
/// @param line target line
|
/// @param line target line
|
||||||
/// @return line position in text
|
/// @return line position in text
|
||||||
virtual size_t getLinePos(uint line) const;
|
size_t getLinePos(uint line) const;
|
||||||
|
|
||||||
int calcIndexAt(int x, int y) const;
|
int calcIndexAt(int x, int y) const;
|
||||||
int getLineYOffset(int line) const;
|
int getLineYOffset(int line) const;
|
||||||
|
|
||||||
/// @brief Check text with validator set with setTextValidator
|
/// @brief Check text with validator set with setTextValidator
|
||||||
/// @return true if text is valid
|
/// @return true if text is valid
|
||||||
virtual bool validate();
|
bool validate();
|
||||||
|
|
||||||
virtual void setValid(bool valid);
|
void setValid(bool valid);
|
||||||
virtual bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
/// @brief Enable/disable multiline mode
|
/// @brief Enable/disable multiline mode
|
||||||
virtual void setMultiline(bool multiline);
|
void setMultiline(bool multiline);
|
||||||
|
|
||||||
/// @brief Check if multiline mode is enabled
|
/// @brief Check if multiline mode is enabled
|
||||||
virtual bool isMultiline() const;
|
bool isMultiline() const;
|
||||||
|
|
||||||
/// @brief Enable/disable text wrapping
|
/// @brief Enable/disable text wrapping
|
||||||
virtual void setTextWrapping(bool flag);
|
void setTextWrapping(bool flag);
|
||||||
|
|
||||||
/// @brief Check if text wrapping is enabled
|
/// @brief Check if text wrapping is enabled
|
||||||
virtual bool isTextWrapping() const;
|
bool isTextWrapping() const;
|
||||||
|
|
||||||
/// @brief Enable/disable text editing feature
|
/// @brief Enable/disable text editing feature
|
||||||
virtual void setEditable(bool editable);
|
void setEditable(bool editable);
|
||||||
|
|
||||||
/// @brief Check if text editing feature is enabled
|
/// @brief Check if text editing feature is enabled
|
||||||
virtual bool isEditable() const;
|
bool isEditable() const;
|
||||||
|
|
||||||
virtual bool isEdited() const;
|
bool isEdited() const;
|
||||||
virtual void setUnedited();
|
void setUnedited();
|
||||||
|
|
||||||
virtual void setPadding(glm::vec4 padding);
|
void setPadding(glm::vec4 padding);
|
||||||
glm::vec4 getPadding() const;
|
const glm::vec4& getPadding() const;
|
||||||
|
|
||||||
size_t getSelectionStart() const;
|
size_t getSelectionStart() const;
|
||||||
size_t getSelectionEnd() const;
|
size_t getSelectionEnd() const;
|
||||||
|
|
@ -226,34 +226,34 @@ namespace gui {
|
||||||
bool isKeepLineSelection() const;
|
bool isKeepLineSelection() const;
|
||||||
|
|
||||||
/// @brief Set runnable called on textbox focus
|
/// @brief Set runnable called on textbox focus
|
||||||
virtual void setOnEditStart(runnable oneditstart);
|
void setOnEditStart(runnable oneditstart);
|
||||||
|
|
||||||
virtual void setAutoResize(bool flag);
|
void setAutoResize(bool flag);
|
||||||
virtual bool isAutoResize() const;
|
bool isAutoResize() const;
|
||||||
|
|
||||||
virtual void setShowLineNumbers(bool flag);
|
void setShowLineNumbers(bool flag);
|
||||||
virtual bool isShowLineNumbers() const;
|
bool isShowLineNumbers() const;
|
||||||
|
|
||||||
virtual void reposition() override;
|
void reposition() override;
|
||||||
virtual void onFocus() override;
|
void onFocus() override;
|
||||||
virtual void refresh() override;
|
void refresh() override;
|
||||||
virtual void doubleClick(int x, int y) override;
|
void doubleClick(int x, int y) override;
|
||||||
virtual void click(int, int) override;
|
void click(int, int) override;
|
||||||
virtual void mouseMove(int x, int y) override;
|
void mouseMove(int x, int y) override;
|
||||||
virtual bool isFocuskeeper() const override {return true;}
|
bool isFocuskeeper() const override {return true;}
|
||||||
virtual void draw(const DrawContext& pctx, const Assets& assets) override;
|
void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
virtual void drawBackground(const DrawContext& pctx, const Assets& assets) override;
|
void drawBackground(const DrawContext& pctx, const Assets& assets) override;
|
||||||
virtual void typed(unsigned int codepoint) override;
|
void typed(unsigned int codepoint) override;
|
||||||
virtual void keyPressed(Keycode key) override;
|
void keyPressed(Keycode key) override;
|
||||||
virtual std::shared_ptr<UINode> getAt(const glm::vec2& pos) override;
|
std::shared_ptr<UINode> getAt(const glm::vec2& pos) override;
|
||||||
virtual void setOnUpPressed(const runnable &callback);
|
void setOnUpPressed(const runnable& callback);
|
||||||
virtual void setOnDownPressed(const runnable &callback);
|
void setOnDownPressed(const runnable& callback);
|
||||||
|
|
||||||
virtual void setSyntax(std::string_view lang);
|
void setSyntax(std::string_view lang);
|
||||||
virtual const std::string& getSyntax() const;
|
const std::string& getSyntax() const;
|
||||||
|
|
||||||
virtual void setMarkup(std::string_view lang);
|
void setMarkup(std::string_view lang);
|
||||||
virtual const std::string& getMarkup() const;
|
const std::string& getMarkup() const;
|
||||||
|
|
||||||
std::shared_ptr<Label> getLabel() const;
|
std::shared_ptr<Label> getLabel() const;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ int TrackBar::getTrackWidth() const {
|
||||||
return trackWidth;
|
return trackWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec4 TrackBar::getTrackColor() const {
|
const glm::vec4& TrackBar::getTrackColor() const {
|
||||||
return trackColor;
|
return trackColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#include "UINode.hpp"
|
#include "UINode.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class TrackBar : public UINode {
|
class TrackBar final : public UINode {
|
||||||
protected:
|
protected:
|
||||||
glm::vec4 trackColor {1.0f, 1.0f, 1.0f, 0.4f};
|
glm::vec4 trackColor {1.0f, 1.0f, 1.0f, 0.4f};
|
||||||
doublesupplier supplier = nullptr;
|
doublesupplier supplier = nullptr;
|
||||||
|
|
@ -24,29 +24,29 @@ namespace gui {
|
||||||
double step = 1.0,
|
double step = 1.0,
|
||||||
int trackWidth = 12
|
int trackWidth = 12
|
||||||
);
|
);
|
||||||
virtual void draw(const DrawContext& pctx, const Assets& assets) override;
|
void draw(const DrawContext& pctx, const Assets& assets) override;
|
||||||
|
|
||||||
virtual void setSupplier(doublesupplier);
|
void setSupplier(doublesupplier);
|
||||||
virtual void setConsumer(doubleconsumer);
|
void setConsumer(doubleconsumer);
|
||||||
virtual void setSubConsumer(doubleconsumer);
|
void setSubConsumer(doubleconsumer);
|
||||||
|
|
||||||
virtual void mouseMove(int x, int y) override;
|
void mouseMove(int x, int y) override;
|
||||||
virtual void mouseRelease(int x, int y) override;
|
void mouseRelease(int x, int y) override;
|
||||||
|
|
||||||
virtual double getValue() const;
|
double getValue() const;
|
||||||
virtual double getMin() const;
|
double getMin() const;
|
||||||
virtual double getMax() const;
|
double getMax() const;
|
||||||
virtual double getStep() const;
|
double getStep() const;
|
||||||
virtual int getTrackWidth() const;
|
int getTrackWidth() const;
|
||||||
virtual glm::vec4 getTrackColor() const;
|
const glm::vec4& getTrackColor() const;
|
||||||
virtual bool isChangeOnRelease() const;
|
bool isChangeOnRelease() const;
|
||||||
|
|
||||||
virtual void setValue(double);
|
void setValue(double);
|
||||||
virtual void setMin(double);
|
void setMin(double);
|
||||||
virtual void setMax(double);
|
void setMax(double);
|
||||||
virtual void setStep(double);
|
void setStep(double);
|
||||||
virtual void setTrackWidth(int);
|
void setTrackWidth(int);
|
||||||
virtual void setTrackColor(glm::vec4);
|
void setTrackColor(glm::vec4);
|
||||||
virtual void setChangeOnRelease(bool);
|
void setChangeOnRelease(bool);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue