GTK-UI is a library for creating an easy interfaces in C language using low level GTK library.
Just grab gtkui.h
and gtkui.c
files and put them in your project.
Include in the following way:
#include "gtkui.h"
And compile with:
gcc `pkg-config --cflags gtk+-3.0` main.c gtkui.c `pkg-config --libs gtk+-3.0`
- Clone this repo
- run
make
- run
sudo make install
Include in the following way:
#include <gtkui.h>
And compile with:
gcc `pkg-config --cflags gtkui` main.c `pkg-config --libs gtkui`
Grab newest release from here https://github.com/Ph0enixKM/GTK-UI/releases
Include in the following way:
#include <gtkui.h>
And compile with:
gcc `pkg-config --cflags gtkui` main.c `pkg-config --libs gtkui`
The first step of learning how GTK-UI works is to create a Hello World program. As you can see it looks pretty much similar to the vanilla GTK version.
#include <gtkui.h>
int main(int argc, char* argv[]) {
gtk_init(&argc, &argv);
// Here is our GTK-UI function
UIPrint("Hello World");
gtk_main();
}
Keep in mind that GTK-UI works in synergy with GTK and is IS NOT supposed to replace the usage of GTK library.
UI window = UICreateWindow("Title", (WindowConfig) {
.width = 1020, // Width of the window
.height = 720, // Height of the window
.center = true, // Shall the window be centered?
.resizable = true, // Shall the window be resizable?
.border = 10, // Border size of the window
.exit = true // Shall the program end on exit?
});
You do not have to show the window - it's set to be visible by default - the same thing applies to all components made by GTK-UI
Convenient macro for creating window:
UI window = UIWindow("Title", .width = 1020, .height = 720, .exit = true);
UI label = UICreateLabel("Some text here");
UIAppend(window, label);
// Optionally we can also use
UIRemove(window, label);
// We can show and hide elements as well
UIHide(label);
UIShow(label);
// Set and get text of a label
UISetLabelText(label, "New text");
char* text = UIGetLabelText(label);
UI button = UICreateButton("Click me!");
UIAppend(window, button);
UI boxh = UICreateVBox(true); // Horizontal box with homogeneous attribute
UI boxv = UICreateHBox(false); // Vertical box without homogeneous attribute
// Set spacing of a box
UISetBoxSpacing(boxh, 10);
-
- Without switcher:
UI stack = UICreateStack(); UI label1 = UICreateLabel("item one"); UI label2 = UICreateLabel("item one"); UIStackAdd(stack, label1, "first"); UIStackAdd(stack, label2, "second"); UIStackVisibleName(stack, "second");
- With switcher:
UI stack = UICreateStack(); UI switcher = UICreateStackSwitcher(stack); UI label1 = UICreateLabel("item one"); UI label2 = UICreateLabel("item one"); UIStackAddTitled(stack, label1, "first", "First tab"); UIStackAddTitled(stack, label2, "second", "Second tab");
UI img = UICreateImage("path/to/image.png");
You can also load up image file and then reuse it's data for later usage. This way you can reuse the image much faster and use less resources.
GdkPixbuf* imgData = UILoadImageData("path/to/image.png");
UI img = UILoadImage(imgData);
UIAppend(window, img);
UISetImageLoaded(img, imgData);
UISetImage(img, "some_file.png");
UI grid = UICreateGrid(true); // Homogeneous?
UIAppend(window, grid);
// You can set spacing of the grid
UISetGridColumnSpacing(grid, 15);
UISetGridRowSpacing(grid, 10);
// Let's add an image to our grid
UIAttach(grid, img, 0, 0, 1, 1);
// Numerical values indicate x, y, width, height
UI entry = UICreateEntry("placeholder");
UIAppend(window, entry);
// Setting and getting values
UISetEntryValue(entry, "some value");
const char* value = UIGetEntryValue(entry);
// You can also quickly check the
// length in characters of the values
unsigned length = UIEntryLength(entry);
UI slider = UICreateSlider(1, 10, 1); // min, max, step
UIAppend(window, slider);
// Setting and getting values
UISetSliderValue(entry, 7);
double value = UIGetSliderValue(entry);
UI scroll = UICreateScrollView(false, true); // scrollx, scrolly
UIAppend(window, scroll);
Scroll view is a widget that can take up to one element at a time. It is recommended to use a box or grid in order to store all the elements in the view.
void onclick() {
UIPrint("Clicked!");
}
UI image = UICreateImage("image.png");
UI eventBox = UICreateEventBox(image);
UIEvent(eventBox, "button-press-event", onclick, NULL);
You can create an event box to wrap elements that do not support all events. This way you can handle all signals that pass through GtkWigdet or in other words... any UI element.
UI window = UICreateWindow("Title", options);
UIEvent(window, "destroyed", qtk_main_quit, NULL);
-
-
From file
UILoadCSS("path/to/style.css");
-
From string
UILoadCSSData( ".box {" "background: red;" "}" );
-
-
UISetID(widget, "container");
-
UIAddClass(widget, "btn"); bool has = UIHasClass(widget, "btn"); UIRemoveClass(widget, "btn");
-
UIError("Oops!"); UIWarning("Are you sure?"); UIPrint("Debug information");