Cleanup of some code
This commit is contained in:
		@@ -8,4 +8,5 @@ target_sources(${DAWN_TARGET_NAME}
 | 
			
		||||
  PRIVATE
 | 
			
		||||
    UILabel.cpp
 | 
			
		||||
    UIRichTextLabel.cpp
 | 
			
		||||
    UISimpleLabel.cpp
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										49
									
								
								src/dawn/scene/components/ui/text/UISimpleLabel.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								src/dawn/scene/components/ui/text/UISimpleLabel.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
// Copyright (c) 2023 Dominic Masters
 | 
			
		||||
// 
 | 
			
		||||
// This software is released under the MIT License.
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#include "UISimpleLabel.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace Dawn;
 | 
			
		||||
 | 
			
		||||
UISimpleLabel::UISimpleLabel(SceneItem *i) :
 | 
			
		||||
  UILabel(i),
 | 
			
		||||
  text("Hello World"),
 | 
			
		||||
  font(nullptr),
 | 
			
		||||
  size(12),
 | 
			
		||||
  style(0),
 | 
			
		||||
  decorations(0),
 | 
			
		||||
  color(COLOR_WHITE)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void UISimpleLabel::onStart() {
 | 
			
		||||
  UILabel::onStart();
 | 
			
		||||
 | 
			
		||||
  useEffect([&] {
 | 
			
		||||
    if(this->font == nullptr) {
 | 
			
		||||
      this->rebufferQuads({ });
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    struct UILabelText text;
 | 
			
		||||
    struct UILabelStyle style;
 | 
			
		||||
    style.font = this->font;
 | 
			
		||||
    style.size = this->size;
 | 
			
		||||
    style.style = this->style;
 | 
			
		||||
    style.decorations = this->decorations;
 | 
			
		||||
    style.color = this->color;
 | 
			
		||||
 | 
			
		||||
    text.style = style;
 | 
			
		||||
    text.text = this->text;
 | 
			
		||||
    this->rebufferQuads({ text });
 | 
			
		||||
  }, {
 | 
			
		||||
    &this->text,
 | 
			
		||||
    &this->font, 
 | 
			
		||||
    &this->size, 
 | 
			
		||||
    &this->style,
 | 
			
		||||
    &this->decorations,
 | 
			
		||||
    &this->color
 | 
			
		||||
  })();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										29
									
								
								src/dawn/scene/components/ui/text/UISimpleLabel.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/dawn/scene/components/ui/text/UISimpleLabel.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
// Copyright (c) 2023 Dominic Masters
 | 
			
		||||
// 
 | 
			
		||||
// This software is released under the MIT License.
 | 
			
		||||
// https://opensource.org/licenses/MIT
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "UILabel.hpp"
 | 
			
		||||
 | 
			
		||||
namespace Dawn {
 | 
			
		||||
  class UISimpleLabel : public UILabel {
 | 
			
		||||
    public:
 | 
			
		||||
      // @optional
 | 
			
		||||
      StateProperty<std::string> text;
 | 
			
		||||
      // @optional
 | 
			
		||||
      StateProperty<TrueTypeAsset*> font;
 | 
			
		||||
      // @optional
 | 
			
		||||
      StateProperty<uint32_t> size;
 | 
			
		||||
      // @optional
 | 
			
		||||
      StateProperty<flag_t> style;
 | 
			
		||||
      // @optional
 | 
			
		||||
      StateProperty<flag_t> decorations;
 | 
			
		||||
      // @optional
 | 
			
		||||
      StateProperty<struct Color> color;
 | 
			
		||||
      
 | 
			
		||||
      UISimpleLabel(SceneItem *item);
 | 
			
		||||
 | 
			
		||||
      void onStart() override;
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user