Skip to content

Commit

Permalink
prepare to migrate box
Browse files Browse the repository at this point in the history
  • Loading branch information
dterrahe committed Oct 3, 2024
1 parent dc9fb84 commit 3784a4b
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 230 deletions.
2 changes: 2 additions & 0 deletions src/gui/accelerators.c
Original file line number Diff line number Diff line change
Expand Up @@ -5162,6 +5162,7 @@ GtkWidget *dt_action_button_new(dt_lib_module_t *self,
GdkModifierType mods)
{
GtkWidget *button = gtk_button_new_with_label(Q_(label));
gtk_widget_set_hexpand(button, TRUE);
gtk_label_set_ellipsize(GTK_LABEL(gtk_bin_get_child(GTK_BIN(button))),
PANGO_ELLIPSIZE_END);
if(tooltip) gtk_widget_set_tooltip_text(button, tooltip);
Expand All @@ -5188,6 +5189,7 @@ GtkWidget *dt_action_entry_new(dt_action_t *ac,
const gchar *text)
{
GtkWidget *entry = dt_ui_entry_new(5);
gtk_widget_set_hexpand(entry, TRUE);
if(text)
gtk_entry_set_text (GTK_ENTRY(entry), text);
if(tooltip)
Expand Down
8 changes: 8 additions & 0 deletions src/gui/gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -4379,6 +4379,14 @@ void dt_gui_process_events()
continue;
}

GtkWidget *(dt_gui_box_add)(GtkBox *box, gpointer *list)
{
for(; *list; list++)
gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(*list));

return GTK_WIDGET(box);
}

// clang-format off
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
// vim: shiftwidth=2 expandtab tabstop=2 cindent
Expand Down
9 changes: 6 additions & 3 deletions src/gui/gtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,7 @@ static inline GtkWidget *dt_ui_section_label_new(const gchar *str)
static inline GtkWidget *dt_ui_label_new(const gchar *str)
{
GtkWidget *label = gtk_label_new(str);
gtk_widget_set_halign(label, GTK_ALIGN_START);
gtk_label_set_xalign (GTK_LABEL(label), 0.0f);
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END);
g_object_set(label, "halign", GTK_ALIGN_START, "xalign", 0.0f, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
return label;
};

Expand Down Expand Up @@ -569,6 +567,11 @@ void dt_gui_cursor_clear_busy();
// (i.e. the current function will do a lot of work before returning)
void dt_gui_process_events();

GtkWidget *(dt_gui_box_add)(GtkBox *box, gpointer list[]);
#define dt_gui_box_add(box, ...) dt_gui_box_add(GTK_BOX(box), (gpointer[]){ __VA_ARGS__, NULL })
#define dt_gui_hbox(...) dt_gui_box_add(gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0), __VA_ARGS__)
#define dt_gui_vbox(...) dt_gui_box_add(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0), __VA_ARGS__)

#ifdef __cplusplus
} // extern "C"
#endif /* __cplusplus */
Expand Down
22 changes: 3 additions & 19 deletions src/imageio/format/avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,6 @@ void gui_init(dt_imageio_module_format_t *self)

self->gui_data = (void *)gui;

self->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);

/*
* Bit depth combo box
*/
Expand All @@ -850,8 +848,6 @@ void gui_init(dt_imageio_module_format_t *self)
gtk_widget_set_tooltip_text(gui->bit_depth,
_("color information stored in an image, higher is better"));

gtk_box_pack_start(GTK_BOX(self->widget), gui->bit_depth, TRUE, TRUE, 0);

/*
* Color mode combo box
*/
Expand All @@ -862,8 +858,6 @@ void gui_init(dt_imageio_module_format_t *self)
dt_bauhaus_combobox_set_default(gui->color_mode,
dt_confgen_get_bool("plugins/imageio/format/avif/color_mode", DT_DEFAULT));

gtk_box_pack_start(GTK_BOX(self->widget), gui->color_mode, TRUE, TRUE, 0);

/*
* Tiling combo box
*/
Expand All @@ -873,11 +867,6 @@ void gui_init(dt_imageio_module_format_t *self)
"the loss of image quality is negligible."),
tiling, tiling_changed, self,
N_("on"), N_("off"));
gtk_box_pack_start(GTK_BOX(self->widget),
gui->tiling,
TRUE,
TRUE,
0);

/*
* Compression type combo box
Expand All @@ -898,12 +887,6 @@ void gui_init(dt_imageio_module_format_t *self)
dt_bauhaus_combobox_set_default(gui->compression_type,
dt_confgen_get_int("plugins/imageio/format/avif/compression_type", DT_DEFAULT));

gtk_box_pack_start(GTK_BOX(self->widget),
gui->compression_type,
TRUE,
TRUE,
0);

/*
* Quality combo box
*/
Expand All @@ -924,8 +907,6 @@ void gui_init(dt_imageio_module_format_t *self)

dt_bauhaus_slider_set(gui->quality, quality);

gtk_box_pack_start(GTK_BOX(self->widget), gui->quality, TRUE, TRUE, 0);

gtk_widget_set_visible(gui->quality, compression_type != AVIF_COMP_LOSSLESS);
gtk_widget_set_no_show_all(gui->quality, TRUE);

Expand All @@ -941,6 +922,9 @@ void gui_init(dt_imageio_module_format_t *self)
"value-changed",
G_CALLBACK(quality_changed),
NULL);

self->widget = dt_gui_vbox(gui->bit_depth, gui->color_mode, gui->tiling,
gui->compression_type, gui->quality);
}

void gui_cleanup(dt_imageio_module_format_t *self)
Expand Down
5 changes: 2 additions & 3 deletions src/imageio/format/j2k.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ void gui_init(dt_imageio_module_format_t *self)
{
dt_imageio_j2k_gui_t *gui = (dt_imageio_j2k_gui_t *)malloc(sizeof(dt_imageio_j2k_gui_t));
self->gui_data = (void *)gui;
self->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);

const int preset_last = dt_conf_get_int("plugins/imageio/format/j2k/preset");
const int quality_last = dt_conf_get_int("plugins/imageio/format/j2k/quality");
Expand All @@ -673,7 +672,6 @@ void gui_init(dt_imageio_module_format_t *self)
0);
dt_bauhaus_widget_set_label(gui->quality, NULL, N_("quality"));
dt_bauhaus_slider_set(gui->quality, quality_last);
gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(gui->quality), TRUE, TRUE, 0);
g_signal_connect(G_OBJECT(gui->quality), "value-changed", G_CALLBACK(quality_changed), NULL);

DT_BAUHAUS_COMBOBOX_NEW_FULL(gui->preset, self, NULL, N_("DCP mode"), NULL,
Expand All @@ -682,7 +680,8 @@ void gui_init(dt_imageio_module_format_t *self)
N_("Cinema2K, 24FPS"),
N_("Cinema2K, 48FPS"),
N_("Cinema4K, 24FPS"));
gtk_box_pack_start(GTK_BOX(self->widget), gui->preset, TRUE, TRUE, 0);

self->widget = dt_gui_vbox(gui->quality, gui->preset);

// TODO: options for "off"
}
Expand Down
6 changes: 1 addition & 5 deletions src/imageio/format/jpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,6 @@ void gui_init(dt_imageio_module_format_t *self)
dt_conf_get_int("plugins/imageio/format/jpeg/subsample");

// construct gui with jpeg specific options:
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
self->widget = box;
// quality slider
g->quality = dt_bauhaus_slider_new_with_range
((dt_iop_module_t*)self,
Expand All @@ -582,7 +580,6 @@ void gui_init(dt_imageio_module_format_t *self)

dt_bauhaus_widget_set_label(g->quality, NULL, N_("quality"));
dt_bauhaus_slider_set(g->quality, dt_conf_get_int("plugins/imageio/format/jpeg/quality"));
gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(g->quality), TRUE, TRUE, 0);
g_signal_connect(G_OBJECT(g->quality), "value-changed",
G_CALLBACK(quality_changed), NULL);

Expand All @@ -602,8 +599,7 @@ void gui_init(dt_imageio_module_format_t *self)
self,
N_("auto"), N_("4:4:4"), N_("4:4:0"), N_("4:2:2"), N_("4:2:0"));

gtk_box_pack_start(GTK_BOX(box), g->subsample, TRUE, TRUE, 0);

self->widget = dt_gui_vbox(g->quality, g->subsample);
}

