From c98310e78e8ea28c11c57032aea9e3198e44a22a Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sat, 7 Oct 2023 08:24:35 +1100 Subject: [PATCH] imageview: don't measure image until first refresh. The image might not be ready until the first refresh. e.g. some later pane might have an effect. So measure on the first refresh. Also allow the image source to be set with a pane attribute, or to fall back to an obvious defailt. Signed-off-by: NeilBrown --- render-imageview.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/render-imageview.c b/render-imageview.c index ae84cbbe..b274f7f0 100644 --- a/render-imageview.c +++ b/render-imageview.c @@ -38,7 +38,22 @@ DEF_CMD(imageview_refresh) int ph = ci->home->h * ivd->py; call("Draw:clear", ci->focus, 0, NULL, "bg:black"); + + if (!img) + img = pane_attr_get(ci->focus, "imageview:image-source"); if (!img) + img = "comm:doc:get-bytes"; + if (!ivd->image) + ivd->image = strdup(img); + + if (ivd->w <= 0) { + struct call_return cr = call_ret(all, "Draw:image-size", + ci->focus, + 0, NULL, img); + ivd->w = cr.x; + ivd->h = cr.y; + } + if (ivd->w <= 0 || ivd->h <= 0) return 1; if (ivd->scale <= 0) { @@ -165,16 +180,8 @@ DEF_CMD(imageview_attach) if (!p) return Efail; ivd = p->data; - if (ci->str) { - struct call_return cr; - cr = call_ret(bytes, ci->str+5, ci->focus); - + if (ci->str) ivd->image = strdup(ci->str); - cr = call_ret(all, "Draw:image-size", ci->focus, - 0, NULL, ivd->image); - ivd->w = cr.x; - ivd->h = cr.y; - } ivd->scale = 0; pxl = pane_attr_get(p, "Display:pixels"); if (sscanf(pxl ?: "1x1", "%hdx%hx", &ivd->px, &ivd->py) != 2) -- 2.39.5