Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
collapsible_section.c
Go to the documentation of this file.
1/*
2 * This file is part of Ansel,
3 * Copyright (C) 2026 Aurélien PIERRE.
4 *
5 * Ansel is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * Ansel is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Ansel. If not, see <http://www.gnu.org/licenses/>.
17 */
18
20
21#include "widgets/expander.h"
22#include "widgets/label.h"
23#include "widgets/paint.h"
27
29{
30 if(active)
31 {
32 // We don't apply the GTK_STATE_SELECTED flag to the container here because it would
33 // be inherited by all children, which would mess up the state of checkboxes and togglebuttons.
34 dt_gui_add_class(GTK_WIDGET(cs->expander), "active");
35 }
36 else
37 {
40 }
41}
42
43static void _collapsible_container_show(GtkWidget *widget, gpointer user_data)
44{
45 /* Called whenever the container receives a "show" event, including from gtk_widget_show_all().
46 * If the toggle is not active the section should remain collapsed, so we re-hide the container
47 * immediately. By the time this fires, show_all has already recursed into the children and
48 * set their visible flags, so a later expand will find all children ready to display. */
51 gtk_widget_hide(widget);
52}
53
65
66static void _coeffs_expander_click(GtkWidget *widget, GdkEventButton *e, gpointer user_data)
67{
68 if(e->type == GDK_2BUTTON_PRESS || e->type == GDK_3BUTTON_PRESS) return;
69
71
72 const gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cs->toggle));
74 _collapsible_set_states(cs, !active);
75}
76
91
98
100 const char *confname, const char *label,
101 GtkBox *parent, GtkPackType pack)
102{
103 const gboolean expanded = dt_widget_stored_bool(confname);
104
105 cs->confname = confname;
106 cs->parent = parent;
107
108 // collapsible section header
110 GtkWidget *header_evb = gtk_event_box_new();
111 cs->label = dt_ui_section_label_new(label);
112 dt_gui_add_class(destdisp_head, "dt_section_expander");
113 gtk_container_add(GTK_CONTAINER(header_evb), cs->label);
114
118 dt_gui_add_class(cs->toggle, "dt_ignore_fg_state");
119
121 gtk_widget_set_name(GTK_WIDGET(cs->container), "collapsible");
124
126 /* gtk_widget_show_all() on the parent (called by lib modules after gui_init) recurses into
127 * the container and would override the collapsed state set by dtgtk_expander_set_expanded.
128 * Connect to "show" so we can re-apply the correct visibility right after show_all touches it. */
131 // Pack at the requested side so callers control ordering at insertion time.
132 if(pack == GTK_PACK_START)
134 else
137 gtk_widget_set_name(cs->expander, "collapse-block");
138
139 g_signal_connect(G_OBJECT(cs->toggle), "toggled",
140 G_CALLBACK(_coeffs_button_changed), (gpointer)cs);
141
142 g_signal_connect(G_OBJECT(header_evb), "button-release-event",
144 (gpointer)cs);
145}
146
147// clang-format off
148// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
149// vim: shiftwidth=2 expandtab tabstop=2 cindent
150// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
151// clang-format on
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
static void _collapsible_container_show(GtkWidget *widget, gpointer user_data)
void dt_gui_hide_collapsible_section(dt_gui_collapsible_section_t *cs)
void dt_gui_new_collapsible_section(dt_gui_collapsible_section_t *cs, const char *confname, const char *label, GtkBox *parent, GtkPackType pack)
Create a collapsible section and pack it into the parent box.
static void _coeffs_button_changed(GtkDarktableToggleButton *widget, gpointer user_data)
static void _collapsible_set_states(dt_gui_collapsible_section_t *cs, gboolean active)
static void _coeffs_expander_click(GtkWidget *widget, GdkEventButton *e, gpointer user_data)
void dt_gui_update_collapsible_section(dt_gui_collapsible_section_t *cs)
struct _GtkWidget GtkWidget
GtkWidget, opaque, spelled exactly as GTK spells it.
Definition colorspaces.h:98
void dtgtk_expander_set_expanded(GtkDarktableExpander *expander, gboolean expanded)
Definition expander.c:70
GtkWidget * dtgtk_expander_new(GtkWidget *header, GtkWidget *body)
Definition expander.c:101
#define DTGTK_EXPANDER(obj)
Definition expander.h:31
GtkWidget * dt_ui_section_label_new(const gchar *str)
Definition label.c:101
void dtgtk_togglebutton_set_paint(GtkDarktableToggleButton *button, DTGTKCairoPaintIconFunc paint, gint paintflags, void *paintdata)
GtkWidget * dtgtk_togglebutton_new(DTGTKCairoPaintIconFunc paint, gint paintflags, void *paintdata)
#define DTGTK_TOGGLEBUTTON(obj)
void dt_widget_store_bool(const char *key, gboolean value)
gboolean dt_widget_stored_bool(const char *key)
#define DT_GUI_BOX_SPACING
void dt_gui_remove_class(GtkWidget *widget, const gchar *class_name)
void dt_gui_add_class(GtkWidget *widget, const gchar *class_name)
void dtgtk_cairo_paint_solid_arrow(cairo_t *cr, gint x, int y, gint w, gint h, gint flags, void *data)
@ CPF_DIRECTION_LEFT
@ CPF_DIRECTION_DOWN