void gui_cleanup(dt_imageio_module_format_t *self)
Expand Down
12 changes: 3 additions & 9 deletions src/imageio/format/jxl.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,17 +570,13 @@ void gui_init(dt_imageio_module_format_t *self)
if(!gui) return;
self->gui_data = gui;

GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
self->widget = box;

// bits per sample combobox
const int bpp_enum = _bpp_to_enum(dt_conf_get_int("plugins/imageio/format/jxl/bpp"));

DT_BAUHAUS_COMBOBOX_NEW_FULL(gui->bpp, self, NULL, N_("bit depth"),
NULL, bpp_enum, bpp_changed, gui,
N_("8 bit"), N_("10 bit"), N_("12 bit"),
N_("16 bit"), N_("32 bit (float)"));
gtk_box_pack_start(GTK_BOX(box), gui->bpp, TRUE, TRUE, 0);

// pixel type combobox
const int pixel_type = dt_conf_get_bool("plugins/imageio/format/jxl/pixel_type") & 1;
Expand All @@ -591,7 +587,6 @@ void gui_init(dt_imageio_module_format_t *self)
dt_bauhaus_combobox_set_default(gui->pixel_type,
dt_confgen_get_bool("plugins/imageio/format/jxl/pixel_type",
DT_DEFAULT) & 1);
gtk_box_pack_start(GTK_BOX(box), gui->pixel_type, TRUE, TRUE, 0);

gtk_widget_set_visible(gui->pixel_type, bpp_enum == 3);
gtk_widget_set_no_show_all(gui->pixel_type, TRUE);
Expand All @@ -609,7 +604,6 @@ void gui_init(dt_imageio_module_format_t *self)
_("the quality of the output image\n0-29 = very lossy\n30-99 = JPEG "
"quality comparable\n100 = lossless"));
g_signal_connect(G_OBJECT(gui->quality), "value-changed", G_CALLBACK(quality_changed), gui);
gtk_box_pack_start(GTK_BOX(box), gui->quality, TRUE, TRUE, 0);

// encoding color profile combobox
const int original = dt_conf_get_bool("plugins/imageio/format/jxl/original") & 1;
Expand All @@ -623,7 +617,6 @@ void gui_init(dt_imageio_module_format_t *self)
dt_bauhaus_combobox_set_default(gui->original,
dt_confgen_get_bool("plugins/imageio/format/jxl/original",
DT_DEFAULT) & 1);
gtk_box_pack_start(GTK_BOX(box), gui->original, TRUE, TRUE, 0);

gtk_widget_set_visible(gui->original, quality < 100);
gtk_widget_set_no_show_all(gui->original, TRUE);
Expand All @@ -639,7 +632,6 @@ void gui_init(dt_imageio_module_format_t *self)
_("the effort used to encode the image, higher efforts will have "
"better results at the expense of longer encoding times"));
g_signal_connect(G_OBJECT(gui->effort), "value-changed", G_CALLBACK(effort_changed), NULL);
gtk_box_pack_start(GTK_BOX(box), gui->effort, TRUE, TRUE, 0);

// decoding speed (tier) slider
gui->tier = dt_bauhaus_slider_new_with_range(
Expand All @@ -651,7 +643,9 @@ void gui_init(dt_imageio_module_format_t *self)
gtk_widget_set_tooltip_text(gui->tier,
_("the preferred decoding speed with some sacrifice of quality"));
g_signal_connect(G_OBJECT(gui->tier), "value-changed", G_CALLBACK(tier_changed), NULL);
gtk_box_pack_start(GTK_BOX(box), gui->tier, TRUE, TRUE, 0);

self->widget = dt_gui_vbox(gui->bpp, gui->pixel_type, gui->quality,
gui->original, gui->effort, gui->tier);
}

void gui_cleanup(dt_imageio_module_format_t *self)
Expand Down
6 changes: 2 additions & 4 deletions src/imageio/format/png.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,15 +624,12 @@ void gui_init(dt_imageio_module_format_t *self)
if(dt_conf_key_exists("plugins/imageio/format/png/compression"))
compression = dt_conf_get_int("plugins/imageio/format/png/compression");

self->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);

// Bit depth combo box
DT_BAUHAUS_COMBOBOX_NEW_FULL(gui->bit_depth, self, NULL, N_("bit depth"), NULL,
0, bit_depth_changed, self,
N_("8 bit"), N_("16 bit"));
if(bpp == 16)
dt_bauhaus_combobox_set(gui->bit_depth, 1);
gtk_box_pack_start(GTK_BOX(self->widget), gui->bit_depth, TRUE, TRUE, 0);

