window
tutorialsthe c abi

5. text

one label, and the whole file

text is one more control, a label. add this with the others, before gui_host_set_root

	// a line of text, it sits inside its bounds, left aligned and centred top to bottom
	gui_control_t* label = NULL;
	gui_label_create("hello", &label);
	gui_control_set_bounds(label, 40, 200, 400, 40);

	gui_control_add(root, label);

the font and the colour come from the theme, which you have not touched, so it takes the default. theme is where you change them

you should see hello under the shapes. that is the whole track, you can draw in a window of your own

the whole file

//
//	my first window
//
#include "abi/window_abi.h"

#include <stdio.h>

int main(void)
{
	// the dll says which abi it speaks, and it has to match the header we compiled against
	if (gui_abi_version() != GUI_ABI_VERSION)
	{
		printf("wrong dll, it speaks abi %d\n", gui_abi_version());
		return 1;
	}

	// what we want, built up one setter at a time, anything we dont set keeps its default
	gui_desc_t* desc = NULL;

	gui_desc_create(&desc);
	gui_desc_set_title(desc, "my window");
	gui_desc_set_size(desc, 640, 480);
	gui_desc_set_kind(desc, gui_kind_chromed);
	gui_desc_set_present(desc, gui_present_opaque);
	gui_desc_set_on_top(desc, 0);

	// the window itself, the desc is only read here so it goes straight after
	gui_host_t*	host	= NULL;
	int32_t		err		= gui_host_create(desc, &host);

	gui_desc_destroy(desc);

	if (err != gui_ok)
	{
		printf("no window, %s\n", gui_err_text(err));
		return 1;
	}

	// the root, the one control the window draws, a panel the colour of the background
	gui_control_t* root = NULL;
	gui_panel_create(0xFF202830, 0.0f, &root);

	// one orange box, 40 in from the top left, 120 wide and 80 tall
	gui_control_t* box = NULL;
	gui_panel_create(0xFFE06040, 0.0f, &box);
	gui_control_set_bounds(box, 40, 40, 120, 80);

	// the same box with rounded corners, 12 is how round
	gui_control_t* round = NULL;
	gui_panel_create(0xFF40A0E0, 12.0f, &round);
	gui_control_set_bounds(round, 180, 40, 120, 80);

	// a radius of half the size rounds a square all the way into a circle
	gui_control_t* dot = NULL;
	gui_panel_create(0xFF60C060, 40.0f, &dot);
	gui_control_set_bounds(dot, 320, 40, 80, 80);

	// and a panel 2 px tall is a line
	gui_control_t* line = NULL;
	gui_panel_create(0xFFFFFFFF, 0.0f, &line);
	gui_control_set_bounds(line, 40, 160, 500, 2);

	// a line of text, it sits inside its bounds, left aligned and centred top to bottom
	gui_control_t* label = NULL;
	gui_label_create("hello", &label);
	gui_control_set_bounds(label, 40, 200, 400, 40);

	// everything goes in the root, then the root goes in the window
	gui_control_add(root, box);
	gui_control_add(root, round);
	gui_control_add(root, dot);
	gui_control_add(root, line);
	gui_control_add(root, label);

	gui_host_set_root(host, root);

	// put it on screen, then sit in the loop til it closes
	gui_host_show(host, 1);
	gui_host_run(host);

	// frees everything we made, the window included
	gui_shutdown();
	return 0;
}

where next

you wantgo to
every export, groupedthe c abi
buttons, sliders and lists instead of panelscontrols
clicks and other things coming backevents

On this page