Pretty much everything Label wise is working
This commit is contained in:
		@@ -17,88 +17,66 @@ UILabelNew::UILabelNew(SceneItem *item) :
 | 
			
		||||
void UILabelNew::onStart() {
 | 
			
		||||
  this->shaderBuffer.init();
 | 
			
		||||
 | 
			
		||||
  auto font = this->getGame()->assetManager.get<NewTrueTypeAsset>("font_arial");
 | 
			
		||||
 | 
			
		||||
  std::vector<struct UILabelStyle> styleStack;
 | 
			
		||||
  struct UILabelStyle current;
 | 
			
		||||
  styleStack.push_back(current);
 | 
			
		||||
  std::vector<struct UILabelText> texts;
 | 
			
		||||
  texts.push_back({
 | 
			
		||||
    .text = "Hello",
 | 
			
		||||
    .style = {
 | 
			
		||||
      .color = COLOR_RED,
 | 
			
		||||
      .style = 0,
 | 
			
		||||
      .size = 32,
 | 
			
		||||
      .font = font
 | 
			
		||||
 | 
			
		||||
  std::function<void(Xml*)> parseChildren = [&](Xml *node) {
 | 
			
		||||
    if(node->children.empty()) {
 | 
			
		||||
      struct UILabelText text;
 | 
			
		||||
      text.style = current;
 | 
			
		||||
      text.text = node->value;
 | 
			
		||||
      texts.push_back(text);
 | 
			
		||||
    } else {
 | 
			
		||||
      auto itNode = node->children.begin();
 | 
			
		||||
      while(itNode != node->children.end()) {
 | 
			
		||||
        auto child = *itNode;
 | 
			
		||||
        assertTrue(child->node == "font");
 | 
			
		||||
 | 
			
		||||
        struct UILabelStyle style;
 | 
			
		||||
        if(child->attributes.contains("font")) {
 | 
			
		||||
          style.font = this->getGame()->assetManager.get<NewTrueTypeAsset>(child->attributes["font"]);
 | 
			
		||||
        } else {
 | 
			
		||||
          style.font = current.font;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(child->attributes.contains("size")) {
 | 
			
		||||
          style.size = std::stoi(child->attributes["size"]);
 | 
			
		||||
        } else {
 | 
			
		||||
          style.size = current.size;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(child->attributes.contains("style")) {
 | 
			
		||||
          std::string s = child->attributes["style"];
 | 
			
		||||
          style.style = 0;
 | 
			
		||||
          if(s.find("bold") != std::string::npos) style.style |= NEW_TRUETYPE_VARIANT_BOLD;
 | 
			
		||||
          if(s.find("italic") != std::string::npos) style.style |= NEW_TRUETYPE_VARIANT_ITALICS;
 | 
			
		||||
        } else {
 | 
			
		||||
          style.style = current.style;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(child->attributes.contains("color")) {
 | 
			
		||||
          style.color = Color::fromString(child->attributes["color"]);
 | 
			
		||||
        } else {
 | 
			
		||||
          style.color = current.color;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        styleStack.push_back(style);
 | 
			
		||||
        current = style;
 | 
			
		||||
 | 
			
		||||
        parseChildren(child);
 | 
			
		||||
 | 
			
		||||
        styleStack.pop_back();
 | 
			
		||||
        current = styleStack.back();
 | 
			
		||||
        ++itNode;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
  texts.push_back({
 | 
			
		||||
    .text = "World",
 | 
			
		||||
    .style = {
 | 
			
		||||
      .color = COLOR_BLUE,
 | 
			
		||||
      .style = 1,
 | 
			
		||||
      .size = 64,
 | 
			
		||||
      .font = font
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  auto root = Xml::load("<root>" + this->test + "</root>");
 | 
			
		||||
  parseChildren(&root);
 | 
			
		||||
  this->rebufferQuads(texts);
 | 
			
		||||
 | 
			
		||||
  // std::vector<struct UILabelStyle> styleStack;
 | 
			
		||||
  // struct UILabelStyle current;
 | 
			
		||||
  // styleStack.push_back(current);
 | 
			
		||||
  // std::vector<struct UILabelText> texts;
 | 
			
		||||
 | 
			
		||||
  // std::function<void(Xml*)> parseChildren = [&](Xml *node) {
 | 
			
		||||
  //   if(node->children.empty()) {
 | 
			
		||||
  //     struct UILabelText text;
 | 
			
		||||
  //     text.style = current;
 | 
			
		||||
  //     text.text = node->value;
 | 
			
		||||
  //     (node->value)
 | 
			
		||||
  //   } else {
 | 
			
		||||
  //     auto itNode = node->children.begin();
 | 
			
		||||
  //     while(itNode != node->children.end()) {
 | 
			
		||||
  //       auto child = *itNode;
 | 
			
		||||
  //       std::cout << "Node: " << child->node << std::endl;
 | 
			
		||||
 | 
			
		||||
  //       assertTrue(child->node == "font");
 | 
			
		||||
 | 
			
		||||
  //       struct UILabelStyle style;
 | 
			
		||||
  //       if(child->attributes.contains("font")) {
 | 
			
		||||
  //         style.font = this->getGame()->assetManager.get<NewTrueTypeAsset>(child->attributes["font"]);
 | 
			
		||||
  //       } else {
 | 
			
		||||
  //         style.font = current.font;
 | 
			
		||||
  //       }
 | 
			
		||||
 | 
			
		||||
  //       if(child->attributes.contains("size")) {
 | 
			
		||||
  //         style.size = std::stoi(child->attributes["size"]);
 | 
			
		||||
  //       } else {
 | 
			
		||||
  //         style.size = current.size;
 | 
			
		||||
  //       }
 | 
			
		||||
 | 
			
		||||
  //       if(child->attributes.contains("style")) {
 | 
			
		||||
  //         style.style = std::stoi(child->attributes["style"]);
 | 
			
		||||
  //       } else {
 | 
			
		||||
  //         style.style = current.style;
 | 
			
		||||
  //       }
 | 
			
		||||
 | 
			
		||||
  //       if(child->attributes.contains("color")) {
 | 
			
		||||
  //         style.color = std::stoi(child->attributes["color"]);
 | 
			
		||||
  //       } else {
 | 
			
		||||
  //         style.color = current.color;
 | 
			
		||||
  //       }
 | 
			
		||||
 | 
			
		||||
  //       styleStack.push_back(style);
 | 
			
		||||
  //       current = style;
 | 
			
		||||
 | 
			
		||||
  //       parseChildren(child);
 | 
			
		||||
 | 
			
		||||
  //       styleStack.pop_back();
 | 
			
		||||
  //       current = styleStack.back();
 | 
			
		||||
  //       ++itNode;
 | 
			
		||||
  //     }
 | 
			
		||||
  //   }
 | 
			
		||||
  // };
 | 
			
		||||
 | 
			
		||||
  // auto root = Xml::load("<root>" + this->test + "</root>");
 | 
			
		||||
  // parseChildren(&root);
 | 
			
		||||
  // this->rebufferQuads(texts);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<struct ShaderPassItem> UILabelNew::getUIRenderPasses() {
 | 
			
		||||
@@ -165,11 +143,10 @@ float_t UILabelNew::getContentHeight() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UILabelNew::rebufferQuads(std::vector<struct UILabelText> texts) {
 | 
			
		||||
  std::cout << "Rebuffering" << std::endl;
 | 
			
		||||
  auto oldTexts = this->texts;
 | 
			
		||||
 | 
			
		||||
  textureMap.clear();
 | 
			
		||||
  glm::vec2 position(32, 32);
 | 
			
		||||
  glm::vec2 position(0, 0);
 | 
			
		||||
  struct FontShaderBufferData fontData;
 | 
			
		||||
  int32_t quadIndex = 0;
 | 
			
		||||
  int32_t partIndex = 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
  struct UILabelStyle {
 | 
			
		||||
    struct Color color = COLOR_MAGENTA;
 | 
			
		||||
    struct Color color = COLOR_WHITE;
 | 
			
		||||
    flag_t style = 0;
 | 
			
		||||
    uint32_t size = 16;
 | 
			
		||||
    NewTrueTypeAsset *font = nullptr;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user