commit - d16169765fc12c4a3a5e97b595b5fafe77243ab2
commit + 16946472422902f8b4a9feb948e6e73d605a6e76
blob - 38588f3ab18ed6b97496e9364aeeab33bebbbdf8
blob + a885c16166113b3772919d9d01bf5d3e4f32b7d3
--- aui.h
+++ aui.h
struct aui_gridpar {
unsigned int column;
- unsigned int columnspan;
- int padx[2];
- int pady[2];
unsigned int row;
- unsigned int rowspan;
-#define AUI_STICKY_N (1 << 0)
-#define AUI_STICKY_W (1 << 1)
-#define AUI_STICKY_S (1 << 2)
-#define AUI_STICKY_E (1 << 3)
- unsigned char sticky;
};
struct aui_widget;
const char *text; /* Should not be allocated, string literal */
};
+struct aui_frameconfig {
+ struct aui_color bg;
+};
+
void aui_run(void);
void aui_destroy(struct aui_widget *);
struct aui_window *aui_window_new(struct aui_windowconfig *);
blob - 7a3b05d627cd9f5f83b902e24a7cb39c0c2a8f96
blob + 98c86a341a67860a50f01948937df86b56ad35f3
--- button.c
+++ button.c
static void button_mouse_release(struct aui_widget *, uint16_t, uint16_t, uint8_t);
static void button_set_geometry(struct aui_widget *, struct aui_geometry *);
static void button_free(struct aui_widget *);
+static struct aui_geometry button_get_min_size(struct aui_widget *);
static struct widget_ops button_ops = {
button_mouse_hover,
button_mouse_release,
button_set_geometry, /* set geometry */
button_free,
+ button_get_min_size,
};
struct aui_color color[] = {
driver->ops->set_rectangle_geometry(widget->window, widget->primitives.list[1], &fgeom);
driver->ops->set_text(widget->primitives.list[2], button->config.text, tx, ty);
}
+
+static struct aui_geometry
+button_get_min_size(struct aui_widget *widget)
+{
+ struct aui_geometry geom = driver->ops->get_text_geometry(widget->primitives.list[2]);
+ struct aui_button *button = (struct aui_button *)widget;
+
+ geom.width = (geom.width < 20) ? geom.width = 20 : geom.width + 20;
+ geom.height = (button->config.text == NULL) ? 12 + 20 : geom.height + 20;
+
+ return geom;
+}
blob - 274e6c524dcc10f20dfc94d0e0c9429a925e119f
blob + a5479ecb087d4be19941e7b4f678051e92e0c8f4
--- frame.c
+++ frame.c
static void frame_mouse_release(struct aui_widget *, uint16_t, uint16_t, uint8_t);
static void frame_set_geometry(struct aui_widget *, struct aui_geometry *);
static void frame_free(struct aui_widget *);
+static struct aui_geometry frame_get_min_size(struct aui_widget *);
static struct widget_ops frame_ops = {
frame_mouse_hover,
frame_mouse_release,
frame_set_geometry,
frame_free,
+ frame_get_min_size,
};
struct aui_color colors[] = {
{
}
+
+static struct aui_geometry frame_get_min_size(struct aui_widget *widget)
+{
+ struct aui_geometry geom = { 0, 0, 120, 120 };
+ return geom;
+}
blob - e6bd6db3edd2dd39c0d85565dd76719bf8386aa8
blob + 25f5fe46830eb47cb866b852d54ef82b5163a416
--- layout.c
+++ layout.c
struct aui_container *con = (struct aui_container *)parent;
- if ((con->layout_type != type) && (con->layout_type != AUI_LAYOUT_NONE && con->map_count != 0)) {
+ if ((con->layout_type != type) && (con->layout_type != AUI_LAYOUT_NONE)) {
fprintf(stderr, "libaui: cannot map as mismatching type / non-empty container\n");
return -1;
}
geom.x += dx;
geom.y += dy;
child->in_ops->set_geometry(child, &geom);
- con->map_count++;
switch (child->type) {
case WIDGET_TYPE_FRAME:
}
break;
case AUI_LAYOUT_GRID: {
- unsigned int cell_size[2] = { 50, 50 };
- unsigned int *added = calloc(con->grid_size[0], sizeof(unsigned int));
- unsigned int *radded = calloc(con->grid_size[1], sizeof(unsigned int));
+ uint8_t *rmap = calloc(con->grid_size[1], sizeof(uint8_t));
+ uint8_t *cmap = calloc(con->grid_size[0], sizeof(uint8_t));
+ unsigned int *rsize = calloc(con->grid_size[1], sizeof(unsigned int));
+ unsigned int *csize = calloc(con->grid_size[0], sizeof(unsigned int));
+
TAILQ_FOREACH(child, &widget->queue, entries) {
if (child->mapped == 0)
continue;
+ struct aui_geometry min = child->in_ops->get_min_size(child);
+
+ rmap[child->gridpar.row] = 1;
+ cmap[child->gridpar.column] = 1;
+
+ rsize[child->gridpar.row] = (rsize[child->gridpar.row] < min.height) ?
+ min.height : rsize[child->gridpar.row];
+
+ csize[child->gridpar.column] = (csize[child->gridpar.column] < min.width) ?
+ min.width : csize[child->gridpar.column];
+ }
+
+ unsigned int *rpos = calloc(con->grid_size[1], sizeof(unsigned int));
+ unsigned int *cpos = calloc(con->grid_size[0], sizeof(unsigned int));
+
+ unsigned int rowdt = 0;
+ unsigned int coldt = 0;
+
+ for (int r = 0; r < con->grid_size[1]; r++) {
+ rpos[r] = rowdt;
+ rowdt = (rmap[r] == 1) ? rowdt + rsize[r] : rowdt;
+ }
+
+ for (int c = 0; c < con->grid_size[0]; c++) {
+ cpos[c] = coldt;
+ coldt = (cmap[c] == 1) ? coldt + csize[c] : coldt;
+ }
+
+ TAILQ_FOREACH(child, &widget->queue, entries) {
+ if (child->mapped == 0)
+ continue;
+
+ struct aui_geometry min = child->in_ops->get_min_size(child);
struct aui_geometry geom = { 0 };
- struct aui_widget *sub;
- geom.x = widget->geom.x;
- geom.y = widget->geom.y;
+ int dx = (csize[child->gridpar.column] - min.width);
+ int dy = (rsize[child->gridpar.row] - min.height);
- memset(added, 0, sizeof(unsigned int) * con->grid_size[0]);
- memset(radded, 0, sizeof(unsigned int) * con->grid_size[1]);
+ geom.x = widget->geom.x + cpos[child->gridpar.column] + dx / 2;
+ geom.y = widget->geom.y + rpos[child->gridpar.row] + dy / 2;
+ geom.width = min.width;
+ geom.height = min.height;
- TAILQ_FOREACH(sub, &widget->queue, entries) {
- if (sub->mapped == 0 || sub == child)
- continue;
-
- if (sub->gridpar.column < child->gridpar.column && added[sub->gridpar.column] == 0) {
- added[sub->gridpar.column] = 1;
- geom.x += cell_size[0];
- }
-
- if (sub->gridpar.row < child->gridpar.row && radded[sub->gridpar.row] == 0) {
- radded[sub->gridpar.row] = 1;
- geom.y += cell_size[1];
- }
- }
-
- geom.width = cell_size[0];
- geom.height = cell_size[1];
-
child->in_ops->set_geometry(child, &geom);
}
- free(added);
- free(radded);
+ free(rsize);
+ free(csize);
+ free(rpos);
+ free(cpos);
+ free(rmap);
+ free(cmap);
- con->map_count++;
-
TAILQ_FOREACH(child, &widget->queue, entries) {
switch (child->type) {
case WIDGET_TYPE_FRAME:
blob - 43506051b78dafba4fd481205d01ff10d1451a72
blob + ea1275edf338f2e6c3ab8c83c1d8410f8c0d0f9d
--- widget.h
+++ widget.h
void (*mouse_release) (struct aui_widget *, uint16_t, uint16_t, uint8_t);
void (*set_geometry) (struct aui_widget *, struct aui_geometry *);
void (*free) (struct aui_widget *);
+ struct aui_geometry (*get_min_size) (struct aui_widget *);
};
struct aui_container {
struct aui_widget widget;
- unsigned int map_count;
enum aui_layout_type layout_type;
uint32_t grid_size[2];
blob - 5708346b399b58c1ce0e06522e02af5042f6d592
blob + 6c91aa4e9996a5df3de2272b9a8aff291dd2dc18
--- window.c
+++ window.c
widget->in_ops = &window_ops;
widget->mapped = 1;
- aw->con.map_count = 0;
widget->window = aw;
aw->draw_flag = 1;