Raspberry Pi Weighting Control System
This project serves as a simple weighting control system, that was realized as a Bachelor Thesis
Public Member Functions | List of all members
gui_label Class Reference

This is a wrapper for ImGui Text which serves as unchangeble label. More...

#include <gui_label.h>

Inheritance diagram for gui_label:
gui_element

Public Member Functions

 gui_label (const char *label, int x=-1, int y=-1, int width=-1, app_workspace_ns::font_size font_size=app_workspace_ns::font_size::NORMAL_FONT)
 Construct a new gui label object. More...
 
 ~gui_label ()
 
void render_element ()
 
void set_label (const char *label)
 
- Public Member Functions inherited from gui_element
void set_refresh_screen (bool *refresh_flag)
 

Additional Inherited Members

- Public Attributes inherited from gui_element
int index = -1
 
- Protected Attributes inherited from gui_element
int width = -1
 
int x = -1
 
int y = -1
 
bool * refresh_screen = nullptr
 

Detailed Description

This is a wrapper for ImGui Text which serves as unchangeble label.

Definition at line 11 of file gui_label.h.

Constructor & Destructor Documentation

◆ gui_label()

gui_label::gui_label ( const char *  label,
int  x = -1,
int  y = -1,
int  width = -1,
app_workspace_ns::font_size  font_size = app_workspace_ns::font_size::NORMAL_FONT 
)

Construct a new gui label object.

Parameters
labelis required... since it's.. u'know... a label...
xif set to -1, isn't used
yif set to -1, isn't used
widthif set to -1, isn't used
font_sizeDefault font size is NORMAL

Definition at line 15 of file gui_label.cpp.

15  {
16  this->label = label;
17  this->x = x;
18  this->y = y;
19  this->width = width;
20  this->font_size = font_size;
21 }

◆ ~gui_label()

gui_label::~gui_label ( )

Definition at line 23 of file gui_label.cpp.

23  {
24 }

Member Function Documentation

◆ render_element()

void gui_label::render_element ( )
virtual

Override of parent function, that is required, because it does the actual rendering of the element

Reimplemented from gui_element.

Definition at line 26 of file gui_label.cpp.

26  {
28 
29  app_workspace_ns::font_size current_fs = app_workspace::get_instance()->get_font_size();
30 
31  // if element is requested with different font size
32  if (current_fs != font_size)
33  app_workspace::get_instance()->use_font_size(font_size);
34 
35  if (width > -1) {
36  // 480 = window width, 10 = padding
37  float wrap_width = (width + (x > -1 ? x : 0)) > 480 ? (480 - x - 10) : width;
38  ImVec2 cpos = ImGui::GetCursorPos();
39  ImGui::PushTextWrapPos(cpos.x + wrap_width);
40  }
41 
42  ImGui::TextWrapped(this->label);
43  //ImGui::Text(this->label);
44 
45  if (width > -1) {
46  ImGui::PopTextWrapPos();
47  }
48 
49  // return back original font size (otherwise all subsequent elements would use font_size, unless specified)
50  if (current_fs != font_size)
51  app_workspace::get_instance()->use_font_size(current_fs);
52 }
static std::unique_ptr< app_workspace > & get_instance()
Get the instance app_workspace which is a singleton.
virtual void render_element()
Definition: gui_element.cpp:9
font_size
This enum defines sizes of corresponding fonts. E.g.: SMALL_FONT is 12px.

◆ set_label()

void gui_label::set_label ( const char *  label)

Changes label of the instance of this element

Definition at line 54 of file gui_label.cpp.

54  {
55  this->label = label;
56 }

The documentation for this class was generated from the following files: