]> git.neil.brown.name Git - edlib.git/commitdiff
imageview: don't measure image until first refresh.
authorNeilBrown <neil@brown.name>
Fri, 6 Oct 2023 21:24:35 +0000 (08:24 +1100)
committerNeilBrown <neil@brown.name>
Fri, 6 Oct 2023 21:24:35 +0000 (08:24 +1100)
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 <neil@brown.name>
render-imageview.c

index ae84cbbe5e86537c3019b46318b9b3fc499af99a..b274f7f0f04b365f1e2732b6f3007e5bb5947ab7 100644 (file)
@@ -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)