From: Christian Heller Date: Mon, 28 Oct 2024 11:53:42 +0000 (+0100) Subject: Browser: Ellipsize by_1st view's vertical labels into slot height. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7B%20web_path%20%7D%7D/edit?a=commitdiff_plain;h=f3bf251593bd0af3741bfe70c7ba845801fd231a;p=stable_plom Browser: Ellipsize by_1st view's vertical labels into slot height. --- diff --git a/browser.py b/browser.py index 28ed0c6..bd60c4e 100755 --- a/browser.py +++ b/browser.py @@ -476,19 +476,26 @@ class ImgItem(GalleryItem): class VerticalLabel(Gtk.DrawingArea): """Label of vertical text (rotated -90°).""" - def __init__(self, text): + def __init__(self, text, max_height_ref): super().__init__() - self._layout = self.create_pango_layout() - self._layout.set_markup(text) - self._text_width, self._text_height = self._layout.get_pixel_size() + self._text = text + self._max_height_ref = max_height_ref + test_layout = self.create_pango_layout() + test_layout.set_markup(text) + _, self._text_height = test_layout.get_pixel_size() self.set_draw_func(self._on_draw) def _on_draw(self, _, cairo_ctx, __, height): - """Show ._layout rotated by 90°, move and re-size appropriately.""" - cairo_ctx.translate(0, self._text_width + (height - self._text_width)) + """Create layout, rotate by 90°, size widget to measurements.""" + layout = self.create_pango_layout() + layout.set_markup(self._text) + layout.set_width(self._max_height_ref[0] * Pango.SCALE) + layout.set_ellipsize(Pango.EllipsizeMode.MIDDLE) + text_width, _ = layout.get_pixel_size() + cairo_ctx.translate(0, text_width + (height - text_width)) cairo_ctx.rotate(radians(-90)) - PangoCairo.show_layout(cairo_ctx, self._layout) - self.set_size_request(self._text_height, self._text_width) + PangoCairo.show_layout(cairo_ctx, layout) + self.set_size_request(self._text_height, text_width) @property def width(self): @@ -531,6 +538,7 @@ class Gallery: scroller = Gtk.ScrolledWindow(propagate_natural_height=True) self._col_headers_frame = Gtk.Fixed() self._col_headers_grid = None + self._vlabel_height_ref = [0] self.frame = Gtk.Box(orientation=OR_V) self.frame.append(self._col_headers_frame) self.frame.append(scroller) @@ -801,7 +809,8 @@ class Gallery: attr_name, attr_values = remaining[0] if 1 == len(remaining): for i, attr in enumerate(ancestors): - vlabel = VerticalLabel(f'{attr[0]}: {attr[1]}') + vlabel = VerticalLabel(f'{attr[0]}: {attr[1]}', + self._vlabel_height_ref) self._grid.attach(vlabel, i, i_row_ref[0], 1, 1) row = [None] * len(attr_values) for item in items_of_parent: @@ -943,6 +952,7 @@ class Gallery: i_vlabels += 1 max_slot_width = (vp_width - side_offset) // self._per_row slot_size = min(vp_height, max_slot_width) + self._vlabel_height_ref[0] = slot_size if self._by_1st: i_widgets = 0 while True: