63 GtkStateFlags
state = gtk_widget_get_state_flags(widget);
66 GtkStyleContext *context = gtk_widget_get_style_context(widget);
67 gtk_style_context_get_color(context,
state, &fg_color);
73 const gboolean active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
80 const gboolean hasfocus = gtk_widget_has_focus(widget);
88 if(
state & GTK_STATE_FLAG_PRELIGHT)
91 flags &= ~CPF_PRELIGHT;
95 GtkAllocation allocation;
96 gtk_widget_get_allocation(widget, &allocation);
97 const int width = allocation.width;
98 const int height = allocation.height;
101 GtkBorder margin, border, padding;
102 gtk_style_context_get_margin(context,
state, &margin);
103 gtk_style_context_get_border(context,
state, &border);
104 gtk_style_context_get_padding(context,
state, &padding);
107 int startx = margin.left;
108 int starty = margin.top;
109 int cwidth =
width - margin.left - margin.right;
110 int cheight =
height - margin.top - margin.bottom;
113 gtk_render_background(context, cr, startx, starty, cwidth, cheight);
114 gtk_render_frame(context, cr, startx, starty, cwidth, cheight);
116 gdk_cairo_set_source_rgba(cr, &fg_color);
122 startx += border.left + padding.left;
123 starty += border.top + padding.top;
124 cwidth -= border.left + border.right + padding.left + padding.right;
125 cheight -= border.top + border.bottom + padding.top + padding.bottom;
131 GtkBorder cmargin = { 0 };
132 GtkWidget *canvas = gtk_bin_get_child(GTK_BIN(widget));
135 GtkStyleContext *ccontext = gtk_widget_get_style_context(canvas);
136 gtk_style_context_get_margin(ccontext,
state, &cmargin);
139 startx += round(cmargin.left * cwidth / 100.0f);
140 starty += round(cmargin.top * cheight / 100.0f);
141 cwidth = round((
float)cwidth * (1.0 - (cmargin.left + cmargin.right) / 100.0f));
142 cheight = round((
float)cheight * (1.0 - (cmargin.top + cmargin.bottom) / 100.0f));
146 if(cwidth > 0 && cheight > 0)
158 button->
icon = paint;
161 button->
canvas = gtk_drawing_area_new();
162 gtk_container_add(GTK_CONTAINER(button), button->
canvas);
164 gtk_widget_set_valign(GTK_WIDGET(button), GTK_ALIGN_CENTER);
165 gtk_widget_set_halign(GTK_WIDGET(button), GTK_ALIGN_CENTER);
166 gtk_widget_set_vexpand(GTK_WIDGET(button),
FALSE);
167 gtk_widget_set_hexpand(GTK_WIDGET(button),
FALSE);
173 static GType dtgtk_togglebutton_type = 0;
174 if(!dtgtk_togglebutton_type)
176 static const GTypeInfo dtgtk_togglebutton_info = {
183 dtgtk_togglebutton_type = g_type_register_static(GTK_TYPE_TOGGLE_BUTTON,
"GtkDarktableToggleButton",
184 &dtgtk_togglebutton_info, 0);
186 return dtgtk_togglebutton_type;
void(* DTGTKCairoPaintIconFunc)(cairo_t *cr, gint x, gint y, gint w, gint h, gint flags, void *data)