UiXmlReader update
This commit is contained in:
parent
6ae59cd851
commit
3cd648e10c
@ -177,13 +177,20 @@ Button* Button::listenAction(onaction action) {
|
||||
return this;
|
||||
}
|
||||
|
||||
void Button::textAlign(Align align) {
|
||||
void Button::setTextAlign(Align align) {
|
||||
if (label) {
|
||||
label->setAlign(align);
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
Align Button::getTextAlign() const {
|
||||
if (label) {
|
||||
return label->getAlign();
|
||||
}
|
||||
return Align::left;
|
||||
}
|
||||
|
||||
// ============================== RichButton ==================================
|
||||
RichButton::RichButton(vec2 size) : Container(vec2(), size) {
|
||||
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
|
||||
|
||||
@ -73,7 +73,8 @@ namespace gui {
|
||||
virtual void mouseRelease(GUI*, int x, int y) override;
|
||||
virtual Button* listenAction(onaction action);
|
||||
|
||||
virtual void textAlign(Align align);
|
||||
virtual Align getTextAlign() const;
|
||||
virtual void setTextAlign(Align align);
|
||||
|
||||
virtual void setText(std::wstring text);
|
||||
virtual std::wstring getText() const;
|
||||
|
||||
@ -98,6 +98,13 @@ static glm::vec4 readColor(const std::string& str) {
|
||||
}
|
||||
}
|
||||
|
||||
static Align align_from_string(const std::string& str, Align def) {
|
||||
if (str == "left") return Align::left;
|
||||
if (str == "center") return Align::center;
|
||||
if (str == "right") return Align::right;
|
||||
return def;
|
||||
}
|
||||
|
||||
/* Read basic UINode properties */
|
||||
static void readUINode(xml::xmlelement element, UINode& node) {
|
||||
if (element->has("coord")) {
|
||||
@ -109,6 +116,12 @@ static void readUINode(xml::xmlelement element, UINode& node) {
|
||||
if (element->has("color")) {
|
||||
node.setColor(readColor(element->attr("color").getText()));
|
||||
}
|
||||
if (element->has("margin")) {
|
||||
node.setMargin(readVec4(element->attr("margin").getText()));
|
||||
}
|
||||
|
||||
std::string alignName = element->attr("align", "").getText();
|
||||
node.setAlign(align_from_string(alignName, node.getAlign()));
|
||||
}
|
||||
|
||||
static void _readContainer(UiXmlReader& reader, xml::xmlelement element, Container& container) {
|
||||
@ -128,10 +141,6 @@ static void _readPanel(UiXmlReader& reader, xml::xmlelement element, Panel& pane
|
||||
panel.setPadding(readVec4(element->attr("padding").getText()));
|
||||
}
|
||||
|
||||
if (element->has("margin")) {
|
||||
panel.setMargin(readVec4(element->attr("margin").getText()));
|
||||
}
|
||||
|
||||
if (element->has("size")) {
|
||||
panel.setResizing(false);
|
||||
}
|
||||
@ -147,7 +156,9 @@ static void _readPanel(UiXmlReader& reader, xml::xmlelement element, Panel& pane
|
||||
static std::wstring readAndProcessInnerText(xml::xmlelement element) {
|
||||
std::wstring text = L"";
|
||||
if (element->size() == 1) {
|
||||
text = util::str2wstr_utf8(element->sub(0)->attr("#").getText());
|
||||
std::string source = element->sub(0)->attr("#").getText();
|
||||
util::trim(source);
|
||||
text = util::str2wstr_utf8(source);
|
||||
if (text[0] == '@') {
|
||||
text = langs::get(text.substr(1));
|
||||
}
|
||||
@ -179,6 +190,9 @@ static std::shared_ptr<UINode> readButton(UiXmlReader& reader, xml::xmlelement e
|
||||
callback();
|
||||
});
|
||||
}
|
||||
if (element->has("text-align")) {
|
||||
button->setTextAlign(align_from_string(element->attr("text-align").getText(), button->getTextAlign()));
|
||||
}
|
||||
return button;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user