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_button Class Reference

Wrapper for ImGui::Button. More...

#include <gui_button.h>

Inheritance diagram for gui_button:
gui_element

Public Member Functions

 gui_button (const char *label, void(*callback)(), int x=-1, int y=-1, int width=-1, int height=-1, app_workspace_ns::font_size font_size=app_workspace_ns::font_size::NORMAL_FONT)
 Construct a new gui button object. More...
 
void render_element ()
 
- 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

Wrapper for ImGui::Button.

Definition at line 11 of file gui_button.h.

Constructor & Destructor Documentation

◆ gui_button()

gui_button::gui_button ( const char *  label,
void(*)()  callback,
int  x = -1,
int  y = -1,
int  width = -1,
int  height = -1,
app_workspace_ns::font_size  font_size = app_workspace_ns::font_size::NORMAL_FONT 
)

Construct a new gui button object.

Parameters
labelis required parameter
callbackis required parameter
xif set to -1, isn't used
yif set to -1, isn't used
widthif set to -1, isn't used
heightif set to -1, isn't used
font_sizeDefault font size is NORMAL

Definition at line 5 of file gui_button.cpp.

7 {
8  this->label = label;
9  this->callback = callback;
10  this->x = x;
11  this->y = y;
12  this->width = width;
13  this->height = height;
14  this->font_size = font_size;
15 }

Member Function Documentation

◆ render_element()

void gui_button::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 17 of file gui_button.cpp.

17  {
19 
20  // this was added, because label serves as unique identifier and in debug screen 3
21  // 3 buttons have same label causing all of tehm being selected at once
22  char lab[100] = {0};
23  sprintf(lab, "%s##%d", label ? label : "", index);
24 
25  app_workspace_ns::font_size current_fs = app_workspace::get_instance()->get_font_size();
26 
27  // if element is requested with different font size
28  if (current_fs != font_size)
29  app_workspace::get_instance()->use_font_size(font_size);
30 
31  ImVec2 size(this->width > 0 ? (float) this->width : 0.0f,
32  this->height > 0 ? (float) this->height : 0.0f);
33 
34  if (ImGui::Button(lab, size)) {
35  if (this->callback != nullptr)
36  this->callback();
37  }
38 
39  // return back original font size (otherwise all subsequent elements would use font_size, unless specified)
40  if (current_fs != font_size)
41  app_workspace::get_instance()->use_font_size(current_fs);
42 }
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.

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