Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
scroll_wrap.c
Go to the documentation of this file.
1/*
2 * This file is part of Ansel,
3 * Copyright (C) 2026 Aurélien PIERRE.
4 * Copyright (C) 2026 Guillaume Stutin.
5 *
6 * Ansel is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Ansel is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Ansel. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "widgets/scroll_wrap.h"
21
22#include "system/macros.h" // IS_NULL_PTR
23#include "system/mem_alloc.h"
27#include <glib/gi18n.h>
28#include "widgets/container.h"
29
30static const char *const DT_GUI_WIDGET_AUTO_HEIGHT_KEY = "dt-gui-widget-auto-height";
31
32// ---- Resizable drawing area (the histogram-scope paradigm, made reusable) -------------------
33// A fixed-pixel-height GtkDrawingArea (or any widget sized by height-request) made vertically
34// resizable by the shared grip primitive, with the height persisted to config. Unlike the
35// scroll-wrap helper above, the content draws itself and is not scrolled; we only manage its
36// height-request, so the drawing code keeps reading the live allocation as usual.
37
38static const char *const DT_UI_RESIZABLE_AREA_KEY = "dt-ui-resizable-area";
39
41{
42 char *config_str; // conf key persisting the user-chosen height (px); owned
43 int min_height; // minimum height floor, device pixels
44 int last_height; // last applied height, shared with the drag handle
46
47/* The tallest run of whole rows that fits in `limit`, walked in display order.
48 *
49 * Rounding to a multiple of a nominal row height cannot answer this once a row is not that
50 * height: a separator is three pixels, so a list of four rows plus a separator rounds to five
51 * nominal rows and cuts the fifth in half -- which is the very thing the rounding exists to
52 * prevent. Returns TRUE once the limit is reached, so the recursion into expanded children can
53 * stop the walk. */
54static gboolean _treeview_fit_rows(GtkTreeView *treeview, GtkTreeModel *model, GtkTreeIter *parent,
55 const gint nominal, const gint limit, gint *used)
56{
57 if(!GTK_IS_TREE_MODEL(model)) return TRUE;
58
59 GtkTreeIter iter;
60 gboolean valid = parent ? gtk_tree_model_iter_children(model, &iter, parent)
61 : gtk_tree_model_get_iter_first(model, &iter);
62
63 while(valid)
64 {
65 GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
66
67 GdkRectangle rect = { 0 };
68 if(path) gtk_tree_view_get_background_area(treeview, path, NULL, &rect);
69 const gint row = rect.height > 0 ? rect.height : nominal;
70
71 if(*used + row > limit)
72 {
73 if(path) gtk_tree_path_free(path);
74 return TRUE;
75 }
76 *used += row;
77
78 if(path && gtk_tree_model_iter_has_child(model, &iter) && gtk_tree_view_row_expanded(treeview, path)
79 && _treeview_fit_rows(treeview, model, &iter, nominal, limit, used))
80 {
81 gtk_tree_path_free(path);
82 return TRUE;
83 }
84
85 if(path) gtk_tree_path_free(path);
86 valid = gtk_tree_model_iter_next(model, &iter);
87 }
88
89 return FALSE;
90}
91
93{
94 gint height = DT_PIXEL_APPLY_DPI(10);
95
96 if(GTK_IS_TREE_VIEW(w))
97 {
98 gint row_height = 0;
99
100 const gint num_columns = gtk_tree_view_get_n_columns(GTK_TREE_VIEW(w));
101 for(int c = 0; c < num_columns; c++)
102 {
103 gint cell_height = 0;
104 gtk_tree_view_column_cell_get_size(gtk_tree_view_get_column(GTK_TREE_VIEW(w), c),
105 NULL, NULL, NULL, NULL, &cell_height);
106 if(cell_height > row_height) row_height = cell_height;
107 }
108 GValue separation = { G_TYPE_INT };
109 gtk_widget_style_get_property(w, "vertical-separator", &separation);
110
111 if(row_height > 0) height = row_height + g_value_get_int(&separation);
112 }
113 else if(GTK_IS_TEXT_VIEW(w))
114 {
115 PangoLayout *layout = gtk_widget_create_pango_layout(w, "X");
116 pango_layout_get_pixel_size(layout, NULL, &height);
117 g_object_unref(layout);
118 }
119 else
120 {
121 GtkWidget *child = dt_gui_container_first_child(GTK_CONTAINER(w));
122 if(child)
123 {
124 height = gtk_widget_get_allocated_height(child);
125 }
126 }
127
128 return height;
129}
130
131// find the scrolled window parent of a treeview, if any
133{
134 if(!GTK_IS_WIDGET(w)) return NULL;
135
136 GtkWidget *parent = w;
137 while(parent)
138 {
139 if(GTK_IS_SCROLLED_WINDOW(parent)) break;
140 parent = gtk_widget_get_parent(parent);
141 }
142
143 return GTK_IS_SCROLLED_WINDOW(parent) ? parent : NULL;
144}
145
146// Counts only visible items (those whose parents are expanded)
147/* The height the visible rows actually occupy.
148 *
149 * Each row is measured rather than counted, because not every row is one nominal row tall: a
150 * GtkTreeView separator is drawn as a few pixels, and counting it as a row would claim a whole
151 * one of window height for it. gtk_tree_view_get_background_area() answers 0 for a view that is
152 * not realised yet, and those rows fall back to the nominal height -- which is what this did for
153 * every row before. */
154static int _treeview_visible_height(GtkTreeView *treeview, GtkTreeModel *model, GtkTreeIter *parent,
155 const gint nominal)
156{
157 if(!GTK_IS_TREE_MODEL(model)) return 0;
158
159 GtkTreeIter iter;
160 gboolean valid = parent ? gtk_tree_model_iter_children(model, &iter, parent)
161 : gtk_tree_model_get_iter_first(model, &iter);
162 int height = 0;
163
164 while(valid)
165 {
166 GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
167
168 GdkRectangle rect = { 0 };
169 if(path) gtk_tree_view_get_background_area(treeview, path, NULL, &rect);
170 height += rect.height > 0 ? rect.height : nominal;
171
172 // If this item is expanded, recursively measure its visible children
173 if(path && gtk_tree_model_iter_has_child(model, &iter) && gtk_tree_view_row_expanded(treeview, path))
174 height += _treeview_visible_height(treeview, model, &iter, nominal);
175
176 if(path) gtk_tree_path_free(path);
177
178 valid = gtk_tree_model_iter_next(model, &iter);
179 }
180
181 return height;
182}
183
185{
186 if(!GTK_IS_TEXT_VIEW(textview)) return 0;
187
188 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
189 if(!GTK_IS_TEXT_BUFFER(buffer)) return 0;
190
191 // For text views, use the number of logical lines in the buffer.
192 return MAX(0, gtk_text_buffer_get_line_count(buffer));
193}
194
196{
197 if(IS_NULL_PTR(state)) return;
198
199 GtkTreeModel *model = state->model;
200 if(model)
201 {
202 if(state->model_row_inserted) g_signal_handler_disconnect(model, state->model_row_inserted);
203 if(state->model_row_deleted) g_signal_handler_disconnect(model, state->model_row_deleted);
204 if(state->model_row_changed) g_signal_handler_disconnect(model, state->model_row_changed);
205 if(state->model_rows_reordered) g_signal_handler_disconnect(model, state->model_rows_reordered);
206 g_object_remove_weak_pointer(G_OBJECT(model), (gpointer *)&state->model);
207 }
208
209 if(GTK_IS_TREE_VIEW(treeview))
210 {
211 if(state->model_row_expanded) g_signal_handler_disconnect(treeview, state->model_row_expanded);
212 if(state->model_row_collapsed) g_signal_handler_disconnect(treeview, state->model_row_collapsed);
213 }
214
215 state->model = NULL;
216 state->model_row_inserted = 0;
217 state->model_row_deleted = 0;
218 state->model_row_changed = 0;
219 state->model_rows_reordered = 0;
220 state->model_row_expanded = 0;
221 state->model_row_collapsed = 0;
222}
223
225{
226 if(IS_NULL_PTR(state)) return;
227
228 GtkTextBuffer *buffer = state->buffer;
229 if(buffer)
230 {
231 if(state->buffer_changed) g_signal_handler_disconnect(buffer, state->buffer_changed);
232 g_object_remove_weak_pointer(G_OBJECT(buffer), (gpointer *)&state->buffer);
233 }
234
235 state->buffer = NULL;
236 state->buffer_changed = 0;
237}
238
247{
249 return win ? gtk_widget_get_allocated_height(win) : DT_PIXEL_APPLY_DPI(1000);
250}
251
263{
264 dt_gui_widget_auto_height_t *state = g_object_get_data(G_OBJECT(w), DT_GUI_WIDGET_AUTO_HEIGHT_KEY);
265 if(IS_NULL_PTR(state)) return;
266
268 if(!GTK_IS_SCROLLED_WINDOW(sw)) return;
269
270 const gint max_height = _resizable_scroll_max_height();
271 const gint min_size = MAX(1, state->min_size);
272 int stored = 0;
273 const gboolean has_conf = dt_widget_stored_int(state->config_str, &stored);
274
275 gint height;
276 gint increment = 0;
277
278 if(state->mode == DT_UI_RESIZE_STATIC)
279 {
280 // Fixed height: the persisted size -- the key's default in anselconfig.xml.in when it has one,
281 // since such a key is never unset -- or min_size without one. Independent of content,
282 // so a content refresh (e.g. on hovering another thumbnail) never shifts the layout.
283 height = CLAMP(has_conf ? stored : min_size, min_size, max_height);
284 }
285 else
286 {
287 // Dynamic: fit to content, capped by the user's persisted height (or the window ceiling).
288 const gboolean row_based = GTK_IS_TREE_VIEW(w) || GTK_IS_TEXT_VIEW(w);
289 increment = row_based ? _get_container_row_heigth(w) : 0;
290
291 gint content = 0;
292 if(GTK_IS_TREE_VIEW(w))
293 {
294 const int measured = _treeview_visible_height(GTK_TREE_VIEW(w), gtk_tree_view_get_model(GTK_TREE_VIEW(w)),
295 NULL, increment);
296 content = MAX(increment, measured);
297 }
298 else if(GTK_IS_TEXT_VIEW(w))
299 {
300 const int rows = _textview_count_visible_rows(w);
301 content = MAX(1, rows) * increment;
302 }
303 else
304 {
305 gtk_widget_get_preferred_height(w, NULL, &content);
306 }
307
308 /* One blank row past the last one, when the caller asked for it: a list filled edge to edge
309 * cannot be told from one with more rows hidden below, the blank row says it ends there. It
310 * only counts while everything fits -- a capped list snaps to its rows below and scrolls. */
311 if(row_based && state->trailing_row) content += increment;
312
313 const gint cap = has_conf ? CLAMP(stored, min_size, max_height) : max_height;
314 height = CLAMP(MIN(content, cap), min_size, max_height);
315
316 /* Snap to whole rows to avoid clipped half-rows -- but only when the area is showing less
317 * than it holds, which is the only case where a row can be cut. When everything fits, the
318 * measured height is already exact, and rounding it up would add most of a row of dead space
319 * for any content that is not a whole number of them, such as a list carrying a separator. */
320 if(increment > 0 && height < content)
321 {
322 if(GTK_IS_TREE_VIEW(w))
323 {
324 gint used = 0;
325 _treeview_fit_rows(GTK_TREE_VIEW(w), gtk_tree_view_get_model(GTK_TREE_VIEW(w)), NULL, increment,
326 height, &used);
327 if(used > 0) height = used;
328 }
329 else
330 {
331 // A textview's lines are all the one height, so a multiple of it is a row boundary.
332 height += increment - 1;
333 height -= height % increment;
334 }
335 }
336 }
337 state->last_height = height;
338
339 // The request covers the scrolled window's whole CSS box, and the viewport only gets what is
340 // left of it: padding AND border are both taken out first. Counting one and not the other
341 // leaves the content exactly that many pixels short of fitting, and an AUTOMATIC policy
342 // answers a two-pixel shortfall with a full scrollbar -- on an area whose whole purpose is to
343 // be sized to fit its content. The .dt_recessed_scroll treeviews carry both (2px padding over
344 // a 1px border), so this is not a hypothetical.
345 GtkStyleContext *sw_context = gtk_widget_get_style_context(sw);
346 const GtkStateFlags sw_state = gtk_widget_get_state_flags(sw);
347 GtkBorder padding;
348 GtkBorder border;
349 gtk_style_context_get_padding(sw_context, sw_state, &padding);
350 gtk_style_context_get_border(sw_context, sw_state, &border);
351
352 gint old_height = 0;
353 gtk_widget_get_size_request(sw, NULL, &old_height);
354 const gint new_height = height + padding.top + padding.bottom + border.top + border.bottom
355 + (GTK_IS_TEXT_VIEW(w) ? 2 : 0);
356 if(new_height != old_height)
357 gtk_widget_set_size_request(sw, -1, new_height);
358}
359
360static void _widget_auto_update(GtkWidget *widget)
361{
363}
364
365static gboolean _resizable_scroll_draw(GtkWidget *w, cairo_t *cr, gpointer user_data)
366{
368 return FALSE;
369}
370
371static void _resizable_scroll_realize(GtkWidget *w, gpointer user_data)
372{
374}
375
376// Drag handle accessors: bare (pre-padding) target height, kept consistent with the sizing rule.
377static int _resizable_scroll_handle_get_size(gpointer user_data)
378{
379 GtkWidget *w = GTK_WIDGET(user_data);
380 const dt_gui_widget_auto_height_t *state = g_object_get_data(G_OBJECT(w), DT_GUI_WIDGET_AUTO_HEIGHT_KEY);
381 return state ? state->last_height : 0;
382}
383
384static int _resizable_scroll_handle_resize(int requested_size, gboolean finished, gpointer user_data)
385{
386 GtkWidget *w = GTK_WIDGET(user_data);
387 dt_gui_widget_auto_height_t *state = g_object_get_data(G_OBJECT(w), DT_GUI_WIDGET_AUTO_HEIGHT_KEY);
388 if(IS_NULL_PTR(state) || IS_NULL_PTR(state->config_str)) return requested_size;
389
390 const gint value = CLAMP(requested_size, MAX(1, state->min_size), _resizable_scroll_max_height());
391 dt_widget_store_int(state->config_str, value);
393 return state->last_height;
394}
395
396static void _widget_auto_model_row_inserted(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
397 gpointer user_data)
398{
399 (void)model;
400 (void)path;
401 (void)iter;
402 _widget_auto_update(GTK_WIDGET(user_data));
403}
404
405static void _widget_auto_model_row_deleted(GtkTreeModel *model, GtkTreePath *path, gpointer user_data)
406{
407 (void)model;
408 (void)path;
409 _widget_auto_update(GTK_WIDGET(user_data));
410}
411
412static void _widget_auto_model_row_changed(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
413 gpointer user_data)
414{
415 (void)model;
416 (void)path;
417 (void)iter;
418 _widget_auto_update(GTK_WIDGET(user_data));
419}
420
421static void _widget_auto_model_rows_reordered(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
422 gint *new_order, gpointer user_data)
423{
424 (void)model;
425 (void)path;
426 (void)iter;
427 (void)new_order;
428 _widget_auto_update(GTK_WIDGET(user_data));
429}
430
431static void _widget_auto_model_row_expanded(GtkTreeView *tree_view, GtkTreeIter *expanded_iter, GtkTreePath *path,
432 gpointer user_data)
433{
434 (void)tree_view;
435 (void)expanded_iter;
436 (void)path;
437 _widget_auto_update(GTK_WIDGET(user_data));
438}
439
440static void _widget_auto_model_row_collapsed(GtkTreeView *tree_view, GtkTreeIter *collapsed_iter, GtkTreePath *path,
441 gpointer user_data)
442{
443 (void)tree_view;
444 (void)collapsed_iter;
445 (void)path;
446
447 // Recalculate tree view height after loading the data
448 _widget_auto_update(GTK_WIDGET(user_data));
449}
450
451static void _widget_auto_text_buffer_changed(GtkTextBuffer *buffer, gpointer user_data)
452{
453 (void)buffer;
454 _widget_auto_update(GTK_WIDGET(user_data));
455}
456
458{
459 if(!GTK_IS_TREE_VIEW(treeview)) return;
460
461 dt_gui_widget_auto_height_t *state = g_object_get_data(G_OBJECT(treeview), DT_GUI_WIDGET_AUTO_HEIGHT_KEY);
462 if(IS_NULL_PTR(state)) return;
463
464 GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
465 if(model == state->model) return;
466
468 if(!GTK_IS_TREE_MODEL(model)) return;
469
470 state->model = model;
471 g_object_add_weak_pointer(G_OBJECT(model), (gpointer *)&state->model);
472 state->model_row_inserted = g_signal_connect(model, "row-inserted",
473 G_CALLBACK(_widget_auto_model_row_inserted), treeview);
474 state->model_row_deleted = g_signal_connect(model, "row-deleted",
475 G_CALLBACK(_widget_auto_model_row_deleted), treeview);
476 state->model_row_changed = g_signal_connect(model, "row-changed",
477 G_CALLBACK(_widget_auto_model_row_changed), treeview);
478 state->model_rows_reordered = g_signal_connect(model, "rows-reordered",
479 G_CALLBACK(_widget_auto_model_rows_reordered), treeview);
480 state->model_row_expanded = g_signal_connect(treeview, "row-expanded",
481 G_CALLBACK(_widget_auto_model_row_expanded), treeview);
482 state->model_row_collapsed = g_signal_connect(treeview, "row-collapsed",
483 G_CALLBACK(_widget_auto_model_row_collapsed), treeview);
484}
485
487{
488 if(!GTK_IS_TEXT_VIEW(textview)) return;
489
490 dt_gui_widget_auto_height_t *state = g_object_get_data(G_OBJECT(textview), DT_GUI_WIDGET_AUTO_HEIGHT_KEY);
491 if(IS_NULL_PTR(state)) return;
492
493 GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
494 if(buffer == state->buffer) return;
495
497 if(!GTK_IS_TEXT_BUFFER(buffer)) return;
498
499 state->buffer = buffer;
500 g_object_add_weak_pointer(G_OBJECT(buffer), (gpointer *)&state->buffer);
501 state->buffer_changed = g_signal_connect(buffer, "changed",
502 G_CALLBACK(_widget_auto_text_buffer_changed), textview);
503}
504
505static void _widget_auto_on_model_changed(GObject *treeview, GParamSpec *pspec, gpointer user_data)
506{
507 (void)pspec;
508 (void)user_data;
509 _widget_auto_connect_model(GTK_WIDGET(treeview));
510 _widget_auto_update(GTK_WIDGET(treeview));
511}
512
513static void _widget_auto_on_buffer_changed(GObject *textview, GParamSpec *pspec, gpointer user_data)
514{
515 (void)pspec;
516 (void)user_data;
517 _widget_auto_connect_buffer(GTK_WIDGET(textview));
518 _widget_auto_update(GTK_WIDGET(textview));
519}
520
530
547GtkWidget *dt_ui_scroll_wrap(GtkWidget *w, gint min_size, const char *config_str, dt_ui_resize_mode_t mode)
548{
549 GtkWidget *sw = gtk_scrolled_window_new(NULL, NULL);
550 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
551 if(GTK_IS_TREE_VIEW(w)) dt_gui_add_class(sw, "dt_recessed_scroll");
552 gtk_container_add(GTK_CONTAINER(sw), w);
553
554 // Per-widget sizing state, freed with w.
555 dt_gui_widget_auto_height_t *state = calloc(1, sizeof(*state));
556 state->config_str = g_strdup(config_str);
557 state->min_size = MAX(1, DT_PIXEL_APPLY_DPI(min_size));
558 state->mode = mode;
559 g_object_set_data_full(G_OBJECT(w), DT_GUI_WIDGET_AUTO_HEIGHT_KEY, state, _widget_auto_height_free);
560
561 if(mode == DT_UI_RESIZE_DYNAMIC)
562 {
563 // Sizing triggers. Lists/textviews recompute from their model/buffer change signals (cheap and
564 // exact) plus a one-shot on realize, when row heights become accurate -- we deliberately avoid a
565 // per-draw recount, which would re-walk a large model on every redraw. Generic content has no
566 // such signals, so it recomputes on draw using its (GTK-cached) preferred height.
567 if(GTK_IS_TREE_VIEW(w))
568 {
569 g_signal_connect(w, "notify::model", G_CALLBACK(_widget_auto_on_model_changed), NULL);
570 g_signal_connect(w, "realize", G_CALLBACK(_resizable_scroll_realize), NULL);
571 }
572 else if(GTK_IS_TEXT_VIEW(w))
573 {
574 g_signal_connect(w, "notify::buffer", G_CALLBACK(_widget_auto_on_buffer_changed), NULL);
575 g_signal_connect(w, "realize", G_CALLBACK(_resizable_scroll_realize), NULL);
576 }
577 else
578 {
579 g_signal_connect(G_OBJECT(w), "draw", G_CALLBACK(_resizable_scroll_draw), NULL);
580 }
583 }
584 else
585 {
586 // Static: height is content-independent, so we only size once after realization (and on drag).
587 g_signal_connect(w, "realize", G_CALLBACK(_resizable_scroll_realize), NULL);
588 }
589
590 // Drag grip floating on the scrolled window's bottom edge (overlay): it takes no layout space,
591 // so the wrapper leaves no margin-like gap and stays aligned with neighbouring widgets. The grip
592 // is centered on the bottom border via CSS and is invisible until hovered.
593 GtkWidget *handle = dtgtk_resize_handle_new(GTK_ORIENTATION_VERTICAL, FALSE,
594 _("Drag to resize"),
597
598 GtkWidget *over = gtk_overlay_new();
599 gtk_container_add(GTK_CONTAINER(over), sw);
600 gtk_overlay_add_overlay(GTK_OVERLAY(over), handle);
601
603 return over;
604}
605
610{
611 if(!GTK_IS_CONTAINER(wrapper)) return NULL;
612 GList *children = gtk_container_get_children(GTK_CONTAINER(wrapper));
613 GtkWidget *sw = NULL;
614 for(GList *l = children; l; l = g_list_next(l))
615 {
616 if(GTK_IS_SCROLLED_WINDOW(l->data))
617 {
618 sw = GTK_WIDGET(l->data);
619 break;
620 }
621 }
622 g_list_free(children);
623 return sw;
624}
625
627{
629 = IS_NULL_PTR(content_widget) ? NULL : g_object_get_data(G_OBJECT(content_widget), DT_GUI_WIDGET_AUTO_HEIGHT_KEY);
630 if(IS_NULL_PTR(state)) return;
631
632 state->trailing_row = TRUE;
633 _widget_auto_update(content_widget);
634}
635
636static void _resizable_area_free(gpointer data)
637{
639 if(IS_NULL_PTR(state)) return;
640 g_free(state->config_str);
641 dt_free(state);
642}
643
644static int _resizable_area_get_size(gpointer user_data)
645{
646 GtkWidget *area = GTK_WIDGET(user_data);
647 const dt_ui_resizable_area_t *state = g_object_get_data(G_OBJECT(area), DT_UI_RESIZABLE_AREA_KEY);
648 if(state) return state->last_height;
649 return gtk_widget_get_allocated_height(area);
650}
651
652static int _resizable_area_resize(int requested_size, gboolean finished, gpointer user_data)
653{
654 GtkWidget *area = GTK_WIDGET(user_data);
655 dt_ui_resizable_area_t *state = g_object_get_data(G_OBJECT(area), DT_UI_RESIZABLE_AREA_KEY);
656 if(IS_NULL_PTR(state)) return requested_size;
657
658 const int height = CLAMP(requested_size, MAX(1, state->min_height), _resizable_scroll_max_height());
659 state->last_height = height;
660 gtk_widget_set_size_request(area, -1, height);
661 if(finished) dt_widget_store_int(state->config_str, height);
662 return height;
663}
664
665GtkWidget *dt_ui_resizable_drawing_area(GtkWidget *area, char *config_str, int default_height, int min_height)
666{
667 dt_ui_resizable_area_t *state = calloc(1, sizeof(*state));
668 state->config_str = g_strdup(config_str);
669 state->min_height = MAX(1, DT_PIXEL_APPLY_DPI(min_height));
670
671 int height = DT_PIXEL_APPLY_DPI(default_height);
672 dt_widget_stored_int(config_str, &height);
673 height = CLAMP(height, state->min_height, _resizable_scroll_max_height());
674 state->last_height = height;
675 g_object_set_data_full(G_OBJECT(area), DT_UI_RESIZABLE_AREA_KEY, state, _resizable_area_free);
676 gtk_widget_set_size_request(area, -1, height);
677
678 // Drag grip floating on the area's bottom edge (an overlay, not a packed sibling), so it takes
679 // no layout space -- the area stays flush with neighbouring widgets, no margin-like gap. It sits
680 // over the graph's bottom inset/axis margin (graphs reserve one), invisible until hovered.
681 GtkWidget *handle = dtgtk_resize_handle_new(GTK_ORIENTATION_VERTICAL, FALSE,
682 _("Drag to resize"),
684
685 GtkWidget *over = gtk_overlay_new();
686 gtk_container_add(GTK_CONTAINER(over), area);
687 gtk_overlay_add_overlay(GTK_OVERLAY(over), handle);
688 return over;
689}
690
691// clang-format off
692// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
693// vim: shiftwidth=2 expandtab tabstop=2 cindent
694// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
695// clang-format on
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
struct _GtkWidget GtkWidget
GtkWidget, opaque, spelled exactly as GTK spells it.
Definition colorspaces.h:98
static const int row
GtkWidget * dt_gui_container_first_child(GtkContainer *container)
Definition container.c:43
dev roi_request value
void * data
Definition geometry.h:111
const char * model
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition macros.h:96
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
Definition mem_alloc.h:171
uint32_t height
Definition mipmap_cache.c:1
g_free(manifest_path)
GtkWidget * dtgtk_resize_handle_new(GtkOrientation orientation, gboolean invert, const char *tooltip, dtgtk_resize_handle_get_size_f get_size, dtgtk_resize_handle_resize_f resize, gpointer user_data)
Create a themed handle widget driving one-dimensional resize gestures.
static void _widget_auto_model_rows_reordered(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gint *new_order, gpointer user_data)
void dt_ui_scroll_wrap_reserve_trailing_row(GtkWidget *content_widget)
Make a DT_UI_RESIZE_DYNAMIC list or text view ask for one blank row past its content.
static int _resizable_scroll_handle_resize(int requested_size, gboolean finished, gpointer user_data)
static void _widget_auto_on_buffer_changed(GObject *textview, GParamSpec *pspec, gpointer user_data)
static int _textview_count_visible_rows(GtkWidget *textview)
static int _resizable_area_resize(int requested_size, gboolean finished, gpointer user_data)
static void _widget_auto_connect_model(GtkWidget *treeview)
static void _widget_auto_model_row_expanded(GtkTreeView *tree_view, GtkTreeIter *expanded_iter, GtkTreePath *path, gpointer user_data)
static void _widget_auto_model_row_changed(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
GtkWidget * dt_ui_resizable_drawing_area(GtkWidget *area, char *config_str, int default_height, int min_height)
Make a self-drawing widget (typically a GtkDrawingArea graph or scope) vertically resizable.
static int _resizable_area_get_size(gpointer user_data)
static gint _get_container_row_heigth(GtkWidget *w)
Definition scroll_wrap.c:92
static void _widget_auto_connect_buffer(GtkWidget *textview)
static void _resizable_scroll_realize(GtkWidget *w, gpointer user_data)
static int _treeview_visible_height(GtkTreeView *treeview, GtkTreeModel *model, GtkTreeIter *parent, const gint nominal)
static void _widget_auto_height_free(gpointer data)
static void _widget_auto_model_row_collapsed(GtkTreeView *tree_view, GtkTreeIter *collapsed_iter, GtkTreePath *path, gpointer user_data)
static int _resizable_scroll_handle_get_size(gpointer user_data)
static void _widget_auto_model_row_deleted(GtkTreeModel *model, GtkTreePath *path, gpointer user_data)
static gboolean _treeview_fit_rows(GtkTreeView *treeview, GtkTreeModel *model, GtkTreeIter *parent, const gint nominal, const gint limit, gint *used)
Definition scroll_wrap.c:54
static void _widget_auto_disconnect_buffer(dt_gui_widget_auto_height_t *state)
static GtkWidget * _search_parent_scrolled_window(GtkWidget *w)
GtkWidget * dt_ui_scroll_wrap_get_scrolled_window(GtkWidget *wrapper)
Return the inner scrolled window of a dt_ui_scroll_wrap() wrapper, or NULL.
static void _widget_auto_text_buffer_changed(GtkTextBuffer *buffer, gpointer user_data)
static gint _resizable_scroll_max_height(void)
Window-height ceiling shared by the auto-size rule and the drag handle.
static void _resizable_area_free(gpointer data)
static const char *const DT_GUI_WIDGET_AUTO_HEIGHT_KEY
Definition scroll_wrap.c:30
static void _widget_auto_model_row_inserted(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
GtkWidget * dt_ui_scroll_wrap(GtkWidget *w, gint min_size, const char *config_str, dt_ui_resize_mode_t mode)
Wrap a scrollable content widget in a recessed, vertically resizable scrolled window.
static void _widget_auto_on_model_changed(GObject *treeview, GParamSpec *pspec, gpointer user_data)
static void _resizable_scroll_apply(GtkWidget *w)
The single sizing rule for every dt_ui_scroll_wrap area.
static void _widget_auto_update(GtkWidget *widget)
static const char *const DT_UI_RESIZABLE_AREA_KEY
Definition scroll_wrap.c:38
static void _widget_auto_disconnect_model(dt_gui_widget_auto_height_t *state, GtkWidget *treeview)
static gboolean _resizable_scroll_draw(GtkWidget *w, cairo_t *cr, gpointer user_data)
dt_ui_resize_mode_t
Definition scroll_wrap.h:40
@ DT_UI_RESIZE_STATIC
Definition scroll_wrap.h:47
@ DT_UI_RESIZE_DYNAMIC
Definition scroll_wrap.h:43
const float uint32_t state[4]
#define MIN(a, b)
Definition thinplate.c:32
#define MAX(a, b)
Definition thinplate.c:29
GtkWidget * dt_widget_root_window(void)
gboolean dt_widget_stored_int(const char *key, int *value)
void dt_widget_store_int(const char *key, int value)
#define DT_PIXEL_APPLY_DPI(value)
void dt_gui_add_class(GtkWidget *widget, const gchar *class_name)