ltk

GUI toolkit for X11 (WIP)
git clone git://lumidify.org/ltk.git (fast, but not encrypted)
git clone https://lumidify.org/ltk.git (encrypted, but very slow)
git clone git://4kcetb7mo7hj6grozzybxtotsub5bempzo4lirzc3437amof2c2impyd.onion/ltk.git (over tor)
Log | Files | Refs | README | LICENSE

test.c (4901B)


      1 #include <stdio.h>
      2 
      3 #include <ltk/ltk.h>
      4 #include <ltk/label.h>
      5 #include <ltk/button.h>
      6 #include <ltk/image.h>
      7 #include <ltk/image_widget.h>
      8 #include <ltk/grid.h>
      9 #include <ltk/entry.h>
     10 #include <ltk/menu.h>
     11 #include <ltk/box.h>
     12 #include <ltk/checkbutton.h>
     13 #include <ltk/radiobutton.h>
     14 #include <ltk/combobox.h>
     15 
     16 int
     17 quit(ltk_widget *self, ltk_callback_arglist args, ltk_callback_arg data) {
     18 	(void)self;
     19 	(void)args;
     20 	(void)data;
     21 	ltk_mainloop_quit();
     22 	return 1;
     23 }
     24 
     25 int
     26 printstuff(ltk_widget *self, ltk_callback_arglist args, ltk_callback_arg data) {
     27 	(void)self;
     28 	(void)args;
     29 	printf("%d\n", LTK_CAST_ARG_INT(data));
     30 	return 1;
     31 }
     32 
     33 int
     34 printstate(ltk_widget *self, ltk_callback_arglist args, ltk_callback_arg data) {
     35 	(void)self;
     36 	(void)data;
     37 	int state = LTK_GET_ARG_INT(args, 0);
     38 	printf("%d\n", state);
     39 	return 0;
     40 }
     41 
     42 int
     43 main(int argc, char *argv[]) {
     44 	(void)argc;
     45 	(void)argv;
     46 	ltk_init();
     47 
     48 	ltk_window *window = ltk_window_create("Hi", 0, 0, 500, 500);
     49 	ltk_grid *grid = ltk_grid_create(window, 5, 2);
     50 	ltk_grid_set_column_weight(grid, 0, 1);
     51 	ltk_grid_set_column_weight(grid, 1, 1);
     52 	ltk_grid_set_row_weight(grid, 4, 1);
     53 	ltk_button *button = ltk_button_create(window, "I'm a button!");
     54 	ltk_button *button1 = ltk_button_create(window, "I'm also a button!");
     55 	ltk_label *label = ltk_label_create(window, "I'm a label!");
     56 	ltk_image *img = ltk_image_create_from_path("test.jpg");
     57 	if (!img) {
     58 		fprintf(stderr, "Unable to load image.\n");
     59 		return 1;
     60 	}
     61 	ltk_image_widget *iw = ltk_image_widget_create(window, img);
     62 	ltk_entry *entry = ltk_entry_create(window, "");
     63 	ltk_menu *menu = ltk_menu_create(window);
     64 	ltk_menuentry *e1 = ltk_menuentry_create(window, "Hi");
     65 	ltk_menuentry *e2 = ltk_menuentry_create(window, "I'm a submenu");
     66 	ltk_menu_add_entry(menu, e1);
     67 	ltk_menu_add_entry(menu, e2);
     68 	ltk_menu *submenu = ltk_submenu_create(window);
     69 	ltk_menuentry *e3 = ltk_menuentry_create(window, "Menu Entry 1");
     70 	ltk_menuentry *e4 = ltk_menuentry_create(window, "Quit");
     71 	ltk_menu_add_entry(submenu, e3);
     72 	ltk_menu_add_entry(submenu, e4);
     73 	ltk_menuentry_attach_submenu(e2, submenu);
     74 
     75 	ltk_box *box = ltk_box_create(window, LTK_VERTICAL);
     76 	ltk_button *btn1 = ltk_button_create(window, "Bla1");
     77 	ltk_button *btn2 = ltk_button_create(window, "Bla2");
     78 	ltk_button *btn3 = ltk_button_create(window, "Bla3");
     79 	ltk_button *btn4 = ltk_button_create(window, "Bla4");
     80 	ltk_button *btn5 = ltk_button_create(window, "Bla5");
     81 	ltk_box_add(box, LTK_CAST_WIDGET(btn1), LTK_STICKY_LEFT);
     82 	ltk_box_add(box, LTK_CAST_WIDGET(btn2), LTK_STICKY_LEFT);
     83 	ltk_box_add(box, LTK_CAST_WIDGET(btn3), LTK_STICKY_LEFT);
     84 	ltk_box_add(box, LTK_CAST_WIDGET(btn4), LTK_STICKY_LEFT);
     85 	ltk_box_add(box, LTK_CAST_WIDGET(btn5), LTK_STICKY_LEFT);
     86 
     87 	ltk_checkbutton *cbtn1 = ltk_checkbutton_create(window, "Checkbutton1", 0);
     88 	ltk_checkbutton *cbtn2 = ltk_checkbutton_create(window, "Checkbutton2", 1);
     89 	ltk_box_add(box, LTK_CAST_WIDGET(cbtn1), LTK_STICKY_LEFT);
     90 	ltk_box_add(box, LTK_CAST_WIDGET(cbtn2), LTK_STICKY_LEFT);
     91 
     92 	ltk_radiobutton *rbtn1 = ltk_radiobutton_create(window, "Radiobutton1", 0, NULL);
     93 	ltk_radiobutton *rbtn2 = ltk_radiobutton_create(window, "Radiobutton2", 1, rbtn1);
     94 	ltk_box_add(box, LTK_CAST_WIDGET(rbtn1), LTK_STICKY_LEFT);
     95 	ltk_box_add(box, LTK_CAST_WIDGET(rbtn2), LTK_STICKY_LEFT);
     96 
     97 	ltk_combobox *combo = ltk_combobox_create(window);
     98 	ltk_combobox_add_option(combo, "Option 1");
     99 	ltk_combobox_add_option(combo, "Option 2");
    100 	ltk_combobox_add_option(combo, "Option 3");
    101 	ltk_combobox_add_option(combo, "Option 4");
    102 
    103 	ltk_grid_add(grid, LTK_CAST_WIDGET(menu), 0, 0, 1, 1, LTK_STICKY_LEFT|LTK_STICKY_RIGHT);
    104 	ltk_grid_add(grid, LTK_CAST_WIDGET(combo), 0, 1, 1, 1, LTK_STICKY_LEFT);
    105 	ltk_grid_add(grid, LTK_CAST_WIDGET(button), 1, 0, 1, 1, LTK_STICKY_LEFT);
    106 	ltk_grid_add(grid, LTK_CAST_WIDGET(button1), 1, 1, 1, 1, LTK_STICKY_RIGHT);
    107 	ltk_grid_add(grid, LTK_CAST_WIDGET(label), 2, 0, 1, 1, LTK_STICKY_RIGHT);
    108 	ltk_grid_add(grid, LTK_CAST_WIDGET(iw), 2, 1, 1, 1, LTK_STICKY_LEFT|LTK_STICKY_RIGHT|LTK_STICKY_PRESERVE_ASPECT_RATIO);
    109 	ltk_grid_add(grid, LTK_CAST_WIDGET(entry), 3, 0, 1, 1, LTK_STICKY_LEFT|LTK_STICKY_RIGHT);
    110 	ltk_grid_add(grid, LTK_CAST_WIDGET(box), 4, 0, 1, 2, LTK_STICKY_LEFT|LTK_STICKY_RIGHT|LTK_STICKY_TOP|LTK_STICKY_BOTTOM);
    111 	ltk_window_set_root_widget(window, LTK_CAST_WIDGET(grid));
    112 	ltk_widget_register_signal_handler(LTK_CAST_WIDGET(button), LTK_BUTTON_SIGNAL_PRESSED, &quit, LTK_ARG_VOID);
    113 	ltk_widget_register_signal_handler(LTK_CAST_WIDGET(e4), LTK_MENUENTRY_SIGNAL_PRESSED, &quit, LTK_ARG_VOID);
    114 	ltk_widget_register_signal_handler(LTK_CAST_WIDGET(button1), LTK_BUTTON_SIGNAL_PRESSED, &printstuff, LTK_MAKE_ARG_INT(5));
    115 	ltk_widget_register_signal_handler(LTK_CAST_WIDGET(window), LTK_WINDOW_SIGNAL_CLOSE, &quit, LTK_ARG_VOID);
    116 	ltk_widget_register_signal_handler(LTK_CAST_WIDGET(button1), LTK_WIDGET_SIGNAL_CHANGE_STATE, &printstate, LTK_ARG_VOID);
    117 
    118 	ltk_mainloop();
    119 	return 0;
    120 }