aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-08-06 22:20:21 +0200
committerGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-08-06 22:20:21 +0200
commit11154aaca7d00a86e9891b86a61badb29fc92a07 (patch)
treead5a3ea48458400f0340b7513f9fd6fe7013e8e6
parent7e92dc64a53914cbbf9e744824570ae25ccf982d (diff)
downloadsynthpod-11154aaca7d00a86e9891b86a61badb29fc92a07.zip
synthpod-11154aaca7d00a86e9891b86a61badb29fc92a07.tar.gz
synthpod-11154aaca7d00a86e9891b86a61badb29fc92a07.tar.bz2
synthpod-11154aaca7d00a86e9891b86a61badb29fc92a07.tar.xz
Squashed 'subprojects/d2tk/' changes from 96803ab6..745820dd
745820dd base: handle empty tables. 47a8a066 base: skip header in frames without labels. git-subtree-dir: subprojects/d2tk git-subtree-split: 745820dd18d62286cb9bb8c2d83c5fb00afef649
-rw-r--r--VERSION2
-rw-r--r--example/example.c4
-rw-r--r--src/base.c17
-rw-r--r--test/base.c108
4 files changed, 119 insertions, 12 deletions
diff --git a/VERSION b/VERSION
index eddad3c..33a73c4 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.779
+0.1.783
diff --git a/example/example.c b/example/example.c
index b410d8e..b13a026 100644
--- a/example/example.c
+++ b/example/example.c
@@ -732,7 +732,9 @@ _render_c_frame(d2tk_base_t *base, const d2tk_rect_t *rect)
const unsigned k = d2tk_table_get_index(tab);
char lbl [32];
- const ssize_t lbl_len = snprintf(lbl, sizeof(lbl), "This is frame #%u", k);
+ const ssize_t lbl_len = (k % 2)
+ ? snprintf(lbl, sizeof(lbl), "This is frame #%u", k)
+ : 0;
D2TK_BASE_FRAME(base, bnd_outer, lbl_len, lbl, frm)
{
diff --git a/src/base.c b/src/base.c
index 496e459..0a68dd0 100644
--- a/src/base.c
+++ b/src/base.c
@@ -324,6 +324,11 @@ D2TK_API d2tk_table_t *
d2tk_table_begin(const d2tk_rect_t *rect, unsigned N, unsigned M,
d2tk_flag_t flag, d2tk_table_t *tab)
{
+ if( (N == 0) || (M == 0) )
+ {
+ return NULL;
+ }
+
unsigned w;
unsigned h;
@@ -360,7 +365,7 @@ d2tk_table_begin(const d2tk_rect_t *rect, unsigned N, unsigned M,
D2TK_API bool
d2tk_table_not_end(d2tk_table_t *tab)
{
- return tab->k < tab->NM;
+ return tab && (tab->k < tab->NM);
}
D2TK_API d2tk_table_t *
@@ -432,8 +437,12 @@ d2tk_frame_begin(d2tk_base_t *base, const d2tk_rect_t *rect,
const uint64_t hash = d2tk_hash_dict(dict);
d2tk_rect_shrink(&frm->rect, rect, 2*style->padding);
- frm->rect.y += h;
- frm->rect.h -= h;
+
+ if(has_lbl)
+ {
+ frm->rect.y += h;
+ frm->rect.h -= h;
+ }
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -443,7 +452,7 @@ d2tk_frame_begin(d2tk_base_t *base, const d2tk_rect_t *rect,
const size_t ref = d2tk_core_bbox_push(core, true, rect);
- if(lbl)
+ if(has_lbl)
{
bnd_inner.h = h;
diff --git a/test/base.c b/test/base.c
index 6145113..ca5c3af 100644
--- a/test/base.c
+++ b/test/base.c
@@ -780,6 +780,39 @@ _test_table_rel()
}
static void
+_test_table_rel_empty()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = NULL
+ };
+
+ d2tk_base_t *base = d2tk_base_new(&d2tk_mock_driver_lazy, &ctx);
+ const d2tk_rect_t rect = D2TK_RECT(0, 0, DIM_W, DIM_H);
+ assert(base);
+
+ bool visited = false;
+
+ D2TK_BASE_TABLE(&rect, 0, 0, D2TK_FLAG_TABLE_REL, tab)
+ {
+ visited = true;
+ }
+
+ D2TK_BASE_TABLE(&rect, 0, 1, D2TK_FLAG_TABLE_REL, tab)
+ {
+ visited = true;
+ }
+
+ D2TK_BASE_TABLE(&rect, 1, 0, D2TK_FLAG_TABLE_REL, tab)
+ {
+ visited = true;
+ }
+
+ assert(visited == false);
+
+ d2tk_base_free(base);
+}
+
+static void
_test_table_abs()
{
#define N 12
@@ -813,7 +846,42 @@ _test_table_abs()
}
static void
-_test_frame()
+_test_table_abs_empty()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = NULL
+ };
+
+ d2tk_base_t *base = d2tk_base_new(&d2tk_mock_driver_lazy, &ctx);
+ const d2tk_rect_t rect = D2TK_RECT(0, 0, DIM_W, DIM_H);
+ assert(base);
+
+ bool visited = false;
+
+ D2TK_BASE_TABLE(&rect, 0, 0, D2TK_FLAG_TABLE_ABS, tab)
+ {
+ visited = true;
+ }
+
+ D2TK_BASE_TABLE(&rect, 0, 1, D2TK_FLAG_TABLE_ABS, tab)
+ {
+ visited = true;
+ }
+
+ D2TK_BASE_TABLE(&rect, 1, 0, D2TK_FLAG_TABLE_ABS, tab)
+ {
+ visited = true;
+ }
+
+ assert(visited == false);
+
+ d2tk_base_free(base);
+#undef M
+#undef N
+}
+
+static void
+_test_frame_with_label()
{
d2tk_mock_ctx_t ctx = {
.check = NULL
@@ -828,10 +896,35 @@ _test_frame()
const d2tk_rect_t *bnd = d2tk_frame_get_rect(frm);
assert(bnd);
- assert(bnd->x > rect.x);
- assert(bnd->y > rect.y);
- assert(bnd->w < rect.w);
- assert(bnd->h < rect.h);
+ assert(bnd->x > rect.x); //FIXME
+ assert(bnd->y > rect.y); //FIXME
+ assert(bnd->w < rect.w); //FIXME
+ assert(bnd->h < rect.h); //FIXME
+ }
+
+ d2tk_base_free(base);
+}
+
+static void
+_test_frame_wo_label()
+{
+ d2tk_mock_ctx_t ctx = {
+ .check = NULL
+ };
+
+ d2tk_base_t *base = d2tk_base_new(&d2tk_mock_driver_lazy, &ctx);
+ const d2tk_rect_t rect = D2TK_RECT(0, 0, DIM_W, DIM_H);
+ assert(base);
+
+ D2TK_BASE_FRAME(base, &rect, 0, NULL, frm)
+ {
+ const d2tk_rect_t *bnd = d2tk_frame_get_rect(frm);
+
+ assert(bnd);
+ assert(bnd->x > rect.x); //FIXME
+ assert(bnd->y > rect.y); //FIXME
+ assert(bnd->w < rect.w); //FIXME
+ assert(bnd->h < rect.h); //FIXME
}
d2tk_base_free(base);
@@ -1910,8 +2003,11 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
_test_get_set();
_test_state_dump();
_test_table_rel();
+ _test_table_rel_empty();
_test_table_abs();
- _test_frame();
+ _test_table_abs_empty();
+ _test_frame_with_label();
+ _test_frame_wo_label();
_test_layout_relative_x();
_test_layout_relative_y();
_test_layout_absolute_x();