Fix inconsistent updating of KotoButton iconography noticed via KotoExpander in KotoNav.
Turtles all the way down.
This commit is contained in:
parent
34ca201121
commit
8f79854679
3 changed files with 67 additions and 22 deletions
|
@ -309,6 +309,10 @@ void koto_button_flip(KotoButton * self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void koto_button_hide_image(KotoButton * self) {
|
void koto_button_hide_image(KotoButton * self) {
|
||||||
|
if (!KOTO_IS_BUTTON(self)) { // Not a button
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (GTK_IS_WIDGET(self->button_pic)) { // Is a widget
|
if (GTK_IS_WIDGET(self->button_pic)) { // Is a widget
|
||||||
gtk_widget_hide(self->button_pic);
|
gtk_widget_hide(self->button_pic);
|
||||||
}
|
}
|
||||||
|
@ -318,6 +322,10 @@ void koto_button_set_badge_text(
|
||||||
KotoButton * self,
|
KotoButton * self,
|
||||||
gchar * text
|
gchar * text
|
||||||
) {
|
) {
|
||||||
|
if (!KOTO_IS_BUTTON(self)) { // Not a button
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((text == NULL) || (strcmp(text, "") == 0)) { // If the text is empty
|
if ((text == NULL) || (strcmp(text, "") == 0)) { // If the text is empty
|
||||||
self->badge_text = g_strdup("");
|
self->badge_text = g_strdup("");
|
||||||
} else {
|
} else {
|
||||||
|
@ -366,6 +374,14 @@ void koto_button_set_icon_name(
|
||||||
gchar * icon_name,
|
gchar * icon_name,
|
||||||
gboolean for_alt
|
gboolean for_alt
|
||||||
) {
|
) {
|
||||||
|
if (!KOTO_IS_BUTTON(self)) { // Not a button
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!koto_utils_is_string_valid(icon_name)) { // Not a valid icon
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
gchar * copied_icon_name = g_strdup(icon_name);
|
gchar * copied_icon_name = g_strdup(icon_name);
|
||||||
|
|
||||||
if (for_alt) { // Is for the alternate icon
|
if (for_alt) { // Is for the alternate icon
|
||||||
|
@ -390,12 +406,12 @@ void koto_button_set_icon_name(
|
||||||
hide_image = TRUE;
|
hide_image = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GTK_IS_IMAGE(self->button_pic)) { // If we already have a button image
|
||||||
if (hide_image) { // Should hide the image
|
if (hide_image) { // Should hide the image
|
||||||
if (GTK_IS_PICTURE(self->button_pic)) { // If we already have a button image
|
|
||||||
gtk_widget_hide(self->button_pic); // Hide
|
gtk_widget_hide(self->button_pic); // Hide
|
||||||
|
} else { // Should be showing the image
|
||||||
|
gtk_image_set_from_icon_name(GTK_IMAGE(self->button_pic), self->icon_name); // Just update the existing image immediately
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_notify_by_pspec(G_OBJECT(self), for_alt ? btn_props[PROP_ALT_ICON_NAME] : btn_props[PROP_ICON_NAME]);
|
g_object_notify_by_pspec(G_OBJECT(self), for_alt ? btn_props[PROP_ALT_ICON_NAME] : btn_props[PROP_ICON_NAME]);
|
||||||
|
@ -405,6 +421,10 @@ void koto_button_set_image_position(
|
||||||
KotoButton * self,
|
KotoButton * self,
|
||||||
KotoButtonImagePosition pos
|
KotoButtonImagePosition pos
|
||||||
) {
|
) {
|
||||||
|
if (!KOTO_IS_BUTTON(self)) { // Not a button
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (self->image_position == pos) { // Is a different position that currently
|
if (self->image_position == pos) { // Is a different position that currently
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -424,6 +444,10 @@ void koto_button_set_pixbuf_size(
|
||||||
KotoButton * self,
|
KotoButton * self,
|
||||||
guint size
|
guint size
|
||||||
) {
|
) {
|
||||||
|
if (!KOTO_IS_BUTTON(self)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (size == self->pix_size) {
|
if (size == self->pix_size) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -438,11 +462,15 @@ void koto_button_set_text(
|
||||||
KotoButton * self,
|
KotoButton * self,
|
||||||
gchar * text
|
gchar * text
|
||||||
) {
|
) {
|
||||||
if (text == NULL) {
|
if (!KOTO_IS_BUTTON(self)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->text != NULL) { // Text defined
|
if (!koto_utils_is_string_valid(text)) { // Invalid text
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (koto_utils_is_string_valid(self->text)) { // Text defined
|
||||||
g_free(self->text); // Free existing text
|
g_free(self->text); // Free existing text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,7 +520,6 @@ void koto_button_show_image(
|
||||||
gtk_box_prepend(GTK_BOX(self), self->button_pic); // Prepend to the box
|
gtk_box_prepend(GTK_BOX(self), self->button_pic); // Prepend to the box
|
||||||
}
|
}
|
||||||
} else { // From icon name
|
} else { // From icon name
|
||||||
|
|
||||||
if (use_alt && ((self->alt_icon_name == NULL) || (strcmp(self->alt_icon_name, "") == 0))) { // Don't have an alt icon set
|
if (use_alt && ((self->alt_icon_name == NULL) || (strcmp(self->alt_icon_name, "") == 0))) { // Don't have an alt icon set
|
||||||
return;
|
return;
|
||||||
} else if (!use_alt && ((self->icon_name == NULL) || (strcmp(self->icon_name, "") == 0))) { // Don't have icon set
|
} else if (!use_alt && ((self->icon_name == NULL) || (strcmp(self->icon_name, "") == 0))) { // Don't have icon set
|
||||||
|
@ -503,7 +530,7 @@ void koto_button_show_image(
|
||||||
gchar * name = use_alt ? self->alt_icon_name : self->icon_name;
|
gchar * name = use_alt ? self->alt_icon_name : self->icon_name;
|
||||||
|
|
||||||
if (GTK_IS_IMAGE(self->button_pic)) {
|
if (GTK_IS_IMAGE(self->button_pic)) {
|
||||||
gtk_image_set_from_icon_name(GTK_IMAGE(self->button_pic), name); // Just update the existing iamge
|
gtk_image_set_from_icon_name(GTK_IMAGE(self->button_pic), name); // Just update the existing image
|
||||||
} else { // Not an image
|
} else { // Not an image
|
||||||
self->button_pic = gtk_image_new_from_icon_name(name); // Get our new image
|
self->button_pic = gtk_image_new_from_icon_name(name); // Get our new image
|
||||||
gtk_box_prepend(GTK_BOX(self), self->button_pic); // Prepend to the box
|
gtk_box_prepend(GTK_BOX(self), self->button_pic); // Prepend to the box
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "config/config.h"
|
#include "config/config.h"
|
||||||
#include "koto-button.h"
|
#include "koto-button.h"
|
||||||
#include "koto-expander.h"
|
#include "koto-expander.h"
|
||||||
|
#include "koto-utils.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
PROP_EXP_0,
|
PROP_EXP_0,
|
||||||
|
@ -146,20 +147,9 @@ static void koto_expander_set_property(
|
||||||
) {
|
) {
|
||||||
KotoExpander * self = KOTO_EXPANDER(obj);
|
KotoExpander * self = KOTO_EXPANDER(obj);
|
||||||
|
|
||||||
if (!GTK_IS_WIDGET(self->header_button)) { // Header Button is not a widget
|
|
||||||
KotoButton * new_button = koto_button_new_with_icon(NULL, "emblem-favorite-symbolic", NULL, KOTO_BUTTON_PIXBUF_SIZE_SMALL);
|
|
||||||
|
|
||||||
if (GTK_IS_WIDGET(new_button)) { // Created our widget successfully
|
|
||||||
self->header_button = new_button;
|
|
||||||
gtk_widget_set_hexpand(GTK_WIDGET(self->header_button), TRUE);
|
|
||||||
gtk_box_prepend(GTK_BOX(self->header), GTK_WIDGET(self->header_button));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_HEADER_ICON_NAME:
|
case PROP_HEADER_ICON_NAME:
|
||||||
g_return_if_fail(GTK_IS_WIDGET(self->header_button));
|
koto_expander_set_icon_name(self, g_strdup(g_value_get_string(val)));
|
||||||
koto_button_set_icon_name(self->header_button, g_strdup(g_value_get_string(val)), FALSE);
|
|
||||||
break;
|
break;
|
||||||
case PROP_HEADER_LABEL:
|
case PROP_HEADER_LABEL:
|
||||||
g_return_if_fail(GTK_IS_WIDGET(self->header_button));
|
g_return_if_fail(GTK_IS_WIDGET(self->header_button));
|
||||||
|
@ -193,6 +183,14 @@ static void koto_expander_init(KotoExpander * self) {
|
||||||
gtk_revealer_set_reveal_child(GTK_REVEALER(self->revealer), TRUE); // Set to be revealed by default
|
gtk_revealer_set_reveal_child(GTK_REVEALER(self->revealer), TRUE); // Set to be revealed by default
|
||||||
gtk_revealer_set_transition_type(GTK_REVEALER(self->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
|
gtk_revealer_set_transition_type(GTK_REVEALER(self->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
|
||||||
|
|
||||||
|
KotoButton * new_button = koto_button_new_with_icon(NULL, "emblem-favorite-symbolic", NULL, KOTO_BUTTON_PIXBUF_SIZE_SMALL);
|
||||||
|
|
||||||
|
if (KOTO_IS_BUTTON(new_button)) { // Created our widget successfully
|
||||||
|
self->header_button = new_button;
|
||||||
|
gtk_widget_set_hexpand(GTK_WIDGET(self->header_button), TRUE);
|
||||||
|
gtk_box_prepend(GTK_BOX(self->header), GTK_WIDGET(self->header_button));
|
||||||
|
}
|
||||||
|
|
||||||
self->header_expand_button = koto_button_new_with_icon("", "pan-down-symbolic", "pan-up-symbolic", KOTO_BUTTON_PIXBUF_SIZE_SMALL);
|
self->header_expand_button = koto_button_new_with_icon("", "pan-down-symbolic", "pan-up-symbolic", KOTO_BUTTON_PIXBUF_SIZE_SMALL);
|
||||||
gtk_box_append(GTK_BOX(self->header), GTK_WIDGET(self->header_expand_button));
|
gtk_box_append(GTK_BOX(self->header), GTK_WIDGET(self->header_expand_button));
|
||||||
|
|
||||||
|
@ -204,6 +202,26 @@ static void koto_expander_init(KotoExpander * self) {
|
||||||
koto_button_add_click_handler(self->header_expand_button, KOTO_BUTTON_CLICK_TYPE_PRIMARY, G_CALLBACK(koto_expander_toggle_content), self);
|
koto_button_add_click_handler(self->header_expand_button, KOTO_BUTTON_CLICK_TYPE_PRIMARY, G_CALLBACK(koto_expander_toggle_content), self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// koto_expander_set_icon_name will set the icon for our inner KotoButton for this Expander
|
||||||
|
void koto_expander_set_icon_name(
|
||||||
|
KotoExpander *self,
|
||||||
|
gchar * icon
|
||||||
|
) {
|
||||||
|
if (!KOTO_IS_EXPANDER(self)) { // Not a KotoExpander
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!koto_utils_is_string_valid(icon)) { // Not a valid string
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!KOTO_IS_BUTTON(self->header_button)) { // Don't have a header button for whatever reason
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
koto_button_set_icon_name(self->header_button, icon, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
void koto_expander_set_secondary_button(
|
void koto_expander_set_secondary_button(
|
||||||
KotoExpander * self,
|
KotoExpander * self,
|
||||||
KotoButton * new_button
|
KotoButton * new_button
|
||||||
|
|
|
@ -37,7 +37,7 @@ GtkWidget * koto_expander_get_content(KotoExpander * self);
|
||||||
|
|
||||||
void koto_expander_set_icon_name(
|
void koto_expander_set_icon_name(
|
||||||
KotoExpander *self,
|
KotoExpander *self,
|
||||||
const gchar* in
|
gchar * icon
|
||||||
);
|
);
|
||||||
|
|
||||||
void koto_expander_set_label(
|
void koto_expander_set_label(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue