diff --git a/src/delegates.h b/src/delegates.h index c938cd02..7698c59a 100644 --- a/src/delegates.h +++ b/src/delegates.h @@ -10,5 +10,8 @@ using wstringsupplier = std::function; using wstringconsumer = std::function; using doublesupplier = std::function; using doubleconsumer = std::function; +using boolsupplier = std::function; +using boolconsumer = std::function; +using wstringchecker = std::function; #endif // DELEGATES_H_ diff --git a/src/frontend/gui/controls.cpp b/src/frontend/gui/controls.cpp index d79a2cd8..e2dc7003 100644 --- a/src/frontend/gui/controls.cpp +++ b/src/frontend/gui/controls.cpp @@ -10,24 +10,20 @@ #include "../../util/stringutil.h" #include "GUI.h" -using glm::vec2; -using glm::vec3; -using glm::vec4; - using namespace gui; Label::Label(std::string text, std::string fontName) - : UINode(vec2(), vec2(text.length() * 8, 15)), + : UINode(glm::vec2(), glm::vec2(text.length() * 8, 15)), text(util::str2wstr_utf8(text)), - fontName_(fontName) { + fontName(fontName) { setInteractive(false); } Label::Label(std::wstring text, std::string fontName) - : UINode(vec2(), vec2(text.length() * 8, 15)), + : UINode(glm::vec2(), glm::vec2(text.length() * 8, 15)), text(text), - fontName_(fontName) { + fontName(fontName) { setInteractive(false); } @@ -46,14 +42,14 @@ void Label::draw(const GfxContext* pctx, Assets* assets) { auto batch = pctx->getBatch2D(); batch->color = getColor(); - Font* font = assets->getFont(fontName_); - vec2 size = getSize(); - vec2 newsize = vec2( + Font* font = assets->getFont(fontName); + glm::vec2 size = getSize(); + glm::vec2 newsize ( font->calcWidth(text), font->getLineHeight()+font->getYOffset() ); - vec2 coord = calcCoord(); + glm::vec2 coord = calcCoord(); switch (align) { case Align::left: break; @@ -74,13 +70,13 @@ Label* Label::textSupplier(wstringsupplier supplier) { } // ================================= Image ==================================== -Image::Image(std::string texture, vec2 size) : UINode(vec2(), size), texture(texture) { +Image::Image(std::string texture, glm::vec2 size) : UINode(glm::vec2(), size), texture(texture) { setInteractive(false); } void Image::draw(const GfxContext* pctx, Assets* assets) { - vec2 coord = calcCoord(); - vec4 color = getColor(); + glm::vec2 coord = calcCoord(); + glm::vec4 color = getColor(); auto batch = pctx->getBatch2D(); batch->texture(assets->getTexture(texture)); batch->color = color; @@ -90,10 +86,11 @@ void Image::draw(const GfxContext* pctx, Assets* assets) { // ================================= Button =================================== Button::Button(std::shared_ptr content, glm::vec4 padding) - : Panel(vec2(), padding, 0) { - vec4 margin = getMargin(); - setSize(content->getSize()+vec2(padding[0]+padding[2]+margin[0]+margin[2], - padding[1]+padding[3]+margin[1]+margin[3])); + : Panel(glm::vec2(), padding, 0) { + glm::vec4 margin = getMargin(); + setSize(content->getSize()+ + glm::vec2(padding[0]+padding[2]+margin[0]+margin[2], + padding[1]+padding[3]+margin[1]+margin[3])); add(content); setScrollable(false); setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f)); @@ -102,13 +99,13 @@ Button::Button(std::shared_ptr content, glm::vec4 padding) Button::Button( std::wstring text, - vec4 padding, + glm::vec4 padding, onaction action, - vec2 size + glm::vec2 size ) : Panel(size, padding, 0) { if (size.y < 0.0f) { - size = vec2( + size = glm::vec2( glm::max(padding.x + padding.z + text.length()*8, size.x), glm::max(padding.y + padding.w + 16, size.y) ); @@ -122,7 +119,7 @@ Button::Button( label = std::make_shared