Label - Horizon-NTH/HorizonGUI GitHub Wiki
The Label
class in the hgui::kernel
namespace is designed to display labels within your graphical application.
Labels can be used to present information, titles, or any textual content.
This class extends the Widget
class and includes features for setting and managing text, font, font size,
color, and scale. The class can be found in the header file Label.h
.
-
typedef std::tuple<unsigned int, color, float> TextOption
: Represents a text option with font size, color, and scale parameters.
-
Label(const std::string& text, const std::shared_ptr<Shader>& shader, const point& position, const std::shared_ptr<Font>& font, unsigned int fontSize, const color& color, bool align, float scale, HGUI_PRECISION rotation)
: Constructs aLabel
object with the specified text, shader, position, font, font size, color, scale and a rotation. You can also specify whether the text should be aligned based on all printable character (true) or only the one displayed (false).
-
std::string get_text() const
: Retrieves the current text content of the label. -
void set_text(const std::string& newText)
: Sets the text content of the label to the specified text. -
const color& get_color() const
: Retrieves the current text color. -
void set_color(const color& newColor)
: Sets the text color. -
unsigned int get_font_size() const
: Retrieves the font size used for rendering the label. -
void set_font_size(unsigned int fontSize)
: Sets the font size for rendering the label. -
const std::shared_ptr<Font>& get_font() const
: Retrieves the font used for rendering the label. -
void set_font(const std::shared_ptr<Font>& font)
: Sets the font for rendering the label. -
bool is_align() const
: Retrieves the type of alignement used. -
void set_alignement(bool align)
: Sets the type of alignement used. -
HGUI_PRECISION get_scale() const
: Retrieves the scale of the label. -
void set_scale(HGUI_PRECISION scale)
: Sets the scale of the label. -
HGUI_PRECISION get_rotation() const
: Retrieves the rotation of the label. -
void set_rotation(HGUI_PRECISION rotation)
: Sets the rotation of the label. -
void set_width(unsigned int newWidth)
: Sets the width of the label.
Note: This function can take some times so use it with parsimony. It will also change the height of the label.
-
void set_height(unsigned int newHeight)
: Sets the height of the label.
Note: This function can take some times so use it with parsimony. It will also change the width of the label.
#include <hgui/header/Label.h>
// Example Usage of Label class
std::shared_ptr<hgui::kernel::Shader> shader = /* initialize shader */;
std::shared_ptr<hgui::Font> font = /* initialize font */;
hgui::kernel::Label label("Hello, World!", shader, hgui::point(100, 100), font, 24, hgui::color(1.0f, 1.0f, 1.0f), 1.0f, 0.0f);
// Get current label text
std::string labelText = label.get_text();
// Change label text
label.set_text("New Text Content");
// Get font size
unsigned int fontSize = label.get_font_size();
// Change font size
label.set_font_size(30);
// Set label width or height
label.set_width(200);
label.set_height(50);
// Draw the label
label.draw();
Note: In the "Example Usage" section, we demonstrate how to create a
Label
object with specific text, font, font size, color, scale and rotation settings. You can get and set the label's text content, font size, and dimensions. The label can be rendered within your graphical application using thedraw
function, which displays the text according to the specified configuration. This class is suitable for displaying text labels in your user interface.