locale independent util::parse_double

This commit is contained in:
MihailRis
2024-02-02 20:02:30 +03:00
parent 84e8fd1af6
commit bc72742ee3
20 changed files with 140 additions and 48 deletions
-3
View File
@@ -44,9 +44,6 @@ class Camera;
*/
namespace gui {
typedef std::function<void()> runnable;
typedef std::function<void(const std::string&)> stringconsumer;
class UINode;
class Container;
class PagesControl;
+9
View File
@@ -115,6 +115,15 @@ void UINode::setSize(vec2 size) {
void UINode::setColor(vec4 color) {
this->color = color;
this->hoverColor = color;
}
void UINode::setHoverColor(glm::vec4 newColor) {
this->hoverColor = newColor;
}
glm::vec4 UINode::getHoverColor() const {
return hoverColor;
}
vec4 UINode::getColor() const {
+21
View File
@@ -24,6 +24,7 @@ namespace gui {
glm::vec2 coord;
glm::vec2 size;
glm::vec4 color {1.0f};
glm::vec4 hoverColor {1.0f};
glm::vec4 margin {1.0f};
bool visible = true;
bool hover = false;
@@ -50,9 +51,16 @@ namespace gui {
virtual void setParent(UINode* node);
UINode* getParent() const;
/* Set element color (doesn't affect inner elements).
Also replaces hover color to avoid adding extra properties. */
virtual void setColor(glm::vec4 newColor);
/* Get element color */
glm::vec4 getColor() const;
virtual void setHoverColor(glm::vec4 newColor);
glm::vec4 getHoverColor() const;
virtual void setMargin(glm::vec4 margin);
glm::vec4 getMargin() const;
@@ -66,18 +74,31 @@ namespace gui {
bool isPressed() const;
void defocus();
bool isFocused() const;
/* Check if elements catches all user input when focused */
virtual bool isFocuskeeper() const {return false;}
virtual void typed(unsigned int codepoint) {};
virtual void keyPressed(int key) {};
/* Check if screen position is inside of the element
@param pos screen position */
virtual bool isInside(glm::vec2 pos);
/* Get element under the cursor.
@param pos cursor screen position
@param self shared pointer to element
@return self, sub-element or nullptr if element is not interractive */
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self);
/* Check if element is opaque for cursor */
virtual bool isInteractive() const;
/* Make the element opaque (true) or transparent (false) for cursor */
virtual void setInteractive(bool flag);
/* Get inner content offset. Used for scroll */
virtual glm::vec2 contentOffset() {return glm::vec2(0.0f);};
/* Calculate screen position of the element */
virtual glm::vec2 calcCoord() const;
virtual void setCoord(glm::vec2 coord);
virtual glm::vec2 getSize() const;
+1 -1
View File
@@ -255,7 +255,7 @@ bool TextBox::isValid() const {
return valid;
}
void TextBox::setOnEditStart(gui::runnable oneditstart) {
void TextBox::setOnEditStart(runnable oneditstart) {
onEditStart = oneditstart;
}
+5 -1
View File
@@ -6,10 +6,12 @@
#include <vector>
#include <functional>
#include <glm/glm.hpp>
#include "GUI.h"
#include "UINode.h"
#include "panels.h"
#include "../../window/input.h"
#include "../../delegates.h"
class Batch2D;
class Assets;
@@ -60,7 +62,9 @@ namespace gui {
std::vector<onaction> actions;
std::shared_ptr<Label> label = nullptr;
public:
Button(std::shared_ptr<UINode> content, glm::vec4 padding=glm::vec4(2.0f));
Button(std::shared_ptr<UINode> content,
glm::vec4 padding=glm::vec4(2.0f));
Button(std::wstring text,
glm::vec4 padding,
onaction action);
+3 -2
View File
@@ -5,6 +5,7 @@
#include <glm/glm.hpp>
#include "../locale/langs.h"
#include "../../delegates.h"
using namespace gui;
using glm::vec2;
@@ -29,7 +30,7 @@ std::shared_ptr<Button> guiutil::gotoButton(
});
}
void guiutil::alert(GUI* gui, const std::wstring& text, gui::runnable on_hidden) {
void guiutil::alert(GUI* gui, const std::wstring& text, runnable on_hidden) {
auto menu = gui->getMenu();
Panel* panel = new Panel(vec2(500, 200), vec4(8.0f), 8.0f);
panel->setColor(vec4(0.0f, 0.0f, 0.0f, 0.5f));
@@ -69,7 +70,7 @@ void guiutil::alert(GUI* gui, const std::wstring& text, gui::runnable on_hidden)
void guiutil::confirm(
GUI* gui,
const std::wstring& text,
gui::runnable on_confirm,
runnable on_confirm,
std::wstring yestext,
std::wstring notext) {
if (yestext.empty()) yestext = langs::get(L"Yes");
+3 -2
View File
@@ -4,6 +4,7 @@
#include <memory>
#include <string>
#include "GUI.h"
#include "../../delegates.h"
namespace gui {
class Button;
@@ -23,13 +24,13 @@ namespace guiutil {
void alert(
gui::GUI* gui,
const std::wstring& text,
gui::runnable on_hidden=nullptr
runnable on_hidden=nullptr
);
void confirm(
gui::GUI* gui,
const std::wstring& text,
gui::runnable on_confirm=nullptr,
runnable on_confirm=nullptr,
std::wstring yestext=L"",
std::wstring notext=L"");
}
+22 -11
View File
@@ -14,6 +14,7 @@ using glm::vec4;
Container::Container(vec2 coord, vec2 size) : UINode(coord, size) {
actualLength = size.y;
setColor(glm::vec4());
}
std::shared_ptr<UINode> Container::getAt(vec2 pos, std::shared_ptr<UINode> self) {
@@ -96,6 +97,17 @@ void Container::draw(const GfxContext* pctx, Assets* assets) {
}
}
void Container::drawBackground(const GfxContext* pctx, Assets* assets) {
if (color.a <= 0.0f)
return;
vec2 coord = calcCoord();
auto batch = pctx->getBatch2D();
batch->texture(nullptr);
batch->color = color;
batch->rect(coord.x, coord.y, size.x, size.y);
}
void Container::addBack(std::shared_ptr<UINode> node) {
nodes.insert(nodes.begin(), node);
node->setParent(this);
@@ -138,15 +150,6 @@ Panel::Panel(vec2 size, glm::vec4 padding, float interval, bool resizing)
Panel::~Panel() {
}
void Panel::drawBackground(const GfxContext* pctx, Assets* assets) {
vec2 coord = calcCoord();
auto batch = pctx->getBatch2D();
batch->texture(nullptr);
batch->color = color;
batch->rect(coord.x, coord.y, size.x, size.y);
}
void Panel::maxLength(int value) {
maxLength_ = value;
}
@@ -155,6 +158,14 @@ int Panel::maxLength() const {
return maxLength_;
}
void Panel::setPadding(glm::vec4 padding) {
this->padding = padding;
}
glm::vec4 Panel::getPadding() const {
return padding;
}
void Panel::refresh() {
float x = padding.x;
float y = padding.y;
@@ -182,7 +193,7 @@ void Panel::refresh() {
y += nodesize.y + margin.w + interval;
float width = size.x - padding.x - padding.z - margin.x - margin.z;
node->setSize(vec2(width, nodesize.y));;
//node->setSize(vec2(width, nodesize.y));;
node->refresh();
maxw = fmax(maxw, ex+node->getSize().x+margin.z+padding.z);
}
@@ -203,7 +214,7 @@ void Panel::refresh() {
x += nodesize.x + margin.z + interval;
float height = size.y - padding.y - padding.w - margin.y - margin.w;
node->setSize(vec2(nodesize.x, height));
//node->setSize(vec2(nodesize.x, height));
node->refresh();
maxh = fmax(maxh, y+margin.y+node->getSize().y+margin.w+padding.w);
}
+10 -4
View File
@@ -34,7 +34,7 @@ namespace gui {
Container(glm::vec2 coord, glm::vec2 size);
virtual void act(float delta) override;
virtual void drawBackground(const GfxContext* pctx, Assets* assets) {};
virtual void drawBackground(const GfxContext* pctx, Assets* assets);
virtual void draw(const GfxContext* pctx, Assets* assets) override;
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
virtual void addBack(std::shared_ptr<UINode> node);
@@ -55,11 +55,14 @@ namespace gui {
bool resizing_;
int maxLength_ = 0;
public:
Panel(glm::vec2 size, glm::vec4 padding=glm::vec4(2.0f), float interval=2.0f, bool resizing=true);
Panel(
glm::vec2 size,
glm::vec4 padding=glm::vec4(2.0f),
float interval=2.0f,
bool resizing=true
);
virtual ~Panel();
virtual void drawBackground(const GfxContext* pctx, Assets* assets) override;
virtual void orientation(Orientation orientation);
Orientation orientation() const;
@@ -67,6 +70,9 @@ namespace gui {
virtual void maxLength(int value);
int maxLength() const;
virtual void setPadding(glm::vec4 padding);
glm::vec4 getPadding() const;
};
struct Page {
+1 -1
View File
@@ -584,7 +584,7 @@ void create_settings_panel(Engine* engine) {
langs::get(L"Backlight", L"settings"), vec2(400, 32)
);
checkbox->supplier([=]() {
return engine->getSettings().graphics.backlight != 0;
return engine->getSettings().graphics.backlight;
});
checkbox->consumer([=](bool checked) {
engine->getSettings().graphics.backlight = checked;