Browse Source

split up parent/child layout flags into uiSetBox and uiSetLayout

pull/1/head
Leonard Ritter 10 years ago
parent
commit
15ec166709
2 changed files with 32 additions and 24 deletions
  1. +9
    -9
      example.cpp
  2. +23
    -15
      oui.h

+ 9
- 9
example.cpp View File

@@ -354,7 +354,7 @@ int panel() {
int column_append(int parent, int item) {
uiAppend(parent, item);
// fill parent horizontally, anchor to previous item vertically
uiAddLayout(item, UI_HFILL);
uiSetLayout(item, UI_HFILL);
// if not the first item, add a margin of 1
uiSetMargins(item, 0, 1, 0, 0);
return item;
@@ -362,26 +362,26 @@ int column_append(int parent, int item) {

int column() {
int item = uiItem();
uiSetLayout(item, UI_COLUMN);
uiSetBox(item, UI_COLUMN);
return item;
}

int vgroup_append(int parent, int item) {
uiAppend(parent, item);
// fill parent horizontally, anchor to previous item vertically
uiAddLayout(item, UI_HFILL);
uiSetLayout(item, UI_HFILL);
return item;
}

int vgroup() {
int item = uiItem();
uiSetLayout(item, UI_COLUMN);
uiSetBox(item, UI_COLUMN);
return item;
}

int hgroup_append(int parent, int item) {
uiAppend(parent, item);
uiAddLayout(item, UI_HFILL);
uiSetLayout(item, UI_HFILL);
return item;
}

@@ -392,19 +392,19 @@ int hgroup_append_fixed(int parent, int item) {

int hgroup() {
int item = uiItem();
uiSetLayout(item, UI_ROW);
uiSetBox(item, UI_ROW);
return item;
}

int row_append(int parent, int item) {
uiAppend(parent, item);
uiAddLayout(item, UI_HFILL);
uiSetLayout(item, UI_HFILL);
return item;
}

int row() {
int item = uiItem();
uiSetLayout(item, UI_ROW);
uiSetBox(item, UI_ROW);
return item;
}

@@ -658,7 +658,7 @@ void draw(NVGcontext *vg, float w, float h) {
int col = column();
uiAppend(root, col);
uiSetMargins(col, 10, 10, 10, 10);
uiAddLayout(col, UI_TOP|UI_HFILL);
uiSetLayout(col, UI_TOP|UI_HFILL);
column_append(col, button(BND_ICONID(6,3), "Item 1", demohandler));


+ 23
- 15
oui.h View File

@@ -228,10 +228,8 @@ typedef enum UIitemState {
UI_FROZEN = 3,
} UIitemState;

// layout flags
typedef enum UIlayoutFlags {
// container flags:

// container flags to pass to uiSetBox()
typedef enum UIboxFlags {
// flex-direction (bit 0+1)

// left to right
@@ -254,21 +252,22 @@ typedef enum UIlayoutFlags {
UI_WRAP = 0x004,

// justify-content (start, end, center, space-between)
// can be implemented by putting flex container in a layout container,
// can be implemented by putting a flex container in a layout container,
// then using UI_LEFT, UI_RIGHT, UI_HFILL, UI_HCENTER, etc.

// align-items
// can be implemented by putting flex container in a layout container,
// can be implemented by putting a flex container in a layout container,
// then using UI_TOP, UI_DOWN, UI_VFILL, UI_VCENTER, etc.
// FILL is equivalent to stretch/grow

// align-content (start, end, center, stretch)
// can be implemented by putting flex container in a layout container,
// can be implemented by putting a flex container in a layout container,
// then using UI_TOP, UI_DOWN, UI_VFILL, UI_VCENTER, etc.
// FILL is equivalent to stretch; space-between is not supported.
} UIboxFlags;

// child item flags:
// child layout flags to pass to uiSetLayout()
typedef enum UIlayoutFlags {
// attachments (bit 5-8)
// fully valid when parent uses UI_LAYOUT model
// partially valid when in UI_FLEX model
@@ -639,8 +638,10 @@ OUI_EXPORT short uiGetMarginDown(int item);

// extra item flags
enum {
// bit 0-8
UI_ITEM_LAYOUT_MASK = 0x0001FF,
// bit 0-2
UI_ITEM_BOX_MASK = 0x000007,
// bit 5-8
UI_ITEM_LAYOUT_MASK = 0x0001E0,
// bit 9-18
UI_ITEM_EVENT_MASK = 0x07FE00,
// item is frozen (bit 19)
@@ -1004,17 +1005,24 @@ int uiGetHeight(int item) {

void uiSetLayout(int item, int flags) {
UIitem *pitem = uiItemPtr(item);
assert((flags & UI_ITEM_LAYOUT_MASK) == flags);
pitem->flags &= ~UI_ITEM_LAYOUT_MASK;
pitem->flags |= flags & UI_ITEM_LAYOUT_MASK;
}

void uiAddLayout(int item, int flags) {
int uiGetLayout(int item) {
return uiItemPtr(item)->flags & UI_ITEM_LAYOUT_MASK;
}

void uiSetBox(int item, int flags) {
UIitem *pitem = uiItemPtr(item);
pitem->flags |= flags & UI_ITEM_LAYOUT_MASK;
assert((flags & UI_ITEM_BOX_MASK) == flags);
pitem->flags &= ~UI_ITEM_BOX_MASK;
pitem->flags |= flags & UI_ITEM_BOX_MASK;
}

int uiGetLayout(int item) {
return uiItemPtr(item)->flags & UI_ITEM_LAYOUT_MASK;
int uiGetBox(int item) {
return uiItemPtr(item)->flags & UI_ITEM_BOX_MASK;
}

void uiSetMargins(int item, short l, short t, short r, short b) {


Loading…
Cancel
Save