GPU Governor

Making a GUI library in C

june 2024- 3 minutes read

C and C++ has some good gui libraries like qt, gtk, nuklear and imgui but all of them are not easy to use and makes you write alot of boiler plate codes compared to something like tkinter. So i tried to create mine from Scratch with focus on easy of use.

Project Image

The image above is demo of Sweet; my Gui library. The demo shows a simple showcase of text, label, slider, dropdown and button widgets. you can find the source code on this github repo.

Tech Stack

C, SDL graphics framework, clang compiler.

Challenges & Learnings

I used Standard C libraries along side the SDL framework, at the time of the project i was able to inplement only a few widgets which includes label, text, buttons, dropdown, sliders.


Here's how a main function for creating basic widgets looks like:

          
            #include<stdio>
            #include<stdlib>
            #include<SDL2/SDL.h>
            #include"sweet.h"
            int main() {
              sw_init("Gui", 800, 700);
              
              //button
              CREATE my_button = sw_button("light", 2, 400, h4, BLACK, YELLOW, BOLD);
              // text based
              CREATE my_label = sw_label("This is a Label", 0, 30, h1, BLACK, BLUE, BOLD);
              CREATE my_text = sw_text("haha hi, you've been on my mind", 0, 2, h3, WHITE,BOLD);
              
              // drop down
               const char* options[] = {"Option 1", "Option 2", "Option 3", "Option 4", "Option 5"};
               CREATE dropdown = sw_drop_down(450, 100, options, 5);

              // slider         
               CREATE slider = sw_slider(100, 500, 400, 20, 100.0f, WHITE, BLACK, PINK, YELLOW, 24);
           
              // writing this because i may forget, if a widgets is not showing up ensure it is registering
              sw_loop();
           
               sw_quit();
               return 0;
           }
          
        

view the project source code.



ScreenShots

More Screen shots from the project :