From: NeilBrown Date: Wed, 13 Jan 2016 04:45:39 +0000 (+1100) Subject: make popups work better in gtk display. X-Git-Tag: lca2016~20 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=72812a09cd5574031048f80da970e4f9c62b08b0;p=edlib.git make popups work better in gtk display. Now at least they aren't 3 pixels high. 'search' has problems though. Signed-off-by: NeilBrown --- diff --git a/lib-popup.c b/lib-popup.c index 628011a7..f9f3627f 100644 --- a/lib-popup.c +++ b/lib-popup.c @@ -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; diff --git a/python/display-pygtk.py b/python/display-pygtk.py index 4151c189..4e718cd6 100644 --- a/python/display-pygtk.py +++ b/python/display-pygtk.py @@ -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", diff --git a/render-lines.c b/render-lines.c index 17db3032..88fa9840 100644 --- a/render-lines.c +++ b/render-lines.c @@ -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; }