Added wofi_widget_builder_insert_text_with_list() and wofi_widget_builder_insert_image_with_list()
This commit is contained in:
parent
efbc44fd98
commit
8ad0ee3ac4
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 Scoopta
|
* Copyright (C) 2020-2022 Scoopta
|
||||||
* This file is part of Wofi
|
* This file is part of Wofi
|
||||||
* Wofi is free software: you can redistribute it and/or modify
|
* Wofi is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -24,6 +24,11 @@
|
|||||||
|
|
||||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||||
|
|
||||||
|
struct css_class {
|
||||||
|
char* class;
|
||||||
|
struct wl_list link;
|
||||||
|
};
|
||||||
|
|
||||||
struct widget_builder* wofi_widget_builder_init(struct mode* mode, size_t actions);
|
struct widget_builder* wofi_widget_builder_init(struct mode* mode, size_t actions);
|
||||||
|
|
||||||
void wofi_widget_builder_set_search_text(struct widget_builder* builder, char* search_text);
|
void wofi_widget_builder_set_search_text(struct widget_builder* builder, char* search_text);
|
||||||
@ -32,8 +37,12 @@ void wofi_widget_builder_set_action(struct widget_builder* builder, char* action
|
|||||||
|
|
||||||
__attribute__((sentinel)) void wofi_widget_builder_insert_text(struct widget_builder* builder, const char* text, ...);
|
__attribute__((sentinel)) void wofi_widget_builder_insert_text(struct widget_builder* builder, const char* text, ...);
|
||||||
|
|
||||||
|
void wofi_widget_builder_insert_text_with_list(struct widget_builder* builder, const char* text, struct wl_list* classes);
|
||||||
|
|
||||||
__attribute__((sentinel)) void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, ...);
|
__attribute__((sentinel)) void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, ...);
|
||||||
|
|
||||||
|
void wofi_widget_builder_insert_image_with_list(struct widget_builder* builder, GdkPixbuf* pixbuf, struct wl_list* classes);
|
||||||
|
|
||||||
struct widget_builder* wofi_widget_builder_get_idx(struct widget_builder* builder, size_t idx);
|
struct widget_builder* wofi_widget_builder_get_idx(struct widget_builder* builder, size_t idx);
|
||||||
|
|
||||||
struct widget* wofi_widget_builder_get_widget(struct widget_builder* builder);
|
struct widget* wofi_widget_builder_get_widget(struct widget_builder* builder);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 Scoopta
|
* Copyright (C) 2020-2022 Scoopta
|
||||||
* This file is part of Wofi
|
* This file is part of Wofi
|
||||||
* Wofi is free software: you can redistribute it and/or modify
|
* Wofi is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -42,25 +42,65 @@ void wofi_widget_builder_set_action(struct widget_builder* builder, char* action
|
|||||||
wofi_property_box_add_property(builder->box, "action", action);
|
wofi_property_box_add_property(builder->box, "action", action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void va_to_list(struct wl_list* classes, va_list args) {
|
||||||
|
char* arg;
|
||||||
|
while((arg = va_arg(args, char*)) != NULL) {
|
||||||
|
struct css_class* class = malloc(sizeof(struct css_class));
|
||||||
|
class->class = arg;
|
||||||
|
wl_list_insert(classes, &class->link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void wofi_widget_builder_insert_text(struct widget_builder* builder, const char* text, ...) {
|
void wofi_widget_builder_insert_text(struct widget_builder* builder, const char* text, ...) {
|
||||||
|
struct wl_list classes;
|
||||||
|
wl_list_init(&classes);
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, text);
|
||||||
|
va_to_list(&classes, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
wofi_widget_builder_insert_text_with_list(builder, text, &classes);
|
||||||
|
|
||||||
|
struct css_class* node, *tmp;
|
||||||
|
wl_list_for_each_safe(node, tmp, &classes, link) {
|
||||||
|
free(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wofi_widget_builder_insert_text_with_list(struct widget_builder* builder, const char* text, struct wl_list* classes) {
|
||||||
GtkWidget* label = gtk_label_new(text);
|
GtkWidget* label = gtk_label_new(text);
|
||||||
gtk_container_add(GTK_CONTAINER(builder->box), label);
|
gtk_container_add(GTK_CONTAINER(builder->box), label);
|
||||||
gtk_widget_set_name(label, "text");
|
gtk_widget_set_name(label, "text");
|
||||||
|
|
||||||
GtkStyleContext* ctx = gtk_widget_get_style_context(label);
|
GtkStyleContext* ctx = gtk_widget_get_style_context(label);
|
||||||
|
|
||||||
va_list args;
|
struct css_class* node;
|
||||||
va_start(args, text);
|
wl_list_for_each(node, classes, link) {
|
||||||
char* arg;
|
char* tmp = utils_concat(3, builder->mode->name, "-", node->class);
|
||||||
while((arg = va_arg(args, char*)) != NULL) {
|
|
||||||
char* tmp = utils_concat(3, builder->mode->name, "-", arg);
|
|
||||||
gtk_style_context_add_class(ctx, tmp);
|
gtk_style_context_add_class(ctx, tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
va_end(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, ...) {
|
void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf* pixbuf, ...) {
|
||||||
|
struct wl_list classes;
|
||||||
|
wl_list_init(&classes);
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, pixbuf);
|
||||||
|
va_to_list(&classes, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
wofi_widget_builder_insert_image_with_list(builder, pixbuf, &classes);
|
||||||
|
|
||||||
|
struct css_class* node, *tmp;
|
||||||
|
wl_list_for_each_safe(node, tmp, &classes, link) {
|
||||||
|
free(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wofi_widget_builder_insert_image_with_list(struct widget_builder* builder, GdkPixbuf* pixbuf, struct wl_list* classes) {
|
||||||
GtkWidget* img = gtk_image_new();
|
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));
|
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);
|
gtk_image_set_from_surface(GTK_IMAGE(img), surface);
|
||||||
@ -70,15 +110,12 @@ void wofi_widget_builder_insert_image(struct widget_builder* builder, GdkPixbuf*
|
|||||||
|
|
||||||
GtkStyleContext* ctx = gtk_widget_get_style_context(img);
|
GtkStyleContext* ctx = gtk_widget_get_style_context(img);
|
||||||
|
|
||||||
va_list args;
|
struct css_class* node;
|
||||||
va_start(args, pixbuf);
|
wl_list_for_each(node, classes, link) {
|
||||||
char* arg;
|
char* tmp = utils_concat(3, builder->mode->name, "-", node->class);
|
||||||
while((arg = va_arg(args, char*)) != NULL) {
|
|
||||||
char* tmp = utils_concat(3, builder->mode->name, "-", arg);
|
|
||||||
gtk_style_context_add_class(ctx, tmp);
|
gtk_style_context_add_class(ctx, tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
va_end(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct widget_builder* wofi_widget_builder_get_idx(struct widget_builder* builder, size_t idx) {
|
struct widget_builder* wofi_widget_builder_get_idx(struct widget_builder* builder, size_t idx) {
|
||||||
|
Loading…
Reference in New Issue
Block a user