andlabs / libui

Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.
Other
10.74k stars 616 forks source link

One-header, like nuklear #391

Open DesWurstes opened 6 years ago

DesWurstes commented 6 years ago

Do you plan to have one file to be included, like nuklear.h? It'd be really useful.

mischnic commented 6 years ago

You only need to include ui.h:

#include <stdio.h>
#include <string.h>
#include "ui.h"

static void cb(uiEntry *e, void *data){
    printf("%s\n", uiEntryText(e));
}

int main(void)
{
    uiInitOptions o;
    const char *err;

    memset(&o, 0, sizeof (uiInitOptions));
    err = uiInit(&o);
    if (err != NULL) {
        fprintf(stderr, "error initializing ui: %s\n", err);
        uiFreeInitError(err);
        return 1;
    }

    uiWindow *mainwin = uiNewWindow("test", 400, 400, 1);
    uiWindowSetMargined(mainwin, 1);

    uiBox *box = uiNewVerticalBox();
    uiBoxSetPadded(box, 1);
    uiWindowSetChild(mainwin, uiControl(box));

    uiEntry *entry = uiNewEntry();
    uiBoxAppend(box, uiControl(entry), 0);
    uiEntryOnChanged(entry, cb, NULL);
    uiEntrySetText(entry, "asd");

    uiControlShow(uiControl(mainwin));

    uiMain();
    return 0;
}
andlabs commented 6 years ago

The implementation of libui also is not in the header; you must either provide a shared library at runtime or link in a static library at link time. Shoving it all into a header will be extremely complicated; likely requiring everything to be renamed with the ui and uipriv namespaces, and may result in multiple definition errors (I don't know how nuklear gets around this). It would be based on the static-link mode, though.

msink commented 6 years ago

BTW, I'm curious - why there are public headers ui_darwin.h/ui_unix.h/ui_windows.h ? When an user program need them?

andlabs commented 6 years ago

User programs won't need them yet (they may become useful late in libui's development for desktop integration), but people who want to write their own uiControl wrappers for existing controls will need them.