diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2021-10-15 23:08:42 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2021-10-15 23:09:26 +0200 |
commit | ce92a23551fa0fd8ce5b6405d78805c9fa73e20e (patch) | |
tree | f04effc5c71fd25e39dd95ba7945970d46d6dfd3 /src/stardict-view.c | |
parent | 573554b9decf74f3b57ab6d26252700132255525 (diff) | |
download | tdv-ce92a23551fa0fd8ce5b6405d78805c9fa73e20e.tar.gz tdv-ce92a23551fa0fd8ce5b6405d78805c9fa73e20e.tar.xz tdv-ce92a23551fa0fd8ce5b6405d78805c9fa73e20e.zip |
sdgui: scroll by three rows
Don't use an arbitrary amount of pixels, base it off the font.
Diffstat (limited to 'src/stardict-view.c')
-rw-r--r-- | src/stardict-view.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/stardict-view.c b/src/stardict-view.c index 884f2e8..ce9eafc 100644 --- a/src/stardict-view.c +++ b/src/stardict-view.c @@ -123,10 +123,10 @@ view_entry_height (ViewEntry *ve, gint *word_offset, gint *defn_offset) pango_layout_get_pixel_size (ve->definition_layout, &defn_w, &defn_h); // Align baselines, without further considerations - gint wb = pango_layout_get_baseline (ve->word_layout) / PANGO_SCALE; - gint db = pango_layout_get_baseline (ve->definition_layout) / PANGO_SCALE; - gint word_y = MAX (0, db - wb); - gint defn_y = MAX (0, wb - db); + gint wb = pango_layout_get_baseline (ve->word_layout); + gint db = pango_layout_get_baseline (ve->definition_layout); + gint word_y = MAX (0, PANGO_PIXELS (db - wb)); + gint defn_y = MAX (0, PANGO_PIXELS (wb - db)); if (word_offset) *word_offset = word_y; @@ -162,7 +162,7 @@ view_entry_draw (ViewEntry *ve, cairo_t *cr, gint full_width, gboolean even) PangoRectangle logical = {}; pango_layout_iter_get_line_extents (iter, NULL, &logical); - cairo_move_to (cr, PADDING, word_y + logical.y / PANGO_SCALE); + cairo_move_to (cr, PADDING, word_y + PANGO_PIXELS (logical.y)); pango_cairo_show_layout (cr, ve->word_layout); } while (pango_layout_iter_next_line (iter)); @@ -322,6 +322,16 @@ reload (StardictView *self) gtk_widget_queue_draw (widget); } +static gint +natural_row_size (GtkWidget *widget) +{ + PangoLayout *layout = gtk_widget_create_pango_layout (widget, "X"); + gint width = 0, height = 0; + pango_layout_get_pixel_size (layout, &width, &height); + g_object_unref (layout); + return height; +} + // --- Boilerplate ------------------------------------------------------------- G_DEFINE_TYPE (StardictView, stardict_view, GTK_TYPE_WIDGET) @@ -345,17 +355,11 @@ static void stardict_view_get_preferred_height (GtkWidget *widget, gint *minimum, gint *natural) { - PangoLayout *layout = gtk_widget_create_pango_layout (widget, NULL); - - gint width = 0, height = 0; - pango_layout_get_pixel_size (layout, &width, &height); - g_object_unref (layout); - // There isn't any value that would make any real sense if (!STARDICT_VIEW (widget)->dict) *natural = *minimum = 0; else - *natural = *minimum = height; + *natural = *minimum = natural_row_size (widget); } static void @@ -452,11 +456,11 @@ stardict_view_scroll_event (GtkWidget *widget, GdkEventScroll *event) switch (event->direction) { case GDK_SCROLL_UP: - self->top_offset -= 50; + self->top_offset -= 3 * natural_row_size (widget); adjust_for_offset (self); return TRUE; case GDK_SCROLL_DOWN: - self->top_offset += 50; + self->top_offset += 3 * natural_row_size (widget); adjust_for_offset (self); return TRUE; default: |