v1.2.1: widget_builder now only lets you assign classes. The name will be consistent with the image escape system

This commit is contained in:
Scoopta 2020-07-28 16:18:44 -07:00
parent 203800e9aa
commit cd61e73f20
5 changed files with 35 additions and 19 deletions

View File

@ -30,9 +30,9 @@ void wofi_widget_builder_set_search_text(struct widget_builder* builder, char* s
void wofi_widget_builder_set_action(struct widget_builder* builder, char* action);
void wofi_widget_builder_insert_text(struct widget_builder* builder, const char* text, char* css_name);
__attribute__((sentinel)) void wofi_widget_builder_insert_text(struct widget_builder* builder, const char* text, ...);
void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, char* css_name);
__attribute__((sentinel)) void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, ...);
struct widget_builder* wofi_widget_builder_get_idx(struct widget_builder* builder, size_t idx);

View File

@ -36,7 +36,7 @@ Sets the action for the widget specified by the builder
\- The text to set as the action
.TP
.B void wofi_widget_builder_insert_text(struct widget_builder* builder, char* text, char* css_name)
.B void wofi_widget_builder_insert_text(struct widget_builder* builder, char* text, ...)
Inserts text into the widget specified by the builder
.B struct widget_builder* builder
@ -45,8 +45,8 @@ Inserts text into the widget specified by the builder
.B char* text
\- The text to add to the widget
.B char* css_name
\- The name of the CSS node for this text. The name that will be assigned is #mode_name-css_name where mode_name is the name of the mode, i.e. drun etc.
.B ...
\- The names of the CSS classes for this text. The class that will be assigned is .mode_name-css_name where mode_name is the name of the mode, i.e. drun etc. This should have a NULL sentinel
.TP
.B void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, char* css_name)
@ -58,8 +58,8 @@ Inserts an image into the widget specified by the builder
.B GdkPixbuf* pixbuf
\- The image to add to the widget
.B char* css_name
\- The name of the CSS node for this image. The name that will be assigned is #mode_name-css_name where mode_name is the name of the mode, i.e. drun etc.
.B ...
\- The names of the CSS classes for this image. The class that will be assigned is .mode_name-css_name where mode_name is the name of the mode, i.e. drun etc. This should have a NULL sentinel
.TP
.B struct widget_builder* wofi_widget_builder_get_idx(struct widget_builder* builder, size_t idx)

View File

@ -1,4 +1,4 @@
project('wofi', 'c', version : 'v1.2', default_options : ['c_std=c99', 'buildtype=release', 'warning_level=2'])
project('wofi', 'c', version : 'v1.2.1', default_options : ['c_std=c99', 'buildtype=release', 'warning_level=2'])
cc = meson.get_compiler('c')
pkgcfg = import('pkgconfig')

View File

@ -121,11 +121,11 @@ static bool populate_widget(char* file, char* action, struct widget_builder* bui
pixbuf = utils_g_resize_pixbuf(pixbuf, wofi_get_image_size() * wofi_get_window_scale(), GDK_INTERP_BILINEAR);
wofi_widget_builder_insert_image(builder, pixbuf, "icon");
wofi_widget_builder_insert_image(builder, pixbuf, "icon", NULL);
g_object_unref(pixbuf);
}
wofi_widget_builder_insert_text(builder, name, "name");
wofi_widget_builder_insert_text(builder, generic_name, "generic-name");
wofi_widget_builder_insert_text(builder, name, "name", NULL);
wofi_widget_builder_insert_text(builder, generic_name, "generic-name", NULL);
free(generic_name);
if(action == NULL) {

View File

@ -42,27 +42,43 @@ void wofi_widget_builder_set_action(struct widget_builder* builder, char* action
wofi_property_box_add_property(builder->box, "action", action);
}
void wofi_widget_builder_insert_text(struct widget_builder* builder, const char* text, char* css_name) {
void wofi_widget_builder_insert_text(struct widget_builder* builder, const char* text, ...) {
GtkWidget* label = gtk_label_new(text);
gtk_container_add(GTK_CONTAINER(builder->box), label);
if(css_name != NULL) {
char* tmp = utils_concat(3, builder->mode->name, "-", css_name);
gtk_widget_set_name(label, tmp);
gtk_widget_set_name(label, "text");
GtkStyleContext* ctx = gtk_widget_get_style_context(label);
va_list args;
va_start(args, text);
char* arg;
while((arg = va_arg(args, char*)) != NULL) {
char* tmp = utils_concat(3, builder->mode->name, "-", arg);
gtk_style_context_add_class(ctx, tmp);
free(tmp);
}
va_end(args);
}
void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, char* css_name) {
void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, ...) {
GtkWidget* img = gtk_image_new();
cairo_surface_t* surface = gdk_cairo_surface_create_from_pixbuf(pixbuf, wofi_get_window_scale(), gtk_widget_get_window(img));
gtk_image_set_from_surface(GTK_IMAGE(img), surface);
cairo_surface_destroy(surface);
gtk_container_add(GTK_CONTAINER(builder->box), img);
if(css_name != NULL) {
char* tmp = utils_concat(3, builder->mode->name, "-", css_name);
gtk_widget_set_name(img, tmp);
gtk_widget_set_name(img, "img");
GtkStyleContext* ctx = gtk_widget_get_style_context(img);
va_list args;
va_start(args, pixbuf);
char* arg;
while((arg = va_arg(args, char*)) != NULL) {
char* tmp = utils_concat(3, builder->mode->name, "-", arg);
gtk_style_context_add_class(ctx, tmp);
free(tmp);
}
va_end(args);
}
struct widget_builder* wofi_widget_builder_get_idx(struct widget_builder* builder, size_t idx) {