Skip to content

stricaud/gtcaca

Repository files navigation

GTcaca

Graphical Toolkit on top of libcaca.

It allows you to use widgets and have an amazing interface using code like this:

#include <gtcaca/main.h>
#include <gtcaca/window.h>

int main(int argc, char **argv)
{
  gtcaca_init(&argc, &argv);

  gtcaca_window_new("My first window", 1, 1, 50, 20);

  gtcaca_main();
  return 0;
}

Which will make the following:

Text List widget

This code:

#include <gtcaca/main.h>
#include <gtcaca/window.h>
#include <gtcaca/textlist.h>

int textlist_key_press(gtcaca_textlist_widget_t *widget, int key, void *userdata)
{
  switch(key) {
  case CACA_KEY_RETURN:
    caca_printf(gmo.cv, widget->x, widget->y + 20, "Value:%s", gtcaca_textlist_get_selected(widget));
    break;
  }
}

int main(int argc, char **argv)
{
  gtcaca_textlist_widget_t *textlist;
  
  gtcaca_init(&argc, &argv);

  gtcaca_window_new("coucou", 1, 1, 50, 20);

  textlist = gtcaca_textlist_new(2, 2);
  gtcaca_textlist_append(textlist, "myfirst");
  gtcaca_textlist_append(textlist, "mysecond");
  gtcaca_textlist_append(textlist, "mythird");

  gtcaca_textlist_key_cb_register(textlist, textlist_key_press);
  
  gtcaca_main();
  return 0;
}

Which will make this:

When the user pressed the RETURN key, we printed the value of the selection.

Widgets

Application

This is a special widget, describing your application to which you can attach the other widgets.

Text List

Choose-able list

Button

Button

Label

Label

Window

A Window.

Editor

A multi-line text-editing widget: caret/selection, undo/redo, scrolling, syntax colourization (VSCode language configs, TextMate .tmLanguage.json grammars via Oniguruma, and a built-in JSON mode), autocompletion, folding, annotations and Scintilla-style search/replace. See docs/editor.md. The cacamacs app (docs/cacamacs.md) is an Emacs-keybinding editor built on it, reusing installed VSCode extensions for language support.

Layout (vbox / hbox)

Widgets can be placed by hand (explicit x, y in every constructor) or arranged automatically with vertical/horizontal box layouts, à la Qt's QVBoxLayout / QHBoxLayout:

#include <gtcaca/box.h>

gtcaca_box_t *vb = gtcaca_vbox_new();
gtcaca_box_add(vb, GTCACA_WIDGET(label));
gtcaca_box_add(vb, GTCACA_WIDGET(entry));
gtcaca_box_add(vb, GTCACA_WIDGET(button));
gtcaca_box_apply_window(vb, win);   /* compute positions */
gtcaca_box_free(vb);

See docs/layout.md for the full guide and tests/simple_layout.c for a runnable demo.

License

This is released under public domain.

About

some widgets for libcaca

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors