fix UINode enums naming
This commit is contained in:
parent
c6b78dae3e
commit
7abe552e3c
@ -192,7 +192,7 @@ Hud::Hud(Engine& engine, LevelFrontend& frontend, Player& player)
|
|||||||
gui.add(contentAccessPanel);
|
gui.add(contentAccessPanel);
|
||||||
|
|
||||||
auto dplotter = std::make_shared<Plotter>(gui, 350, 250, 2000, 16);
|
auto dplotter = std::make_shared<Plotter>(gui, 350, 250, 2000, 16);
|
||||||
dplotter->setGravity(Gravity::bottom_right);
|
dplotter->setGravity(Gravity::BOTTOM_RIGHT);
|
||||||
dplotter->setInteractive(false);
|
dplotter->setInteractive(false);
|
||||||
add(HudElement(HudElementMode::PERMANENT, nullptr, dplotter, true));
|
add(HudElement(HudElementMode::PERMANENT, nullptr, dplotter, true));
|
||||||
|
|
||||||
|
|||||||
@ -47,7 +47,7 @@ Button::Button(
|
|||||||
setScrollable(false);
|
setScrollable(false);
|
||||||
|
|
||||||
label = std::make_shared<Label>(gui, text);
|
label = std::make_shared<Label>(gui, text);
|
||||||
label->setAlign(Align::center);
|
label->setAlign(Align::CENTER);
|
||||||
label->setSize(getContentSize());
|
label->setSize(getContentSize());
|
||||||
label->setInteractive(false);
|
label->setInteractive(false);
|
||||||
add(label);
|
add(label);
|
||||||
@ -95,5 +95,5 @@ Align Button::getTextAlign() const {
|
|||||||
if (label) {
|
if (label) {
|
||||||
return label->getAlign();
|
return label->getAlign();
|
||||||
}
|
}
|
||||||
return Align::left;
|
return Align::LEFT;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -230,14 +230,14 @@ void Label::draw(const DrawContext& pctx, const Assets& assets) {
|
|||||||
|
|
||||||
glm::vec2 pos = calcPos();
|
glm::vec2 pos = calcPos();
|
||||||
switch (align) {
|
switch (align) {
|
||||||
case Align::left: break;
|
case Align::LEFT: break;
|
||||||
case Align::center: pos.x += (size.x-newsize.x)*0.5f; break;
|
case Align::CENTER: pos.x += (size.x-newsize.x)*0.5f; break;
|
||||||
case Align::right: pos.x += size.x-newsize.x; break;
|
case Align::RIGHT: pos.x += size.x-newsize.x; break;
|
||||||
}
|
}
|
||||||
switch (valign) {
|
switch (valign) {
|
||||||
case Align::top: break;
|
case Align::TOP: break;
|
||||||
case Align::center: pos.y += (size.y-newsize.y)*0.5f; break;
|
case Align::CENTER: pos.y += (size.y-newsize.y)*0.5f; break;
|
||||||
case Align::bottom: pos.y += size.y-newsize.y; break;
|
case Align::BOTTOM: pos.y += size.y-newsize.y; break;
|
||||||
}
|
}
|
||||||
textYOffset = pos.y-calcPos().y;
|
textYOffset = pos.y-calcPos().y;
|
||||||
totalLineHeight = lineHeight;
|
totalLineHeight = lineHeight;
|
||||||
|
|||||||
@ -44,7 +44,7 @@ namespace gui {
|
|||||||
float lineInterval = 1.5f;
|
float lineInterval = 1.5f;
|
||||||
|
|
||||||
/// @brief Vertical alignment (only when multiline is set to false)
|
/// @brief Vertical alignment (only when multiline is set to false)
|
||||||
Align valign = Align::center;
|
Align valign = Align::CENTER;
|
||||||
|
|
||||||
/// @brief Line separators and wrapping will be ignored if set to false
|
/// @brief Line separators and wrapping will be ignored if set to false
|
||||||
bool multiline = false;
|
bool multiline = false;
|
||||||
|
|||||||
@ -216,7 +216,7 @@ TextBox::TextBox(GUI& gui, std::wstring placeholder, glm::vec4 padding)
|
|||||||
lineNumbersLabel->setSize(
|
lineNumbersLabel->setSize(
|
||||||
size - glm::vec2(padding.z + padding.x, padding.w + padding.y)
|
size - glm::vec2(padding.z + padding.x, padding.w + padding.y)
|
||||||
);
|
);
|
||||||
lineNumbersLabel->setVerticalAlign(Align::top);
|
lineNumbersLabel->setVerticalAlign(Align::TOP);
|
||||||
add(lineNumbersLabel);
|
add(lineNumbersLabel);
|
||||||
|
|
||||||
setHoverColor(glm::vec4(0.05f, 0.1f, 0.2f, 0.75f));
|
setHoverColor(glm::vec4(0.05f, 0.1f, 0.2f, 0.75f));
|
||||||
@ -565,7 +565,7 @@ bool TextBox::isValid() const {
|
|||||||
void TextBox::setMultiline(bool multiline) {
|
void TextBox::setMultiline(bool multiline) {
|
||||||
this->multiline = multiline;
|
this->multiline = multiline;
|
||||||
label->setMultiline(multiline);
|
label->setMultiline(multiline);
|
||||||
label->setVerticalAlign(multiline ? Align::top : Align::center);
|
label->setVerticalAlign(multiline ? Align::TOP : Align::CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextBox::isMultiline() const {
|
bool TextBox::isMultiline() const {
|
||||||
|
|||||||
@ -334,7 +334,7 @@ void UINode::reposition() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UINode::setGravity(Gravity gravity) {
|
void UINode::setGravity(Gravity gravity) {
|
||||||
if (gravity == Gravity::none) {
|
if (gravity == Gravity::NONE) {
|
||||||
setPositionFunc(nullptr);
|
setPositionFunc(nullptr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -349,27 +349,27 @@ void UINode::setGravity(Gravity gravity) {
|
|||||||
|
|
||||||
float x = 0.0f, y = 0.0f;
|
float x = 0.0f, y = 0.0f;
|
||||||
switch (gravity) {
|
switch (gravity) {
|
||||||
case Gravity::top_left:
|
case Gravity::TOP_LEFT:
|
||||||
case Gravity::center_left:
|
case Gravity::CENTER_LEFT:
|
||||||
case Gravity::bottom_left: x = margin.x; break;
|
case Gravity::BOTTOM_LEFT: x = margin.x; break;
|
||||||
case Gravity::top_center:
|
case Gravity::TOP_CENTER:
|
||||||
case Gravity::center_center:
|
case Gravity::CENTER_CENTER:
|
||||||
case Gravity::bottom_center: x = (parentSize.x-size.x)/2.0f; break;
|
case Gravity::BOTTOM_CENTER: x = (parentSize.x-size.x)/2.0f; break;
|
||||||
case Gravity::top_right:
|
case Gravity::TOP_RIGHT:
|
||||||
case Gravity::center_right:
|
case Gravity::CENTER_RIGHT:
|
||||||
case Gravity::bottom_right: x = parentSize.x-size.x-margin.z; break;
|
case Gravity::BOTTOM_RIGHT: x = parentSize.x-size.x-margin.z; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
switch (gravity) {
|
switch (gravity) {
|
||||||
case Gravity::top_left:
|
case Gravity::TOP_LEFT:
|
||||||
case Gravity::top_center:
|
case Gravity::TOP_CENTER:
|
||||||
case Gravity::top_right: y = margin.y; break;
|
case Gravity::TOP_RIGHT: y = margin.y; break;
|
||||||
case Gravity::center_left:
|
case Gravity::CENTER_LEFT:
|
||||||
case Gravity::center_center:
|
case Gravity::CENTER_CENTER:
|
||||||
case Gravity::center_right: y = (parentSize.y-size.y)/2.0f; break;
|
case Gravity::CENTER_RIGHT: y = (parentSize.y-size.y)/2.0f; break;
|
||||||
case Gravity::bottom_left:
|
case Gravity::BOTTOM_LEFT:
|
||||||
case Gravity::bottom_center:
|
case Gravity::BOTTOM_CENTER:
|
||||||
case Gravity::bottom_right: y = parentSize.y-size.y-margin.w; break;
|
case Gravity::BOTTOM_RIGHT: y = parentSize.y-size.y-margin.w; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return glm::vec2(x, y);
|
return glm::vec2(x, y);
|
||||||
|
|||||||
@ -50,24 +50,24 @@ namespace gui {
|
|||||||
using StringCallbacksSet = CallbacksSet<GUI&, const std::string&>;
|
using StringCallbacksSet = CallbacksSet<GUI&, const std::string&>;
|
||||||
|
|
||||||
enum class Align {
|
enum class Align {
|
||||||
left, center, right,
|
LEFT, CENTER, RIGHT,
|
||||||
top=left, bottom=right,
|
TOP=LEFT, BOTTOM=RIGHT,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Gravity {
|
enum class Gravity {
|
||||||
none,
|
NONE,
|
||||||
|
|
||||||
top_left,
|
TOP_LEFT,
|
||||||
top_center,
|
TOP_CENTER,
|
||||||
top_right,
|
TOP_RIGHT,
|
||||||
|
|
||||||
center_left,
|
CENTER_LEFT,
|
||||||
center_center,
|
CENTER_CENTER,
|
||||||
center_right,
|
CENTER_RIGHT,
|
||||||
|
|
||||||
bottom_left,
|
BOTTOM_LEFT,
|
||||||
bottom_center,
|
BOTTOM_CENTER,
|
||||||
bottom_right
|
BOTTOM_RIGHT
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief Base abstract class for all UI elements
|
/// @brief Base abstract class for all UI elements
|
||||||
@ -112,7 +112,7 @@ namespace gui {
|
|||||||
/// @brief z-index property specifies the stack order of an element
|
/// @brief z-index property specifies the stack order of an element
|
||||||
int zindex = 0;
|
int zindex = 0;
|
||||||
/// @brief element content alignment (supported by Label only)
|
/// @brief element content alignment (supported by Label only)
|
||||||
Align align = Align::left;
|
Align align = Align::LEFT;
|
||||||
/// @brief parent element
|
/// @brief parent element
|
||||||
UINode* parent = nullptr;
|
UINode* parent = nullptr;
|
||||||
/// @brief position supplier for the element (called on parent element size update)
|
/// @brief position supplier for the element (called on parent element size update)
|
||||||
|
|||||||
@ -101,7 +101,7 @@ void guiutil::confirm(
|
|||||||
gui, glm::vec2(600, 200), glm::vec4(8.0f), 8.0f
|
gui, glm::vec2(600, 200), glm::vec4(8.0f), 8.0f
|
||||||
);
|
);
|
||||||
|
|
||||||
panel->setGravity(Gravity::center_center);
|
panel->setGravity(Gravity::CENTER_CENTER);
|
||||||
container->add(panel);
|
container->add(panel);
|
||||||
panel->setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
panel->setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||||
|
|
||||||
|
|||||||
@ -30,31 +30,31 @@
|
|||||||
using namespace gui;
|
using namespace gui;
|
||||||
|
|
||||||
static Align align_from_string(std::string_view str, Align def) {
|
static Align align_from_string(std::string_view str, Align def) {
|
||||||
if (str == "left") return Align::left;
|
if (str == "left") return Align::LEFT;
|
||||||
if (str == "center") return Align::center;
|
if (str == "center") return Align::CENTER;
|
||||||
if (str == "right") return Align::right;
|
if (str == "right") return Align::RIGHT;
|
||||||
if (str == "top") return Align::top;
|
if (str == "top") return Align::TOP;
|
||||||
if (str == "bottom") return Align::bottom;
|
if (str == "bottom") return Align::BOTTOM;
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Gravity gravity_from_string(const std::string& str) {
|
static Gravity gravity_from_string(const std::string& str) {
|
||||||
static const std::unordered_map<std::string, Gravity> gravity_names {
|
static const std::unordered_map<std::string, Gravity> gravity_names {
|
||||||
{"top-left", Gravity::top_left},
|
{"top-left", Gravity::TOP_LEFT},
|
||||||
{"top-center", Gravity::top_center},
|
{"top-center", Gravity::TOP_CENTER},
|
||||||
{"top-right", Gravity::top_right},
|
{"top-right", Gravity::TOP_RIGHT},
|
||||||
{"center-left", Gravity::center_left},
|
{"center-left", Gravity::CENTER_LEFT},
|
||||||
{"center-center", Gravity::center_center},
|
{"center-center", Gravity::CENTER_CENTER},
|
||||||
{"center-right", Gravity::center_right},
|
{"center-right", Gravity::CENTER_RIGHT},
|
||||||
{"bottom-left", Gravity::bottom_left},
|
{"bottom-left", Gravity::BOTTOM_LEFT},
|
||||||
{"bottom-center", Gravity::bottom_center},
|
{"bottom-center", Gravity::BOTTOM_CENTER},
|
||||||
{"bottom-right", Gravity::bottom_right},
|
{"bottom-right", Gravity::BOTTOM_RIGHT},
|
||||||
};
|
};
|
||||||
auto found = gravity_names.find(str);
|
auto found = gravity_names.find(str);
|
||||||
if (found != gravity_names.end()) {
|
if (found != gravity_names.end()) {
|
||||||
return found->second;
|
return found->second;
|
||||||
}
|
}
|
||||||
return Gravity::none;
|
return Gravity::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static runnable create_runnable(
|
static runnable create_runnable(
|
||||||
@ -334,7 +334,7 @@ static std::shared_ptr<UINode> read_label(
|
|||||||
if (element.has("multiline")) {
|
if (element.has("multiline")) {
|
||||||
label->setMultiline(element.attr("multiline").asBool());
|
label->setMultiline(element.attr("multiline").asBool());
|
||||||
if (!element.has("valign")) {
|
if (!element.has("valign")) {
|
||||||
label->setVerticalAlign(Align::top);
|
label->setVerticalAlign(Align::TOP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (element.has("text-wrap")) {
|
if (element.has("text-wrap")) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user