aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-07-21 15:31:47 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-07-21 16:04:51 +0200
commitd3b34cd482a38a72987ad5136073099acca36537 (patch)
tree86e230bec01283ae53b1a1d8a37330007eab90ae
parentb067c1948b03501ede6ee324ef8c642e05fe6b18 (diff)
downloadfiv-d3b34cd482a38a72987ad5136073099acca36537.tar.gz
fiv-d3b34cd482a38a72987ad5136073099acca36537.tar.xz
fiv-d3b34cd482a38a72987ad5136073099acca36537.zip
Only offer horizontal browser scrolling if useful
Motivated by small screens.
-rw-r--r--fiv-browser.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/fiv-browser.c b/fiv-browser.c
index 6909748..89fb00c 100644
--- a/fiv-browser.c
+++ b/fiv-browser.c
@@ -156,7 +156,7 @@ relayout(FivBrowser *self, int width)
GtkBorder padding = {};
gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
- int available_width = width - padding.left - padding.right;
+ int available_width = width - padding.left - padding.right, max_width = 0;
g_array_set_size(self->layouted_rows, 0);
// Whatever self->drag_begin_* used to point at might no longer be there,
@@ -183,7 +183,10 @@ relayout(FivBrowser *self, int width)
g_array_append_val(items,
((Item) {.entry = entry, .x_offset = x + self->item_border_x}));
+
x += width;
+ if (max_width < width)
+ max_width = width;
}
if (items->len) {
append_row(self, &y,
@@ -193,11 +196,9 @@ relayout(FivBrowser *self, int width)
g_array_free(items, TRUE);
int total_height = y + padding.bottom;
if (self->hadjustment) {
- gint minimum_width = 0;
- gtk_widget_get_preferred_width(widget, &minimum_width, NULL);
-
gtk_adjustment_set_lower(self->hadjustment, 0);
- gtk_adjustment_set_upper(self->hadjustment, MAX(width, minimum_width));
+ gtk_adjustment_set_upper(self->hadjustment,
+ width + MAX(0, max_width - available_width));
gtk_adjustment_set_step_increment(self->hadjustment, width * 0.1);
gtk_adjustment_set_page_increment(self->hadjustment, width * 0.9);
gtk_adjustment_set_page_size(self->hadjustment, width);
@@ -916,9 +917,12 @@ fiv_browser_get_preferred_width(GtkWidget *widget, gint *minimum, gint *natural)
GtkBorder padding = {};
gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
- *minimum = *natural =
- FIV_THUMBNAIL_WIDE_COEFFICIENT * self->item_height + padding.left +
- 2 * self->item_border_x + padding.right;
+
+ // This should ideally reflect thumbnails, but we're in a GtkScrolledWindow,
+ // making this rather inconsequential.
+ int fluff = padding.left + 2 * self->item_border_x + padding.right;
+ *minimum = fluff + self->item_height /* Icons are rectangular. */;
+ *natural = fluff + FIV_THUMBNAIL_WIDE_COEFFICIENT * self->item_height;
}
static void
@@ -989,14 +993,16 @@ fiv_browser_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
GTK_WIDGET_CLASS(fiv_browser_parent_class)
->size_allocate(widget, allocation);
- int height = relayout(FIV_BROWSER(widget), allocation->width);
+ relayout(FIV_BROWSER(widget), allocation->width);
// Avoid fresh blank space.
+ if (self->hadjustment) {
+ gtk_adjustment_set_value(
+ self->hadjustment, gtk_adjustment_get_value(self->hadjustment));
+ }
if (self->vadjustment) {
- double y1 = gtk_adjustment_get_value(self->vadjustment);
- double ph = gtk_adjustment_get_page_size(self->vadjustment);
- if (y1 + ph > height)
- gtk_adjustment_set_value(self->vadjustment, height - ph);
+ gtk_adjustment_set_value(
+ self->vadjustment, gtk_adjustment_get_value(self->vadjustment));
}
}