aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-11-22 15:08:34 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-11-22 15:08:56 +0100
commit8070c7f9eef373ad994c8a0b3f0ae62531bb5520 (patch)
tree908c2a021f76384598ee829d4e51afdbbf6a681c
parent0bec06b55d847a9faad66f5a3b8331a9eb6bde03 (diff)
downloadfiv-8070c7f9eef373ad994c8a0b3f0ae62531bb5520.tar.gz
fiv-8070c7f9eef373ad994c8a0b3f0ae62531bb5520.tar.xz
fiv-8070c7f9eef373ad994c8a0b3f0ae62531bb5520.zip
Make browser item spacing adjustable from CSS
-rw-r--r--fastiv-browser.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/fastiv-browser.c b/fastiv-browser.c
index 50c4676..0b70643 100644
--- a/fastiv-browser.c
+++ b/fastiv-browser.c
@@ -43,6 +43,7 @@ struct _FastivBrowser {
FastivIoThumbnailSize item_size; ///< Thumbnail size
int item_height; ///< Thumbnail height in pixels
+ int item_spacing; ///< Space between items in pixels
GArray *entries; ///< [Entry]
GArray *layouted_rows; ///< [Row]
@@ -60,10 +61,6 @@ typedef struct row Row;
static const double g_permitted_width_multiplier = 2;
-// Could be split out to also-idiomatic row-spacing/column-spacing properties.
-// TODO(p): Make a property for this.
-static const int g_item_spacing = 1;
-
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
struct entry {
@@ -106,7 +103,7 @@ static void
append_row(FastivBrowser *self, int *y, int x, GArray *items_array)
{
if (self->layouted_rows->len)
- *y += g_item_spacing;
+ *y += self->item_spacing;
*y += self->item_border_y;
g_array_append_val(self->layouted_rows, ((Row) {
@@ -143,8 +140,8 @@ relayout(FastivBrowser *self, int width)
2 * self->item_border_x;
if (!items->len) {
// Just insert it, whether or not there's any space.
- } else if (x + g_item_spacing + width <= available_width) {
- x += g_item_spacing;
+ } else if (x + self->item_spacing + width <= available_width) {
+ x += self->item_spacing;
} else {
append_row(self, &y,
padding.left + MAX(0, available_width - x) / 2, items);
@@ -661,6 +658,11 @@ fastiv_browser_style_updated(GtkWidget *widget)
GtkStyleContext *style = gtk_widget_get_style_context(widget);
GtkBorder border = {}, margin = {};
+ int item_spacing = self->item_spacing;
+ gtk_widget_style_get(widget, "spacing", &self->item_spacing, NULL);
+ if (item_spacing != self->item_spacing)
+ gtk_widget_queue_resize(widget);
+
// Using a pseudo-class, because GTK+ regions are deprecated.
gtk_style_context_save(style);
gtk_style_context_add_class(style, "item");
@@ -743,6 +745,12 @@ fastiv_browser_class_init(FastivBrowserClass *klass)
widget_class->motion_notify_event = fastiv_browser_motion_notify_event;
widget_class->style_updated = fastiv_browser_style_updated;
+ // Could be split to also-idiomatic row-spacing/column-spacing properties.
+ // The GParamSpec is sinked by this call.
+ gtk_widget_class_install_style_property(widget_class,
+ g_param_spec_int("spacing", "Spacing", "Space between items",
+ 0, G_MAXINT, 1, G_PARAM_READWRITE));
+
// TODO(p): Later override "screen_changed", recreate Pango layouts there,
// if we get to have any, or otherwise reflect DPI changes.
gtk_widget_class_set_css_name(widget_class, "fastiv-browser");