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

Grid issues on Cocoa #435

Open mischnic opened 6 years ago

mischnic commented 6 years ago

There seem to be some bugs regarding uiGrid on macOS

Cocoa: bildschirmfoto 2018-11-01 um 17 28 28 GTK: bildschirmfoto 2018-11-01 um 17 28 22

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

int onClosing(uiWindow *w, void *data)
{
    uiQuit();
    return 1;
}

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

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

    w = uiNewWindow("Grid Test", 500, 400, 0);
    uiWindowSetMargined(w, 1);

    uiGrid *grid = uiNewGrid();
    uiGridSetPadded(grid, 1);
    uiWindowSetChild(w, uiControl(grid));

    uiEntry *name = uiNewEntry();
    uiEntry *surname = uiNewEntry();
    uiSlider *age = uiNewSlider(0, 100);
    uiMultilineEntry *data = uiNewMultilineEntry();
    uiMultilineEntrySetText(data, "This is a text.This is a text.\nThis is a text.\nThis is a text.This is a text.\nThis is a text.\n");

    uiGridAppend(grid, uiControl(uiNewLabel("name")),    0, 0, 2, 1, 0, uiAlignFill, 0, uiAlignStart);
    uiGridAppend(grid, uiControl(uiNewLabel("surname")), 0, 1, 2, 1, 0, uiAlignFill, 0, uiAlignStart);
    uiGridAppend(grid, uiControl(uiNewLabel("age")),     0, 2, 2, 1, 0, uiAlignFill, 0, uiAlignStart);

    uiGridAppend(grid, uiControl(name),     2, 0, 2, 1, 0, uiAlignFill, 0, uiAlignStart);
    uiGridAppend(grid, uiControl(surname),  2, 1, 2, 1, 0, uiAlignFill, 0, uiAlignStart);
    uiGridAppend(grid, uiControl(age),      2, 2, 2, 1, 0, uiAlignFill, 0, uiAlignStart);

    uiGridAppend(grid, uiControl(data),     4, 0, 1, 3, 1, uiAlignFill, 1, uiAlignFill);

    uiWindowOnClosing(w, onClosing, NULL);
    uiControlShow(uiControl(w));
    uiMain();
    return 0;
}

https://github.com/kusti8/proton-native/issues/55 https://github.com/parro-it/libui-node/issues/63

Grid does work on macOS; it's just insanely buggy because either Auto Layout is hard or my attempt at making a grid with it is poor (probably the latter), so it only works under specific circumstances... This is an active problem.

mischnic commented 6 years ago

Also, the parameters to uiGridAppend should be documented.

liufanghua2012 commented 4 years ago

Has this been solved?