Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
label.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
19#include "widgets/label.h"
20
21#include "common/glib_utils.h" // dt_string_replace
22#include "system/macros.h" // IS_NULL_PTR
23#include "system/mem_alloc.h" // dt_free
24#include "widgets/widget_style.h" // dt_gui_add_class, dt_capitalize_label
25
26#include "system/macros.h" // IS_NULL_PTR
27#include "widgets/widget_settings.h" // DT_PIXEL_APPLY_DPI
28
30 GtkStyleContext *context)
31{
32 gint width = 16, height = 16;
34 // Icon themes only look up square icons: request the larger dimension,
35 // then scale the result down to the exact width/height below if the two differ.
38 if(IS_NULL_PTR(info)) return NULL;
39
43 g_object_unref(info);
44 if(IS_NULL_PTR(pixbuf)) return NULL;
45
47 {
50 pixbuf = scaled;
51 }
52
53 return pixbuf;
54}
55
56void dt_gui_set_symbolic_icon(GtkWidget *image, const char *icon_name, GtkIconSize size, const GdkRGBA *color)
57{
60
61 // Naming the icon and letting GTK draw it is the fallback for a theme that has no symbolic
62 // variant of it -- and now also for one whose variant failed to load, which used to leave the
63 // image showing nothing at all.
65 {
67 return;
68 }
69
72}
73
75gchar *delete_underscore(const char *s)
76{
77 return dt_string_replace(s, "_");
78}
79
87gchar *strip_markup(const char *s)
88{
89 if(IS_NULL_PTR(s)) return g_strdup("");
90
92 gchar *plain = NULL;
93
94 const gchar *underscore = "_";
95 gunichar mnemonic = underscore[0];
96 if(!pango_parse_markup(s, -1, mnemonic, &attrs, &plain, NULL, NULL))
98
100 return plain;
101}
102
105{
106 gtk_widget_set_halign(label, GTK_ALIGN_FILL); // make it span the whole available width
107 gtk_label_set_xalign (GTK_LABEL(label), 0.5f);
108 gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END); // ellipsize labels
109 dt_gui_add_class(label, "dt_section_label"); // make sure that we can style these easily
110}
111
115{
116 gchar *str_cpy = g_strdup(str);
121 return label;
122}
123
136
148
158
159// clang-format off
160// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
161// vim: shiftwidth=2 expandtab tabstop=2 cindent
162// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
163// clang-format on
struct _GtkWidget GtkWidget
GtkWidget, opaque, spelled exactly as GTK spells it.
Definition colorspaces.h:98
GdkRGBA color[]
Definition geotagging.c:541
static gchar * dt_string_replace(const char *string, const char *to_replace)
Definition glib_utils.h:64
GtkWidget * dt_ui_section_label_new(const gchar *str)
Definition label.c:114
gchar * delete_underscore(const char *s)
Definition label.c:75
GtkWidget * dt_ui_label_new(const gchar *str)
Definition label.c:125
void dt_gui_textview_set_padding(GtkTextView *textview)
Apply the standard recessed-input text padding to a GtkTextView.
Definition label.c:149
void dt_ellipsize_combo(GtkComboBox *cbox)
Definition label.c:137
GdkPixbuf * dt_gui_symbolic_icon_pixbuf(const char *icon_name, GtkIconSize size, const GdkRGBA *color, GtkStyleContext *context)
Load a symbolic icon as a pre-tinted pixbuf, at the pixel size size names.
Definition label.c:29
void dt_gui_set_symbolic_icon(GtkWidget *image, const char *icon_name, GtkIconSize size, const GdkRGBA *color)
Set a symbolic icon on an image widget, optionally forcing a specific color.
Definition label.c:56
void dt_ui_section_label_set(GtkWidget *label)
Definition label.c:104
gchar * strip_markup(const char *s)
Remove Pango/Gtk markup and accel mnemonics from a text label. If markup parsing fails,...
Definition label.c:87
#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 width
Definition mipmap_cache.c:0
uint32_t height
Definition mipmap_cache.c:1
size_t size
Definition mipmap_cache.c:3
#define MAX(a, b)
Definition thinplate.c:29
#define DT_PIXEL_APPLY_DPI(value)
void dt_capitalize_label(gchar *text)
void dt_gui_add_class(GtkWidget *widget, const gchar *class_name)