aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-08-06 19:06:02 +0200
committerGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-08-06 19:06:02 +0200
commit47a8a06604747ab156ebeac903ec6ef182dfc529 (patch)
tree52ea16574ea757f422dbcc32152850c64041b9d2
parent96803ab69db013383fa8575529545fb14affc774 (diff)
downloadd2tk-47a8a06604747ab156ebeac903ec6ef182dfc529.zip
d2tk-47a8a06604747ab156ebeac903ec6ef182dfc529.tar.gz
d2tk-47a8a06604747ab156ebeac903ec6ef182dfc529.tar.bz2
d2tk-47a8a06604747ab156ebeac903ec6ef182dfc529.tar.xz
base: skip header in frames without labels.
-rw-r--r--example/example.c4
-rw-r--r--src/base.c10
-rw-r--r--test/base.c38
3 files changed, 42 insertions, 10 deletions
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..fcd07a5 100644
--- a/src/base.c
+++ b/src/base.c
@@ -432,8 +432,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 +447,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..9495776 100644
--- a/test/base.c
+++ b/test/base.c
@@ -813,7 +813,7 @@ _test_table_abs()
}
static void
-_test_frame()
+_test_frame_with_label()
{
d2tk_mock_ctx_t ctx = {
.check = NULL
@@ -828,10 +828,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);
@@ -1911,7 +1936,8 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
_test_state_dump();
_test_table_rel();
_test_table_abs();
- _test_frame();
+ _test_frame_with_label();
+ _test_frame_wo_label();
_test_layout_relative_x();
_test_layout_relative_y();
_test_layout_absolute_x();