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

This is a wrapper for various ImGui input types. More...

#include <gui_input.h>

Inheritance diagram for gui_input:
gui_element

Public Member Functions

 gui_input (input_type type, void *data, int data_size, int x=-1, int y=-1, int width=-1, const char *label=nullptr, app_workspace_ns::font_size font_size=app_workspace_ns::font_size::NORMAL_FONT)
 Construct a new gui input object. More...
 
void render_element ()
 
input_type get_type ()
 
app_workspace_ns::kb_input_type get_in_type ()
 
void set_min_max (int min=INT_MIN, int max=INT_MAX)
 
void set_min_max (float min=FLT_MIN, float max=FLT_MAX)
 
void set_min_max (double min=DBL_MIN, double max=DBL_MAX)
 
void set_value_change_action (void(*callback)())
 
- 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 various ImGui input types.

Definition at line 24 of file gui_input.h.

Constructor & Destructor Documentation

◆ gui_input()

gui_input::gui_input ( input_type  type,
void *  data,
int  data_size,
int  x = -1,
int  y = -1,
int  width = -1,
const char *  label = nullptr,
app_workspace_ns::font_size  font_size = app_workspace_ns::font_size::NORMAL_FONT 
)

Construct a new gui input object.

Parameters
typeinput data type
datacontainer for input data, this should correspond to chosen @type
data_sizemax data size, this is used mainly for text input
xif set to -1, isn't used
yif set to -1, isn't used
widthif set to -1, isn't used
labelinput can have a label (name), nullptr when not used
font_sizeDefault font size is NORMAL

Definition at line 6 of file gui_input.cpp.

8 {
9  this->type = type;
10  this->data = data;
11  this->data_size = data_size;
12  this->x = x;
13  this->y = y;
14  this->width = width;
15  this->label = label;
16  this->font_size = font_size;
17 }

Member Function Documentation

◆ get_in_type()

app_workspace_ns::kb_input_type gui_input::get_in_type ( )

Returns keyboard input type, that is determined by data input type

Definition at line 107 of file gui_input.cpp.

107  {
108  // change: password moved to be IN_INT instead of IN_TEXT (due to difficulty inputting with key cycling)
109  switch (type) {
117  }
118 }
@ IN_DOUBLE
Definition: gui_input.h:17
@ IN_INT
Definition: gui_input.h:12
@ IN_PASSWORD_PLAIN
Definition: gui_input.h:16
@ IN_TEXT
Definition: gui_input.h:14
@ IN_PASSWORD
Definition: gui_input.h:15
@ IN_FLOAT
Definition: gui_input.h:13

◆ get_type()

input_type gui_input::get_type ( )

Returns input type

Definition at line 102 of file gui_input.cpp.

102  {
103  return type;
104 }

◆ render_element()

void gui_input::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 19 of file gui_input.cpp.

19  {
21 
22  app_workspace_ns::font_size current_fs = app_workspace::get_instance()->get_font_size();
23  char lab[100] = {0};
24  bool modified = false;
25 
26  // if element is requested with different font size
27  if (current_fs != font_size)
28  app_workspace::get_instance()->use_font_size(font_size);
29 
30  if (width > -1)
31  ImGui::SetNextItemWidth((float) width);
32  //ImGui::PushItemWidth((float) width);
33 
34  sprintf(lab, "%s##%d", label ? label : "", index);
35  /*
36  if (this->label != nullptr)
37  sprintf(lab, "%s##%d", this->label, this->index);
38  else
39  sprintf(lab, "##%d", this->index);
40  */
41 
42  switch (this->type) {
43  case IN_INT:
44  modified = ImGui::InputInt(lab, (int*) data, 0, 0);
45  break;
46  case IN_FLOAT:
47  modified = ImGui::InputFloat(lab, (float*) data);
48  break;
49  case IN_PASSWORD_PLAIN:
50  case IN_TEXT:
51  //modified = ImGui::InputText(lab, (char*) data, data_size);
52  ImGui::InputText(lab, (char*) data, data_size);
53  break;
54  case IN_PASSWORD:
55  //modified = ImGui::InputText(lab, (char*) data, data_size, ImGuiInputTextFlags_Password);
56  ImGui::InputText(lab, (char*) data, data_size, ImGuiInputTextFlags_Password);
57  break;
58  case IN_DOUBLE:
59  modified = ImGui::InputDouble(lab, (double*) data);
60  break;
61 
62  default:
63  spdlog::error("gui_input.cpp - Unrecognized input type");
64  break;
65  }
66 
67  // return back original font size (otherwise all subsequent elements would use font_size, unless specified)
68  if (current_fs != font_size)
69  app_workspace::get_instance()->use_font_size(current_fs);
70 
71  if (modified) {
72  check_input_limit();
73 
74  if (this->callback != nullptr)
75  this->callback();
76  }
77 }
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_min_max() [1/3]

void gui_input::set_min_max ( double  min = DBL_MIN,
double  max = DBL_MAX 
)

Setter for minimal and maximal values for DOUBLE inputs

Definition at line 132 of file gui_input.cpp.

132  {
133  this->has_min_max = true;
134  this->d_min = min;
135  this->d_max = max;
136 }

◆ set_min_max() [2/3]

void gui_input::set_min_max ( float  min = FLT_MIN,
float  max = FLT_MAX 
)

Setter for minimal and maximal values for FLOAT inputs

Definition at line 126 of file gui_input.cpp.

126  {
127  this->has_min_max = true;
128  this->f_min = min;
129  this->f_max = max;
130 }

◆ set_min_max() [3/3]

void gui_input::set_min_max ( int  min = INT_MIN,
int  max = INT_MAX 
)

Setter for minimal and maximal values for INT inputs

Definition at line 120 of file gui_input.cpp.

120  {
121  this->has_min_max = true;
122  this->i_min = min;
123  this->i_max = max;
124 }

◆ set_value_change_action()

void gui_input::set_value_change_action ( void(*)()  callback)

Sets input value gchange listener

Definition at line 138 of file gui_input.cpp.

138  {
139  this->callback = callback;
140 }

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