add table widget
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
This commit is contained in:
parent
0628250631
commit
32266c7656
11 changed files with 336 additions and 95 deletions
|
|
@ -6,16 +6,14 @@
|
||||||
#define Padding 20
|
#define Padding 20
|
||||||
#define PaddingContent 2
|
#define PaddingContent 2
|
||||||
|
|
||||||
MwWidget window, menu, box;
|
MwWidget window, menu, table;
|
||||||
MwWidget boxes[32];
|
|
||||||
int n = 0, row = -1;
|
|
||||||
MwMenu e;
|
MwMenu e;
|
||||||
|
|
||||||
static void MWAPI resize(MwWidget handle, void* user, void* call) {
|
static void MWAPI resize(MwWidget handle, void* user, void* call) {
|
||||||
int w = MwGetInteger(window, MwNwidth);
|
int w = MwGetInteger(window, MwNwidth);
|
||||||
int h = MwGetInteger(window, MwNheight);
|
int h = MwGetInteger(window, MwNheight);
|
||||||
|
|
||||||
MwVaApply(box,
|
MwVaApply(table,
|
||||||
MwNx, Padding,
|
MwNx, Padding,
|
||||||
MwNy, MwGetInteger(menu, MwNheight) + Padding,
|
MwNy, MwGetInteger(menu, MwNheight) + Padding,
|
||||||
MwNwidth, w - Padding * 2,
|
MwNwidth, w - Padding * 2,
|
||||||
|
|
@ -23,32 +21,6 @@ static void MWAPI resize(MwWidget handle, void* user, void* call) {
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void newrow(void) {
|
|
||||||
if(row >= 0) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for(i = n; i < Columns; i++) MwCreateWidget(MwFrameClass, "frame", boxes[row], 0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
boxes[++row] = MwVaCreateWidget(MwBoxClass, "box", box, 0, 0, 0, 0,
|
|
||||||
MwNwaitLayout, 1,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
n = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void add(MwWidget w) {
|
|
||||||
int r = MwGetInteger(w, MwNratio);
|
|
||||||
|
|
||||||
if(r == MwDEFAULT) r = 1;
|
|
||||||
|
|
||||||
n += r;
|
|
||||||
|
|
||||||
if(n == Columns) {
|
|
||||||
newrow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void MWAPI resize_content(MwWidget handle, void* user, void* call) {
|
static void MWAPI resize_content(MwWidget handle, void* user, void* call) {
|
||||||
MwWidget* ws = MwGetChildren(handle);
|
MwWidget* ws = MwGetChildren(handle);
|
||||||
if(ws != NULL) {
|
if(ws != NULL) {
|
||||||
|
|
@ -97,14 +69,14 @@ static void MWAPI resize_frame(MwWidget handle, void* user, void* call) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static MwWidget frame(const char* name, int width, int height, MwClass cl, ...) {
|
static MwWidget frame(const char* name, int width, int height, MwClass cl, ...) {
|
||||||
MwWidget f = MwVaCreateWidget(MwFrameClass, "frame", boxes[row], 0, 0, 0, 0,
|
MwWidget f = MwVaCreateWidget(MwFrameClass, "frame", table, 0, 0, 0, 0,
|
||||||
MwNhasBorder, 1,
|
MwNhasBorder, 1,
|
||||||
MwNinverted, 1,
|
MwNinverted, 1,
|
||||||
NULL);
|
NULL);
|
||||||
MwWidget box = MwVaCreateWidget(MwBoxClass, "box", f, 0, 0, 0, 0,
|
MwWidget table = MwVaCreateWidget(MwBoxClass, "table", f, 0, 0, 0, 0,
|
||||||
MwNorientation, MwVERTICAL,
|
MwNorientation, MwVERTICAL,
|
||||||
NULL);
|
NULL);
|
||||||
MwWidget label = MwVaCreateWidget(MwLabelClass, "label", box, 0, 0, 0, 0,
|
MwWidget label = MwVaCreateWidget(MwLabelClass, "label", table, 0, 0, 0, 0,
|
||||||
MwNtext, name,
|
MwNtext, name,
|
||||||
MwNalignment, MwALIGNMENT_BEGINNING,
|
MwNalignment, MwALIGNMENT_BEGINNING,
|
||||||
MwNfixedSize, 20,
|
MwNfixedSize, 20,
|
||||||
|
|
@ -112,7 +84,7 @@ static MwWidget frame(const char* name, int width, int height, MwClass cl, ...)
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
if(cl != NULL) {
|
if(cl != NULL) {
|
||||||
MwWidget frame = MwCreateWidget(MwFrameClass, "frame", box, 0, 0, 0, 0);
|
MwWidget frame = MwCreateWidget(MwFrameClass, "frame", table, 0, 0, 0, 0);
|
||||||
MwWidget w;
|
MwWidget w;
|
||||||
|
|
||||||
va_start(va, cl);
|
va_start(va, cl);
|
||||||
|
|
@ -128,7 +100,8 @@ static MwWidget frame(const char* name, int width, int height, MwClass cl, ...)
|
||||||
|
|
||||||
MwVaApply(f,
|
MwVaApply(f,
|
||||||
"VhandledWidget", w,
|
"VhandledWidget", w,
|
||||||
MwNratio, MwGetInteger(w, MwNratio),
|
MwNcolumnSpan, MwGetInteger(w, MwNcolumnSpan),
|
||||||
|
MwNrowSpan, MwGetInteger(w, MwNrowSpan),
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,35 +197,32 @@ int main() {
|
||||||
|
|
||||||
MwAddUserHandler(menu, MwNmenuHandler, menu_handler, NULL);
|
MwAddUserHandler(menu, MwNmenuHandler, menu_handler, NULL);
|
||||||
|
|
||||||
box = MwVaCreateWidget(MwBoxClass, "box", window, 0, 0, 0, 0,
|
table = MwVaCreateWidget(MwTableClass, "table", window, 0, 0, 0, 0,
|
||||||
MwNorientation, MwVERTICAL,
|
|
||||||
MwNwaitLayout, 1,
|
MwNwaitLayout, 1,
|
||||||
|
MwNcolumns, 5,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
newrow();
|
|
||||||
|
|
||||||
f = frame("Button", -PaddingContent, -PaddingContent, MwButtonClass,
|
f = frame("Button", -PaddingContent, -PaddingContent, MwButtonClass,
|
||||||
MwNtext, "Press me",
|
MwNtext, "Press me",
|
||||||
NULL);
|
NULL);
|
||||||
add(f);
|
|
||||||
|
|
||||||
add(MwVaCreateWidget(MwLabelClass, "label", boxes[row], 0, 0, 0, 0,
|
MwVaCreateWidget(MwLabelClass, "label", table, 0, 0, 0, 0,
|
||||||
MwNbold, 1,
|
MwNbold, 1,
|
||||||
MwNtext, "The Periodic Table of Milsko Widgets",
|
MwNtext, "The Periodic Table of Milsko Widgets",
|
||||||
MwNratio, Columns - 2,
|
MwNcolumnSpan, Columns - 2,
|
||||||
NULL));
|
NULL);
|
||||||
|
|
||||||
for(i = 0; i < 2; i++) {
|
for(i = 0; i < 2; i++) {
|
||||||
f = frame(i == 0 ? "CheckBox" : "RadioBox", -PaddingContent, -PaddingContent, MwBoxClass,
|
f = frame(i == 0 ? "CheckBox" : "RadioBox", -PaddingContent, -PaddingContent, MwBoxClass,
|
||||||
MwNmargin, PaddingContent,
|
MwNmargin, PaddingContent,
|
||||||
NULL);
|
NULL);
|
||||||
w = child(f);
|
w = child(f);
|
||||||
b = MwVaCreateWidget(MwBoxClass, "box1", w, 0, 0, 0, 0,
|
b = MwVaCreateWidget(MwBoxClass, "table1", w, 0, 0, 0, 0,
|
||||||
MwNorientation, MwVERTICAL,
|
MwNorientation, MwVERTICAL,
|
||||||
MwNfixedSize, 16,
|
MwNfixedSize, 16,
|
||||||
NULL);
|
NULL);
|
||||||
for(j = 0; j < 5; j++) MwCreateWidget(i == 0 ? MwCheckBoxClass : MwRadioBoxClass, i == 0 ? "cb" : "rb", b, 0, 0, 0, 0);
|
for(j = 0; j < 5; j++) MwCreateWidget(i == 0 ? MwCheckBoxClass : MwRadioBoxClass, i == 0 ? "cb" : "rb", b, 0, 0, 0, 0);
|
||||||
b = MwVaCreateWidget(MwBoxClass, "box1", w, 0, 0, 0, 0,
|
b = MwVaCreateWidget(MwBoxClass, "table1", w, 0, 0, 0, 0,
|
||||||
MwNorientation, MwVERTICAL,
|
MwNorientation, MwVERTICAL,
|
||||||
NULL);
|
NULL);
|
||||||
for(j = 0; j < 5; j++) {
|
for(j = 0; j < 5; j++) {
|
||||||
|
|
@ -263,32 +233,25 @@ int main() {
|
||||||
MwNalignment, MwALIGNMENT_BEGINNING,
|
MwNalignment, MwALIGNMENT_BEGINNING,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
add(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
f = frame("Calendar", -PaddingContent, -PaddingContent, MwCalendarClass,
|
f = frame("Calendar", -PaddingContent, -PaddingContent, MwCalendarClass,
|
||||||
MwNscale, 1,
|
MwNscale, 1,
|
||||||
NULL);
|
NULL);
|
||||||
add(f);
|
|
||||||
|
|
||||||
f = frame("ComboBox", -PaddingContent, 24, MwComboBoxClass, NULL);
|
f = frame("ComboBox", -PaddingContent, 24, MwComboBoxClass, NULL);
|
||||||
w = child(f);
|
w = child(f);
|
||||||
MwComboBoxAdd(w, -1, "Hello!");
|
MwComboBoxAdd(w, -1, "Hello!");
|
||||||
add(f);
|
|
||||||
|
|
||||||
f = frame("Entry", -PaddingContent, 24, MwEntryClass, NULL);
|
f = frame("Entry", -PaddingContent, 24, MwEntryClass, NULL);
|
||||||
add(f);
|
|
||||||
|
|
||||||
f = frame("Image", -PaddingContent, -PaddingContent, MwImageClass,
|
f = frame("Image", -PaddingContent, -PaddingContent, MwImageClass,
|
||||||
MwNpixmap, px,
|
MwNpixmap, px,
|
||||||
NULL);
|
NULL);
|
||||||
w = child(f);
|
|
||||||
add(f);
|
|
||||||
|
|
||||||
f = frame("Label", -PaddingContent, -PaddingContent, MwLabelClass,
|
f = frame("Label", -PaddingContent, -PaddingContent, MwLabelClass,
|
||||||
MwNtext, "Epic text\nNewline can be used too!",
|
MwNtext, "Epic text\nNewline can be used too!",
|
||||||
NULL);
|
NULL);
|
||||||
add(f);
|
|
||||||
|
|
||||||
f = frame("ListBox", -PaddingContent, -PaddingContent, MwListBoxClass,
|
f = frame("ListBox", -PaddingContent, -PaddingContent, MwListBoxClass,
|
||||||
MwNhasHeading, 1,
|
MwNhasHeading, 1,
|
||||||
|
|
@ -296,26 +259,21 @@ int main() {
|
||||||
w = child(f);
|
w = child(f);
|
||||||
index = MwListBoxSet(w, -1, 0, "Epic title...");
|
index = MwListBoxSet(w, -1, 0, "Epic title...");
|
||||||
index = MwListBoxSet(w, -1, 0, "Hello");
|
index = MwListBoxSet(w, -1, 0, "Hello");
|
||||||
add(f);
|
|
||||||
|
|
||||||
f = frame("NumberEntry", -PaddingContent, 24, MwNumberEntryClass, NULL);
|
f = frame("NumberEntry", -PaddingContent, 24, MwNumberEntryClass, NULL);
|
||||||
add(f);
|
|
||||||
|
|
||||||
f = frame("ProgressBar", -PaddingContent, 24, MwProgressBarClass,
|
f = frame("ProgressBar", -PaddingContent, 24, MwProgressBarClass,
|
||||||
MwNvalue, 25,
|
MwNvalue, 25,
|
||||||
NULL);
|
NULL);
|
||||||
add(f);
|
|
||||||
|
|
||||||
f = frame("ScrollBar", -PaddingContent, 16, MwScrollBarClass,
|
f = frame("ScrollBar", -PaddingContent, 16, MwScrollBarClass,
|
||||||
MwNorientation, MwHORIZONTAL,
|
MwNorientation, MwHORIZONTAL,
|
||||||
NULL);
|
NULL);
|
||||||
add(f);
|
|
||||||
|
|
||||||
f = frame("Separator", -PaddingContent, -PaddingContent, MwSeparatorClass, NULL);
|
f = frame("Separator", -PaddingContent, -PaddingContent, MwSeparatorClass, NULL);
|
||||||
add(f);
|
|
||||||
|
|
||||||
f = frame("SubWindow", -PaddingContent, -PaddingContent, MwViewportClass,
|
f = frame("SubWindow", -PaddingContent, -PaddingContent, MwViewportClass,
|
||||||
MwNratio, 2,
|
MwNcolumnSpan, 2,
|
||||||
NULL);
|
NULL);
|
||||||
w = child(f);
|
w = child(f);
|
||||||
MwViewportSetSize(w, 512, 512);
|
MwViewportSetSize(w, 512, 512);
|
||||||
|
|
@ -325,23 +283,20 @@ int main() {
|
||||||
MwVaCreateWidget(MwSubWindowClass, "swnd", MwViewportGetViewport(w), 64, 64, 256, 128,
|
MwVaCreateWidget(MwSubWindowClass, "swnd", MwViewportGetViewport(w), 64, 64, 256, 128,
|
||||||
MwNtitle, "Sub window 2",
|
MwNtitle, "Sub window 2",
|
||||||
NULL);
|
NULL);
|
||||||
add(f);
|
|
||||||
|
|
||||||
f = frame("Tab", -PaddingContent, -PaddingContent, MwTabClass,
|
f = frame("Tab", -PaddingContent, -PaddingContent, MwTabClass,
|
||||||
MwNratio, 2,
|
MwNcolumnSpan, 2,
|
||||||
NULL);
|
NULL);
|
||||||
w = child(f);
|
w = child(f);
|
||||||
MwSetText(MwTabAdd(w, "ABC"), MwNbackground, "#f00");
|
MwSetText(MwTabAdd(w, "ABC"), MwNbackground, "#f00");
|
||||||
MwSetText(MwTabAdd(w, "DEF"), MwNbackground, "#0f0");
|
MwSetText(MwTabAdd(w, "DEF"), MwNbackground, "#0f0");
|
||||||
MwSetText(MwTabAdd(w, "GHI"), MwNbackground, "#00f");
|
MwSetText(MwTabAdd(w, "GHI"), MwNbackground, "#00f");
|
||||||
add(f);
|
|
||||||
|
|
||||||
f = frame("TreeView", -PaddingContent, -PaddingContent, MwTreeViewClass, NULL);
|
f = frame("TreeView", -PaddingContent, -PaddingContent, MwTreeViewClass, NULL);
|
||||||
w = child(f);
|
w = child(f);
|
||||||
v = MwTreeViewAdd(w, NULL, NULL, "abc");
|
v = MwTreeViewAdd(w, NULL, NULL, "abc");
|
||||||
v = MwTreeViewAdd(w, v, NULL, "def");
|
v = MwTreeViewAdd(w, v, NULL, "def");
|
||||||
v = MwTreeViewAdd(w, v, NULL, "ghi");
|
v = MwTreeViewAdd(w, v, NULL, "ghi");
|
||||||
add(f);
|
|
||||||
|
|
||||||
f = frame("Viewport", -PaddingContent, -PaddingContent, MwViewportClass, NULL);
|
f = frame("Viewport", -PaddingContent, -PaddingContent, MwViewportClass, NULL);
|
||||||
w = child(f);
|
w = child(f);
|
||||||
|
|
@ -349,23 +304,14 @@ int main() {
|
||||||
MwVaCreateWidget(MwButtonClass, "btn", MwViewportGetViewport(w), 64, 64, 128, 128,
|
MwVaCreateWidget(MwButtonClass, "btn", MwViewportGetViewport(w), 64, 64, 128, 128,
|
||||||
MwNtext, "Thing",
|
MwNtext, "Thing",
|
||||||
NULL);
|
NULL);
|
||||||
add(f);
|
|
||||||
|
|
||||||
if(n != 0) newrow();
|
|
||||||
if(n == 0) MwDestroyWidget(boxes[row]);
|
|
||||||
|
|
||||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||||
|
|
||||||
resize(window, NULL, NULL);
|
resize(window, NULL, NULL);
|
||||||
|
|
||||||
MwVaApply(box,
|
MwVaApply(table,
|
||||||
MwNwaitLayout, 0,
|
MwNwaitLayout, 0,
|
||||||
NULL);
|
NULL);
|
||||||
for(i = 0; i < row; i++) {
|
|
||||||
MwVaApply(boxes[i],
|
|
||||||
MwNwaitLayout, 0,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
MwLoop(window);
|
MwLoop(window);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -383,6 +383,13 @@ MWDECL void* MWAPI MwGetUser(MwWidget handle);
|
||||||
*/
|
*/
|
||||||
MWDECL void MWAPI MwFreeWidget(MwWidget handle);
|
MWDECL void MWAPI MwFreeWidget(MwWidget handle);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Gets the frame of the widget
|
||||||
|
* @param handle Widget
|
||||||
|
* @param rect Frame
|
||||||
|
*/
|
||||||
|
MWDECL void MWAPI MwGetFrame(MwWidget handle, MwRect* rect);
|
||||||
|
|
||||||
#ifdef _MILSKO
|
#ifdef _MILSKO
|
||||||
MWDECL void MwForceRender_Internal(MwWidget handle);
|
MWDECL void MwForceRender_Internal(MwWidget handle);
|
||||||
MWDECL void MwForceRender2_Internal(MwWidget handle, void* ptr);
|
MWDECL void MwForceRender2_Internal(MwWidget handle, void* ptr);
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@
|
||||||
#include <Mw/Widget/SubMenu.h>
|
#include <Mw/Widget/SubMenu.h>
|
||||||
#include <Mw/Widget/SubWindow.h>
|
#include <Mw/Widget/SubWindow.h>
|
||||||
#include <Mw/Widget/Tab.h>
|
#include <Mw/Widget/Tab.h>
|
||||||
|
#include <Mw/Widget/Table.h>
|
||||||
#include <Mw/Widget/TreeView.h>
|
#include <Mw/Widget/TreeView.h>
|
||||||
#include <Mw/Widget/Viewport.h>
|
#include <Mw/Widget/Viewport.h>
|
||||||
#include <Mw/Widget/Window.h>
|
#include <Mw/Widget/Window.h>
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,9 @@
|
||||||
#define MwNday "Iday"
|
#define MwNday "Iday"
|
||||||
#define MwNwaitLayout "IwaitLayout"
|
#define MwNwaitLayout "IwaitLayout"
|
||||||
#define MwNscale "Iscale"
|
#define MwNscale "Iscale"
|
||||||
|
#define MwNcolumns "Icolumns"
|
||||||
|
#define MwNcolumnSpan "IcolumnSpan"
|
||||||
|
#define MwNrowSpan "IrowSpan"
|
||||||
|
|
||||||
#define MwNtitle "Stitle"
|
#define MwNtitle "Stitle"
|
||||||
#define MwNtext "Stext"
|
#define MwNtext "Stext"
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ typedef struct _MwDirectoryEntry MwDirectoryEntry;
|
||||||
typedef struct _MwBox* MwBox;
|
typedef struct _MwBox* MwBox;
|
||||||
typedef struct _MwSubWindow* MwSubWindow;
|
typedef struct _MwSubWindow* MwSubWindow;
|
||||||
typedef struct _MwTab* MwTab;
|
typedef struct _MwTab* MwTab;
|
||||||
|
typedef struct _MwTable* MwTable;
|
||||||
typedef struct _MwMouse MwMouse;
|
typedef struct _MwMouse MwMouse;
|
||||||
#ifdef _MILSKO
|
#ifdef _MILSKO
|
||||||
typedef struct _MwWidget* MwWidget;
|
typedef struct _MwWidget* MwWidget;
|
||||||
|
|
@ -39,6 +40,7 @@ typedef void (*MwHandler)(MwWidget handle);
|
||||||
typedef int (*MwHandlerWithStatus)(MwWidget handle);
|
typedef int (*MwHandlerWithStatus)(MwWidget handle);
|
||||||
typedef void (*MwHandlerProps)(MwWidget handle, char** key);
|
typedef void (*MwHandlerProps)(MwWidget handle, char** key);
|
||||||
typedef void (*MwHandlerProp)(MwWidget handle, const char* key);
|
typedef void (*MwHandlerProp)(MwWidget handle, const char* key);
|
||||||
|
typedef void (*MwHandlerChildrenUpdate)(MwWidget handle, MwWidget child, int new);
|
||||||
typedef void (*MwHandlerChildrenProp)(MwWidget handle, MwWidget child, const char* key);
|
typedef void (*MwHandlerChildrenProp)(MwWidget handle, MwWidget child, const char* key);
|
||||||
typedef void (*MwHandlerKey)(MwWidget handle, int key);
|
typedef void (*MwHandlerKey)(MwWidget handle, int key);
|
||||||
typedef void (*MwHandlerMouse)(MwWidget handle, void* ptr);
|
typedef void (*MwHandlerMouse)(MwWidget handle, void* ptr);
|
||||||
|
|
@ -212,6 +214,11 @@ struct _MwBox {
|
||||||
int layout;
|
int layout;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _MwTable {
|
||||||
|
int layout;
|
||||||
|
MwWidget* widgets;
|
||||||
|
};
|
||||||
|
|
||||||
struct _MwSubWindow {
|
struct _MwSubWindow {
|
||||||
MwWidget frame;
|
MwWidget frame;
|
||||||
MwWidget minimize;
|
MwWidget minimize;
|
||||||
|
|
@ -251,7 +258,7 @@ struct _MwClass {
|
||||||
MwHandlerExecute execute;
|
MwHandlerExecute execute;
|
||||||
MwHandler tick;
|
MwHandler tick;
|
||||||
MwHandler resize;
|
MwHandler resize;
|
||||||
MwHandler children_update;
|
MwHandlerChildrenUpdate children_update;
|
||||||
MwHandlerChildrenProp children_prop_change;
|
MwHandlerChildrenProp children_prop_change;
|
||||||
MwHandlerClipboardReceived clipboard;
|
MwHandlerClipboardReceived clipboard;
|
||||||
MwHandlerProps props_change;
|
MwHandlerProps props_change;
|
||||||
|
|
|
||||||
24
include/Mw/Widget/Table.h
Normal file
24
include/Mw/Widget/Table.h
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*!
|
||||||
|
* @file Mw/Widget/Table.h
|
||||||
|
* @brief Table widget
|
||||||
|
*/
|
||||||
|
#ifndef __MW_WIDGET_TABLE_H__
|
||||||
|
#define __MW_WIDGET_TABLE_H__
|
||||||
|
|
||||||
|
#include <Mw/MachDep.h>
|
||||||
|
#include <Mw/TypeDefs.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Table widget class
|
||||||
|
*/
|
||||||
|
MWDECL MwClass MwTableClass;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
13
milsko.xml
13
milsko.xml
|
|
@ -103,6 +103,9 @@
|
||||||
<integer name="day" />
|
<integer name="day" />
|
||||||
<integer name="waitLayout" />
|
<integer name="waitLayout" />
|
||||||
<integer name="scale" />
|
<integer name="scale" />
|
||||||
|
<integer name="columns" />
|
||||||
|
<integer name="columnSpan" column="yes" />
|
||||||
|
<integer name="rowSpan" column="yes" />
|
||||||
|
|
||||||
<!-- waitMS is a special property, only applies to toplevel widget -->
|
<!-- waitMS is a special property, only applies to toplevel widget -->
|
||||||
<integer name="waitMS" common="yes" />
|
<integer name="waitMS" common="yes" />
|
||||||
|
|
@ -924,6 +927,16 @@
|
||||||
</function>
|
</function>
|
||||||
</functions>
|
</functions>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget name="Table">
|
||||||
|
<properties>
|
||||||
|
<property name="columns" />
|
||||||
|
<property name="margin" />
|
||||||
|
<property name="padding" />
|
||||||
|
<property name="hasBorder" />
|
||||||
|
<property name="inverted" />
|
||||||
|
<property name="waitLayout" />
|
||||||
|
</properties>
|
||||||
|
</widget>
|
||||||
<widget name="Tab">
|
<widget name="Tab">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="value" />
|
<property name="value" />
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,7 @@ new_object("src/widget/separator.c");
|
||||||
new_object("src/widget/submenu.c");
|
new_object("src/widget/submenu.c");
|
||||||
new_object("src/widget/subwindow.c");
|
new_object("src/widget/subwindow.c");
|
||||||
new_object("src/widget/tab.c");
|
new_object("src/widget/tab.c");
|
||||||
|
new_object("src/widget/table.c");
|
||||||
new_object("src/widget/treeview.c");
|
new_object("src/widget/treeview.c");
|
||||||
new_object("src/widget/viewport.c");
|
new_object("src/widget/viewport.c");
|
||||||
new_object("src/widget/window.c");
|
new_object("src/widget/window.c");
|
||||||
|
|
|
||||||
15
src/core.c
15
src/core.c
|
|
@ -286,7 +286,7 @@ static MwWidget MwCreateWidget_Internal(MwClass widget_class, const char* name,
|
||||||
h->root_boldmonofont = NULL;
|
h->root_boldmonofont = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(h->parent != NULL) MwDispatch(h->parent, children_update);
|
if(h->parent != NULL) MwDispatch4(h->parent, children_update, h, 1);
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
@ -415,7 +415,7 @@ void MwDestroyWidget(MwWidget handle) {
|
||||||
arrput(handle->parent->destroy_queue, handle);
|
arrput(handle->parent->destroy_queue, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
MwDispatch(handle->parent, children_update);
|
MwDispatch4(handle->parent, children_update, handle, 0);
|
||||||
}
|
}
|
||||||
destroy_children(handle);
|
destroy_children(handle);
|
||||||
handle->destroyed = 1;
|
handle->destroyed = 1;
|
||||||
|
|
@ -1042,14 +1042,14 @@ void MwReparent(MwWidget handle, MwWidget new_parent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MwDispatch(handle->parent, children_update);
|
MwDispatch4(handle->parent, children_update, handle, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
handle->parent = new_parent;
|
handle->parent = new_parent;
|
||||||
if(new_parent != NULL) {
|
if(new_parent != NULL) {
|
||||||
arrput(new_parent->children, handle);
|
arrput(new_parent->children, handle);
|
||||||
|
|
||||||
MwDispatch(handle->parent, children_update);
|
MwDispatch4(handle->parent, children_update, handle, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(new_parent == NULL) {
|
if(new_parent == NULL) {
|
||||||
|
|
@ -1109,4 +1109,11 @@ void* MwGetUser(MwWidget handle) {
|
||||||
return handle->user;
|
return handle->user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MwGetFrame(MwWidget handle, MwRect* rect) {
|
||||||
|
rect->x = MwGetInteger(handle, MwNx);
|
||||||
|
rect->y = MwGetInteger(handle, MwNy);
|
||||||
|
rect->width = MwGetInteger(handle, MwNwidth);
|
||||||
|
rect->height = MwGetInteger(handle, MwNheight);
|
||||||
|
}
|
||||||
|
|
||||||
const char* MwVersionString = MwVERSION;
|
const char* MwVersionString = MwVERSION;
|
||||||
|
|
|
||||||
|
|
@ -95,18 +95,7 @@ static void draw(MwWidget handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prop_change(MwWidget handle, const char* key) {
|
static void prop_change(MwWidget handle, const char* key) {
|
||||||
if(strcmp(key, MwNorientation) == 0) {
|
if(strcmp(key, MwNorientation) == 0 || strcmp(key, MwNpadding) == 0 || strcmp(key, MwNmargin) == 0) {
|
||||||
MwBox b = handle->internal;
|
|
||||||
b->layout = 1;
|
|
||||||
|
|
||||||
MwForceRender(handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void children_prop_change(MwWidget handle, MwWidget child, const char* key) {
|
|
||||||
(void)child;
|
|
||||||
|
|
||||||
if(strcmp(key, MwNratio) == 0 || strcmp(key, MwNfixedSize) == 0) {
|
|
||||||
MwBox b = handle->internal;
|
MwBox b = handle->internal;
|
||||||
b->layout = 1;
|
b->layout = 1;
|
||||||
|
|
||||||
|
|
@ -131,12 +120,27 @@ static void resize(MwWidget handle) {
|
||||||
MwForceRender(handle);
|
MwForceRender(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void children_update(MwWidget handle) {
|
static void children_update(MwWidget handle, MwWidget child, int new) {
|
||||||
|
MwBox b = handle->internal;
|
||||||
|
|
||||||
|
(void)child;
|
||||||
|
(void)new;
|
||||||
|
|
||||||
|
b->layout = 1;
|
||||||
|
|
||||||
|
MwForceRender(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void children_prop_change(MwWidget handle, MwWidget child, const char* key) {
|
||||||
|
(void)child;
|
||||||
|
|
||||||
|
if(strcmp(key, MwNratio) == 0 || strcmp(key, MwNfixedSize) == 0) {
|
||||||
MwBox b = handle->internal;
|
MwBox b = handle->internal;
|
||||||
b->layout = 1;
|
b->layout = 1;
|
||||||
|
|
||||||
MwForceRender(handle);
|
MwForceRender(handle);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MwClassRec MwBoxClassRec = {
|
MwClassRec MwBoxClassRec = {
|
||||||
wcreate, /* create */
|
wcreate, /* create */
|
||||||
|
|
|
||||||
228
src/widget/table.c
Normal file
228
src/widget/table.c
Normal file
|
|
@ -0,0 +1,228 @@
|
||||||
|
#include <Mw/Milsko.h>
|
||||||
|
|
||||||
|
#include "../../external/stb_ds.h"
|
||||||
|
|
||||||
|
static int wcreate(MwWidget handle) {
|
||||||
|
MwTable t = malloc(sizeof(*t));
|
||||||
|
memset(t, 0, sizeof(*t));
|
||||||
|
|
||||||
|
handle->internal = t;
|
||||||
|
|
||||||
|
MwSetDefault(handle);
|
||||||
|
|
||||||
|
MwSetInteger(handle, MwNcolumns, 1);
|
||||||
|
MwSetInteger(handle, MwNmargin, 0);
|
||||||
|
MwSetInteger(handle, MwNpadding, 0);
|
||||||
|
MwSetInteger(handle, MwNhasBorder, 0);
|
||||||
|
MwSetInteger(handle, MwNinverted, 1);
|
||||||
|
MwSetInteger(handle, MwNwaitLayout, 0);
|
||||||
|
|
||||||
|
t->layout = 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void destroy(MwWidget handle) {
|
||||||
|
MwTable t = handle->internal;
|
||||||
|
|
||||||
|
arrfree(t->widgets);
|
||||||
|
|
||||||
|
free(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct intkv {
|
||||||
|
int key;
|
||||||
|
int value;
|
||||||
|
} intkv_t;
|
||||||
|
|
||||||
|
static void put_intkv(intkv_t** kv, int x, int y, int c, int r) {
|
||||||
|
int k = (x << 16) | y;
|
||||||
|
int v = (c << 16) | r;
|
||||||
|
|
||||||
|
hmput(*kv, k, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int get_intkv(intkv_t* kv, int x, int y) {
|
||||||
|
int k = (x << 16) | y;
|
||||||
|
|
||||||
|
return hmget(kv, k);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LAYOUT_BEGIN \
|
||||||
|
hmfree(kv); \
|
||||||
|
hmdefault(kv, 0); \
|
||||||
|
n = 0; \
|
||||||
|
x = bw; \
|
||||||
|
y = bw; \
|
||||||
|
for(i = 0; i < arrlen(handle->children); i++) { \
|
||||||
|
MwRect rc; \
|
||||||
|
MwWidget hc = handle->children[i]; \
|
||||||
|
int cs = MwGetInteger(hc, MwNcolumnSpan); \
|
||||||
|
int rs = MwGetInteger(hc, MwNrowSpan); \
|
||||||
|
int w, h; \
|
||||||
|
int cy; \
|
||||||
|
int s = MwGetInteger(handle, MwNmargin); \
|
||||||
|
int v = n; \
|
||||||
|
\
|
||||||
|
if(cs == MwDEFAULT) cs = 1; \
|
||||||
|
if(rs == MwDEFAULT) rs = 1; \
|
||||||
|
\
|
||||||
|
w = cs * cw + (cs - 1) * s; \
|
||||||
|
h = rs * ch + (rs - 1) * s; \
|
||||||
|
\
|
||||||
|
MwGetFrame(hc, &rc); \
|
||||||
|
\
|
||||||
|
if(hc == child || rc.x != x || rc.y != y || rc.width != w || rc.height != h) {
|
||||||
|
|
||||||
|
#define LAYOUT_END(label) \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
put_intkv(&kv, n % c, n / c, cs, rs); \
|
||||||
|
\
|
||||||
|
n += cs; \
|
||||||
|
repeat_##label :; \
|
||||||
|
if((n % c) == 0) { \
|
||||||
|
x = bw; \
|
||||||
|
y += ch + s; \
|
||||||
|
} else { \
|
||||||
|
for(; v < n; v++) { \
|
||||||
|
x += cw + s; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
for(cy = (n / c); cy >= 0; cy--) { \
|
||||||
|
int v = get_intkv(kv, n % c, cy) & 0xffff; \
|
||||||
|
\
|
||||||
|
if(cy <= (n / c) && (n / c) <= (cy + v - 1)) { \
|
||||||
|
v = n; \
|
||||||
|
n += get_intkv(kv, n % c, cy) >> 16; \
|
||||||
|
goto repeat_##label; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
static void layout_widget(MwWidget handle, MwWidget child) {
|
||||||
|
int i;
|
||||||
|
int c = MwGetInteger(handle, MwNcolumns);
|
||||||
|
int bw = (MwGetInteger(handle, MwNhasBorder) ? MwDefaultBorderWidth(handle) : 0) + MwGetInteger(handle, MwNpadding);
|
||||||
|
int m = MwGetInteger(handle, MwNmargin);
|
||||||
|
int n, x, y, cw = 0, ch = 0;
|
||||||
|
int gcs, grs;
|
||||||
|
intkv_t* kv = NULL;
|
||||||
|
|
||||||
|
LAYOUT_BEGIN;
|
||||||
|
LAYOUT_END(1);
|
||||||
|
|
||||||
|
gcs = (n + c - 1) / c;
|
||||||
|
grs = n % c;
|
||||||
|
cw = (MwGetInteger(handle, MwNwidth) - bw * 2 - (m * (c - 1))) / c;
|
||||||
|
ch = (MwGetInteger(handle, MwNheight) - m * (gcs - 1) - bw * 2) / gcs;
|
||||||
|
|
||||||
|
LAYOUT_BEGIN;
|
||||||
|
MwVaApply(hc,
|
||||||
|
MwNx, x,
|
||||||
|
MwNy, y,
|
||||||
|
MwNwidth, w,
|
||||||
|
MwNheight, h,
|
||||||
|
NULL);
|
||||||
|
LAYOUT_END(2);
|
||||||
|
|
||||||
|
hmfree(kv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void layout(MwWidget handle) {
|
||||||
|
MwTable t = handle->internal;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if(arrlen(t->widgets) > 0) {
|
||||||
|
for(i = 0; i < arrlen(t->widgets); i++) layout_widget(handle, t->widgets[i]);
|
||||||
|
} else {
|
||||||
|
for(i = 0; i < arrlen(handle->children[i]); i++) layout_widget(handle, handle->children[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw(MwWidget handle) {
|
||||||
|
MwBoxClass->draw(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tick(MwWidget handle) {
|
||||||
|
MwTable t = handle->internal;
|
||||||
|
|
||||||
|
if(t->layout && !MwGetInteger(handle, MwNwaitLayout)) {
|
||||||
|
layout(handle);
|
||||||
|
|
||||||
|
t->layout = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void prop_change(MwWidget handle, const char* key) {
|
||||||
|
if(strcmp(key, MwNcolumns) == 0 || strcmp(key, MwNpadding) == 0 || strcmp(key, MwNmargin) == 0) {
|
||||||
|
MwTable t = handle->internal;
|
||||||
|
t->layout = 1;
|
||||||
|
|
||||||
|
MwForceRender(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void resize(MwWidget handle) {
|
||||||
|
MwTable t = handle->internal;
|
||||||
|
t->layout = 1;
|
||||||
|
|
||||||
|
MwForceRender(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void children_update(MwWidget handle, MwWidget child, int new) {
|
||||||
|
MwTable t = handle->internal;
|
||||||
|
t->layout = 1;
|
||||||
|
|
||||||
|
if(new) {
|
||||||
|
arrput(t->widgets, child);
|
||||||
|
} else {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < arrlen(t->widgets); i++) {
|
||||||
|
if(t->widgets[i] == child) {
|
||||||
|
arrdel(t->widgets, i);
|
||||||
|
i = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MwForceRender(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void children_prop_change(MwWidget handle, MwWidget child, const char* key) {
|
||||||
|
(void)child;
|
||||||
|
|
||||||
|
if(strcmp(key, MwNcolumnSpan) == 0 || strcmp(key, MwNrowSpan) == 0) {
|
||||||
|
MwTable t = handle->internal;
|
||||||
|
t->layout = 1;
|
||||||
|
|
||||||
|
arrput(t->widgets, child);
|
||||||
|
|
||||||
|
MwForceRender(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MwClassRec MwTableClassRec = {
|
||||||
|
wcreate, /* create */
|
||||||
|
destroy, /* destroy */
|
||||||
|
draw, /* draw */
|
||||||
|
NULL, /* click */
|
||||||
|
NULL, /* parent_resize */
|
||||||
|
prop_change, /* prop_change */
|
||||||
|
NULL, /* mouse_move */
|
||||||
|
NULL, /* mouse_up */
|
||||||
|
NULL, /* mouse_down */
|
||||||
|
NULL, /* key */
|
||||||
|
NULL, /* execute */
|
||||||
|
tick, /* tick */
|
||||||
|
resize, /* resize */
|
||||||
|
children_update, /* children_update */
|
||||||
|
children_prop_change, /* children_prop_change */
|
||||||
|
NULL, /* clipboard */
|
||||||
|
NULL, /* props_change */
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL};
|
||||||
|
MwClass MwTableClass = &MwTableClassRec;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue