Don't require use of MenuButton.set_child introduced with GTK 4.6

This commit is contained in:
fiaxh 2022-10-11 17:50:54 +02:00
parent 80258a874d
commit 11b6e615b7
3 changed files with 18 additions and 19 deletions

View file

@ -37,7 +37,7 @@ public class Dino.Ui.CallBottomBar : Gtk.Box {
audio_button.margin_end = audio_button.margin_bottom = 5; // space for the small settings button audio_button.margin_end = audio_button.margin_bottom = 5; // space for the small settings button
audio_button_overlay.set_child(audio_button); audio_button_overlay.set_child(audio_button);
audio_button_overlay.add_overlay(audio_settings_button); audio_button_overlay.add_overlay(audio_settings_button);
menu_button_set_icon_with_size(audio_settings_button, "go-up-symbolic", 10); Util.menu_button_set_icon_with_size(audio_settings_button, "go-up-symbolic", 10);
audio_settings_button.add_css_class("call-mediadevice-settings-button"); audio_settings_button.add_css_class("call-mediadevice-settings-button");
main_buttons.append(audio_button_overlay); main_buttons.append(audio_button_overlay);
@ -47,7 +47,7 @@ public class Dino.Ui.CallBottomBar : Gtk.Box {
video_button.margin_end = video_button.margin_bottom = 5; video_button.margin_end = video_button.margin_bottom = 5;
video_button_overlay.set_child(video_button); video_button_overlay.set_child(video_button);
video_button_overlay.add_overlay(video_settings_button); video_button_overlay.add_overlay(video_settings_button);
menu_button_set_icon_with_size(video_settings_button, "go-up-symbolic", 10); Util.menu_button_set_icon_with_size(video_settings_button, "go-up-symbolic", 10);
video_settings_button.add_css_class("call-mediadevice-settings-button"); video_settings_button.add_css_class("call-mediadevice-settings-button");
main_buttons.append(video_button_overlay); main_buttons.append(video_button_overlay);
@ -76,21 +76,6 @@ public class Dino.Ui.CallBottomBar : Gtk.Box {
this.add_css_class("call-bottom-bar"); this.add_css_class("call-bottom-bar");
} }
private static void menu_button_set_icon_with_size(MenuButton menu_button, string icon_name, int pixel_size) {
#if GTK_4_6
menu_button.set_child(new Image.from_icon_name(icon_name) { pixel_size=pixel_size });
#else
menu_button.set_icon_name(icon_name);
var button = menu_button.get_first_child() as Button;
if (button == null) return;
var box = button.child as Box;
if (box == null) return;
var image = box.get_first_child() as Image;
if (image == null) return;
image.pixel_size = pixel_size;
#endif
}
public AudioSettingsPopover? show_audio_device_choices(bool show) { public AudioSettingsPopover? show_audio_device_choices(bool show) {
audio_settings_button.visible = show; audio_settings_button.visible = show;
if (audio_settings_popover != null) audio_settings_popover.visible = false; if (audio_settings_popover != null) audio_settings_popover.visible = false;

View file

@ -129,8 +129,7 @@ public class ReactionsWidget : Grid {
add_button = new MenuButton() { tooltip_text= _("Add reaction"), visible=true }; add_button = new MenuButton() { tooltip_text= _("Add reaction"), visible=true };
add_button.get_style_context().add_class("reaction-box"); add_button.get_style_context().add_class("reaction-box");
Image add_image = new Image.from_icon_name("dino-emoticon-add-symbolic") { margin_start=5, margin_end=5, visible=true }; Util.menu_button_set_icon_with_size(add_button, "dino-emoticon-add-symbolic", 14);
add_button.set_child(add_image);
EmojiChooser chooser = new EmojiChooser(); EmojiChooser chooser = new EmojiChooser();
chooser.emoji_picked.connect((emoji) => { chooser.emoji_picked.connect((emoji) => {

View file

@ -452,4 +452,19 @@ public bool use_tooltips() {
return Gtk.MINOR_VERSION != 6 || (Gtk.MICRO_VERSION < 4 || Gtk.MICRO_VERSION > 6); return Gtk.MINOR_VERSION != 6 || (Gtk.MICRO_VERSION < 4 || Gtk.MICRO_VERSION > 6);
} }
public static void menu_button_set_icon_with_size(MenuButton menu_button, string icon_name, int pixel_size) {
#if GTK_4_6
menu_button.set_child(new Image.from_icon_name(icon_name) { pixel_size=pixel_size });
#else
menu_button.set_icon_name(icon_name);
var button = menu_button.get_first_child() as Button;
if (button == null) return;
var box = button.child as Box;
if (box == null) return;
var image = box.get_first_child() as Image;
if (image == null) return;
image.pixel_size = pixel_size;
#endif
}
} }