Go Down

Topic: My GUI library for a touchscreen (Read 744 times) previous topic - next topic


Aug 15, 2017, 07:29 pm Last Edit: Aug 15, 2017, 07:38 pm by fenyesb
Hello  :) , I made a library for displaying windows and in them buttons and texts. This was done as a homework project recently for a c++ course at my university, but maybe someone else may also find it useful. I used a Mega with a 320x240 TFT, but it should be easily adjustable.

You can add new windows and controls, by inheriting from the classes and overriding the appropriate functions. For example the code for the button class is like this, so you usually have to override the Touch and Draw functions if you want to create a more advanced button:
Code: [Select]
#include "Button.h"
#include "Config.h"
#include <string>

Button::Button(int x, int y) : Label(x, y), callback(NULL)


void Button::Draw(Graphics graphics) const
 graphics.Color(0, 70, 255);
 graphics.Color(255, 255, 255);

void Button::SetCallback(void (*f)(Button*))
 callback = f;

void Button::SetText(std::string s)
 text = s;

void Button::Touch()
 if(callback != NULL)

This is how you add controls to a window:
Code: [Select]

MainWindow::MainWindow(int x, int y, int w, int h) : Window(x, y, w, h)
 SetTitle("Control test");

 Label* mylabel = new Label(10, 10);
 mylabel->SetText("Hello Label");

 NumericInput* numinput = new NumericInput(10, 30);
 numinput->SetRange(-100, 100);
 Button* mybutton = new Button(10, 60);
 mybutton->SetText("Open dialog");

 Button* filesbutton = new Button(10, 90);
 filesbutton->SetText("Open SD card");
 Checkbox* checkbox = new Checkbox(10, 120);
 Button* resetbutton = new Button(10, 150);

link to the github page

If you have any feedback, feel free to post it here.  :)

Go Up