// Compression level slider
gui->compression = dt_bauhaus_slider_new_with_range((dt_iop_module_t*)self,
Expand All @@ -643,8 +640,9 @@ void gui_init(dt_imageio_module_format_t *self)
0);
dt_bauhaus_widget_set_label(gui->compression, NULL, N_("compression"));
dt_bauhaus_slider_set(gui->compression, compression);
gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(gui->compression), TRUE, TRUE, 0);
g_signal_connect(G_OBJECT(gui->compression), "value-changed", G_CALLBACK(compression_level_changed), NULL);

self->widget = dt_gui_vbox(gui->bit_depth, gui->compression);
}

void gui_cleanup(dt_imageio_module_format_t *self)
Expand Down
10 changes: 2 additions & 8 deletions src/imageio/format/tiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,16 +876,12 @@ void gui_init(dt_imageio_module_format_t *self)
const int compresslevel = dt_conf_get_int("plugins/imageio/format/tiff/compresslevel");
const int shortmode = dt_conf_get_bool("plugins/imageio/format/tiff/shortfile");

self->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);

// Bit depth combo box
DT_BAUHAUS_COMBOBOX_NEW_FULL(gui->bpp, self, NULL, N_("bit depth"), NULL,
bpp == 16 ? 1
: bpp == 32 ? 2
: 0,
bpp_combobox_changed, gui, N_("8 bit"), N_("16 bit"), N_("32 bit (float)"));
gtk_box_pack_start(GTK_BOX(self->widget), gui->bpp, TRUE, TRUE, 0);


// Pixel format combo box
DT_BAUHAUS_COMBOBOX_NEW_FULL(gui->pixelformat, self, NULL, N_("pixel type"), NULL, pixelformat,
Expand All @@ -897,7 +893,6 @@ void gui_init(dt_imageio_module_format_t *self)
#else
gtk_widget_set_visible(gui->pixelformat, FALSE);
#endif
gtk_box_pack_start(GTK_BOX(self->widget), gui->pixelformat, TRUE, TRUE, 0);

gtk_widget_set_no_show_all(gui->pixelformat, TRUE);

Expand All @@ -907,7 +902,6 @@ void gui_init(dt_imageio_module_format_t *self)
N_("deflate with predictor"));
dt_bauhaus_combobox_set_default(gui->compress,
dt_confgen_get_int("plugins/imageio/format/tiff/compress", DT_DEFAULT));
gtk_box_pack_start(GTK_BOX(self->widget), gui->compress, TRUE, TRUE, 0);

// Compression level slider
gui->compresslevel = dt_bauhaus_slider_new_with_range(
Expand All @@ -916,7 +910,6 @@ void gui_init(dt_imageio_module_format_t *self)
dt_confgen_get_int("plugins/imageio/format/tiff/compresslevel", DT_DEFAULT), 0);
dt_bauhaus_widget_set_label(gui->compresslevel, NULL, N_("compression level"));
dt_bauhaus_slider_set(gui->compresslevel, compresslevel);
gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(gui->compresslevel), TRUE, TRUE, 0);
g_signal_connect(G_OBJECT(gui->compresslevel), "value-changed", G_CALLBACK(compress_level_changed), NULL);

gtk_widget_set_visible(gui->compresslevel, compress != 0);
Expand All @@ -928,7 +921,8 @@ void gui_init(dt_imageio_module_format_t *self)
shortfile_combobox_changed, self, N_("no"), N_("yes"));
dt_bauhaus_combobox_set_default(gui->shortfiles,
dt_confgen_get_bool("plugins/imageio/format/tiff/shortfile", DT_DEFAULT));
gtk_box_pack_start(GTK_BOX(self->widget), gui->shortfiles, TRUE, TRUE, 0);

self->widget = dt_gui_vbox(gui->bpp, gui->pixelformat, gui->compress, gui->compresslevel, gui->shortfiles);
}

