From: NeilBrown Date: Fri, 6 Oct 2023 21:24:35 +0000 (+1100) Subject: imageview: don't measure image until first refresh. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=c98310e78e8ea28c11c57032aea9e3198e44a22a;p=edlib.git 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 --- 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)