project: Simplify buttons

GtkButton has an 'icon-name' property that greatly simplifies
setting up buttons. GtkMenuButton has a new 'always-show-arrow'
property that also allows us to simplify some code.
This commit is contained in:
Georges Basile Stavracas Neto 2022-07-08 15:43:57 -03:00
parent c9f8bb22f6
commit 8560ca0677
3 changed files with 13 additions and 43 deletions

View File

@ -81,8 +81,7 @@ struct _MctUserControls
AdwActionRow *restrict_software_installation_row; AdwActionRow *restrict_software_installation_row;
GtkSwitch *restrict_web_browsers_switch; GtkSwitch *restrict_web_browsers_switch;
AdwActionRow *restrict_web_browsers_row; AdwActionRow *restrict_web_browsers_row;
GtkButton *oars_button; GtkMenuButton *oars_button;
GtkLabel *oars_button_label;
GtkPopover *oars_popover; GtkPopover *oars_popover;
MctRestrictApplicationsDialog *restrict_applications_dialog; MctRestrictApplicationsDialog *restrict_applications_dialog;
GtkLabel *restrict_applications_description; GtkLabel *restrict_applications_description;
@ -395,7 +394,7 @@ update_oars_level (MctUserControls *self)
selected_age = maximum_age; selected_age = maximum_age;
} }
gtk_label_set_label (self->oars_button_label, rating_age_category); gtk_menu_button_set_label (self->oars_button, rating_age_category);
self->selected_age = selected_age; self->selected_age = selected_age;
} }
@ -641,13 +640,13 @@ on_set_age_action_activated (GSimpleAction *action,
/* Update the button */ /* Update the button */
if (age == oars_disabled_age) if (age == oars_disabled_age)
gtk_label_set_label (self->oars_button_label, _("All Ages")); gtk_menu_button_set_label (self->oars_button, _("All Ages"));
for (i = 0; age != oars_disabled_age && entries[i] != NULL; i++) for (i = 0; age != oars_disabled_age && entries[i] != NULL; i++)
{ {
if (ages[i] == age) if (ages[i] == age)
{ {
gtk_label_set_label (self->oars_button_label, entries[i]); gtk_menu_button_set_label (self->oars_button, entries[i]);
break; break;
} }
} }
@ -998,7 +997,6 @@ mct_user_controls_class_init (MctUserControlsClass *klass)
gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_web_browsers_switch); gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_web_browsers_switch);
gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_web_browsers_row); gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_web_browsers_row);
gtk_widget_class_bind_template_child (widget_class, MctUserControls, oars_button); gtk_widget_class_bind_template_child (widget_class, MctUserControls, oars_button);
gtk_widget_class_bind_template_child (widget_class, MctUserControls, oars_button_label);
gtk_widget_class_bind_template_child (widget_class, MctUserControls, oars_popover); gtk_widget_class_bind_template_child (widget_class, MctUserControls, oars_popover);
gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_applications_dialog); gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_applications_dialog);
gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_applications_row); gtk_widget_class_bind_template_child (widget_class, MctUserControls, restrict_applications_row);

View File

@ -103,25 +103,7 @@
<property name="valign">center</property> <property name="valign">center</property>
<property name="direction">right</property> <property name="direction">right</property>
<property name="popover">oars_popover</property> <property name="popover">oars_popover</property>
<child> <property name="always-show-arrow">True</property>
<object class="GtkBox">
<property name="orientation">horizontal</property>
<child>
<object class="GtkLabel" id="oars_button_label">
<property name="label"></property>
<property name="expand">True</property>
<property name="halign">start</property>
<property name="xalign">0.0</property>
</object>
</child>
<child>
<object class="GtkImage">
<property name="icon-name">pan-down-symbolic</property>
<property name="icon-size">4</property><!-- GTK_ICON_SIZE_BUTTON -->
</object>
</child>
</object>
</child>
</object> </object>
</child> </child>
</object> </object>

View File

@ -35,18 +35,13 @@
<object class="GtkButton" id="go_back_button"> <object class="GtkButton" id="go_back_button">
<property name="visible">False</property> <property name="visible">False</property>
<property name="valign">center</property> <property name="valign">center</property>
<style>
<class name="circular"/>
</style>
<child>
<object class="GtkImage">
<property name="icon-size">4</property>
<property name="icon_name">go-previous-symbolic</property> <property name="icon_name">go-previous-symbolic</property>
<accessibility> <accessibility>
<property name="label" translatable="yes">Previous Page</property> <property name="label" translatable="yes">Previous Page</property>
</accessibility> </accessibility>
</object> <style>
</child> <class name="circular"/>
</style>
<signal name="clicked" handler="mct_carousel_goto_previous_page" object="MctCarousel" swapped="no"/> <signal name="clicked" handler="mct_carousel_goto_previous_page" object="MctCarousel" swapped="no"/>
</object> </object>
</child> </child>
@ -55,18 +50,13 @@
<property name="valign">center</property> <property name="valign">center</property>
<property name="halign">end</property> <property name="halign">end</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<style>
<class name="circular"/>
</style>
<child>
<object class="GtkImage">
<property name="icon-size">4</property>
<property name="icon_name">go-next-symbolic</property> <property name="icon_name">go-next-symbolic</property>
<accessibility> <accessibility>
<property name="label" translatable="yes">Next Page</property> <property name="label" translatable="yes">Next Page</property>
</accessibility> </accessibility>
</object> <style>
</child> <class name="circular"/>
</style>
<signal name="clicked" handler="mct_carousel_goto_next_page" object="MctCarousel" swapped="no"/> <signal name="clicked" handler="mct_carousel_goto_next_page" object="MctCarousel" swapped="no"/>
</object> </object>
</child> </child>