void gui_cleanup(dt_imageio_module_format_t *self)
Expand Down
5 changes: 2 additions & 3 deletions src/imageio/format/webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ void gui_init(dt_imageio_module_format_t *self)
DT_BAUHAUS_COMBOBOX_NEW_FULL(gui->compression, self, NULL, N_("compression"), NULL,
comp_type, compression_changed, self,
N_("lossy"), N_("lossless"));
gtk_box_pack_start(GTK_BOX(self->widget), gui->compression, TRUE, TRUE, 0);

gui->quality = dt_bauhaus_slider_new_with_range((dt_iop_module_t*)self,
dt_confgen_get_int("plugins/imageio/format/webp/quality", DT_MIN),
Expand All @@ -427,7 +426,6 @@ void gui_init(dt_imageio_module_format_t *self)
"for lossless, 0 is the fastest but gives larger files compared\n"
"to the slowest 100."));
dt_bauhaus_slider_set(gui->quality, quality);
gtk_box_pack_start(GTK_BOX(self->widget), gui->quality, TRUE, TRUE, 0);
g_signal_connect(G_OBJECT(gui->quality), "value-changed", G_CALLBACK(quality_changed), NULL);

gtk_widget_set_visible(gui->quality, comp_type != webp_lossless);
Expand All @@ -440,7 +438,8 @@ void gui_init(dt_imageio_module_format_t *self)
"graphic: discrete tone image (graph, map-tile etc)"),
hint, hint_combobox_changed, self,
N_("default"), N_("picture"), N_("photo"), N_("graphic"));
gtk_box_pack_start(GTK_BOX(self->widget), gui->hint, TRUE, TRUE, 0);

self->widget = dt_gui_vbox(gui->compression, gui->quality, gui->hint);
}

void gui_cleanup(dt_imageio_module_format_t *self)
Expand Down
4 changes: 1 addition & 3 deletions src/imageio/format/xcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,12 @@ void gui_init(dt_imageio_module_format_t *self)
bpp = atoi(conf_bpp);
}

self->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);

// Bit depth combo box
DT_BAUHAUS_COMBOBOX_NEW_FULL(gui->bpp, self, NULL, N_("bit depth"), NULL,
bpp == 16 ? 1 : bpp == 32 ? 2 : 0,
bpp_combobox_changed, NULL,
N_("8 bit"), N_("16 bit"), N_("32 bit (float)"));
gtk_box_pack_start(GTK_BOX(self->widget), gui->bpp, TRUE, TRUE, 0);
self->widget = dt_gui_vbox(gui->bpp);
}

void gui_cleanup(dt_imageio_module_format_t *self)
Expand Down
9 changes: 2 additions & 7 deletions src/imageio/storage/disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,6 @@ void gui_init(dt_imageio_module_storage_t *self)
{
disk_t *d = (disk_t *)malloc(sizeof(disk_t));
self->gui_data = (void *)d;
self->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);

GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start(GTK_BOX(self->widget), GTK_WIDGET(hbox), TRUE, FALSE, 0);

d->entry =
GTK_ENTRY(dt_action_entry_new
Expand All @@ -269,12 +265,10 @@ void gui_init(dt_imageio_module_storage_t *self)
dt_conf_get_string_const("plugins/imageio/storage/disk/file_directory")));
dt_gtkentry_setup_completion(d->entry, dt_gtkentry_get_default_path_compl_list());
gtk_editable_set_position(GTK_EDITABLE(d->entry), -1);
gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(d->entry), TRUE, TRUE, 0);

GtkWidget *widget = dtgtk_button_new(dtgtk_cairo_paint_directory, CPF_NONE, NULL);
gtk_widget_set_name(widget, "non-flat");
gtk_widget_set_tooltip_text(widget, _("select directory"));
gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(widget), "clicked", G_CALLBACK(button_clicked), self);

DT_BAUHAUS_COMBOBOX_NEW_FULL(d->onsave_action, self, NULL, N_("on conflict"), NULL,
Expand All @@ -284,7 +278,8 @@ void gui_init(dt_imageio_module_storage_t *self)
N_("overwrite"),
N_("overwrite if changed"),
N_("skip"));
gtk_box_pack_start(GTK_BOX(self->widget), d->onsave_action, TRUE, TRUE, 0);

self->widget = dt_gui_vbox(dt_gui_hbox(d->entry, widget), d->onsave_action);
}

void gui_cleanup(dt_imageio_module_storage_t *self)
Expand Down
Loading

0 comments on commit 3784a4b

Please sign in to comment.