]> git.neil.brown.name Git - edlib.git/commitdiff
make popups work better in gtk display.
authorNeilBrown <neil@brown.name>
Wed, 13 Jan 2016 04:45:39 +0000 (15:45 +1100)
committerNeilBrown <neil@brown.name>
Wed, 13 Jan 2016 04:45:39 +0000 (15:45 +1100)
Now at least they aren't 3 pixels high.

'search' has problems though.

Signed-off-by: NeilBrown <neil@brown.name>
lib-popup.c
python/display-pygtk.py
render-lines.c

index 628011a722329bba8129ec49873e9b388acdd414..f9f3627f240374b1077a37f3dafe089dcb7eb86b 100644 (file)
@@ -36,14 +36,36 @@ struct popup_info {
        int closing;
 };
 
+DEF_CMD(text_size_callback)
+{
+       struct call_return *cr = container_of(ci->comm, struct call_return, c);
+       cr->x = ci->x;
+       cr->y = ci->y;
+       cr->i = ci->numeric;
+       cr->i2 = ci->extra;
+       return 1;
+}
+
+static int line_height(struct pane *p)
+{
+       struct call_return cr;
+
+       cr.c = text_size_callback;
+       call_comm7("text-size", p, -1, NULL, "x", 0, "", &cr.c);
+       return cr.y;
+}
+
 static void popup_resize(struct pane *p, char *style)
 {
        int x,y,w,h;
+       int lh;
+
        /* First find the size */
+       lh = line_height(p);
        if (strchr(style, 'M'))
                h = p->parent->h/2 + 1;
        else
-               h = 3;
+               h = lh * 3;
        w = p->parent->w/2;
        if (strchr(style, '1')) w = (p->parent->w-2)/4 + 1;
        if (strchr(style, '3')) w = 3 * (p->parent->w-2)/4;
index 4151c189ccdf8b8f5c2ae3f688f1c14b07685525..4e718cd6570ff3c1c9370aad975042df65535e2f 100644 (file)
@@ -23,6 +23,7 @@ class EdDisplay(gtk.Window):
         self.set_title("EDLIB")
         self.connect('destroy', self.close_win)
         self.create_ui()
+        self.need_refresh = True
         self.pane.w = self.charwidth * 80
         self.pane.h = self.lineheight * 24
         self.show()
@@ -109,6 +110,7 @@ class EdDisplay(gtk.Window):
                         l2 = pango.Layout(ctx)
                         l2.set_text(s[0])
                         pm.draw_layout(self.gc, x+cx, y-ascent+cy, l2, bg)
+            return True
 
         if key == "Notify:Close":
             f = a["focus"]
@@ -199,7 +201,9 @@ class EdDisplay(gtk.Window):
 
 
     def refresh(self, *a):
-        self.pane.refresh()
+        if self.need_refresh:
+            self.pane.refresh()
+            self.need_refresh = False
         l = self.panes.keys()
         l.sort(key=lambda pane: pane.abs_z)
         for p in l:
@@ -211,8 +215,11 @@ class EdDisplay(gtk.Window):
 
     def reconfigure(self, w, ev):
         alloc = w.get_allocation()
+        if self.pane.w == alloc.width and self.pane.h == alloc.height:
+            return None
         self.pane.w = alloc.width
         self.pane.h = alloc.height
+        self.need_refresh = True
         self.text.queue_draw()
 
     def press(self, c, event):
@@ -227,7 +234,7 @@ class EdDisplay(gtk.Window):
         if event.state & gtk.gdk.MOD1_MASK:
             s = "M-" + s;
         self.pane.call_xy("Mouse-event", "Click-1", self.pane, (x,y))
-        self.refresh()
+        self.pane.refresh()
 
     eventmap = { "Return" : "Return",
                  "Tab" : "Tab",
index 17db30326c75424fc80f8008d434ea8b172a7387..88fa98408281097a73d9ec1b2549564a412ac03e 100644 (file)
@@ -304,7 +304,7 @@ static void render_line(struct pane *p, char *line, int *yp, int dodraw,
                        CP = offset - (start - line_start);
                ret = 0;
 
-               if (offset >= 0 && line - line_start <= offset) {
+               if (offset >= 0 && start - line_start <= offset) {
                        *cyp = y;
                        *cxp = x;
                }
@@ -358,6 +358,8 @@ static void render_line(struct pane *p, char *line, int *yp, int dodraw,
                                        if (attr.len == 2)
                                                attr.len = 0;
                                }
+                               if (offset == start - line_start)
+                                       offset += line-start;
                                start = line;
                                mwidth = -1;
                        }