Raspberry Pi Weighting Control System
This project serves as a simple weighting control system, that was realized as a Bachelor Thesis
gui_button.cpp
Go to the documentation of this file.
1 #include "gui_button.h"
2 
3 #include "imgui.h"
4 
5 gui_button::gui_button(const char *label, void (*callback)(), int x, int y, int width, int height,
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 }
16 
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.
void render_element()
Definition: gui_button.cpp:17
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.
Definition: gui_button.cpp:5
virtual void render_element()
Definition: gui_element.cpp:9
font_size
This enum defines sizes of corresponding fonts. E.g.: SMALL_FONT is 12px.