tests: add menu alignments to the menubutton test
https://bugzilla.gnome.org/show_bug.cgi?id=720939
This commit is contained in:
parent
b2dbcea3a2
commit
dae65b7c62
@ -1,15 +1,49 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include "prop-editor.h"
|
#include "prop-editor.h"
|
||||||
|
|
||||||
|
#define INITIAL_HALIGN GTK_ALIGN_START
|
||||||
|
#define INITIAL_VALIGN GTK_ALIGN_START
|
||||||
|
|
||||||
|
static GList *menubuttons = NULL;
|
||||||
|
|
||||||
|
static void
|
||||||
|
horizontal_alignment_changed (GtkComboBox *box)
|
||||||
|
{
|
||||||
|
GtkAlign alignment = gtk_combo_box_get_active (box);
|
||||||
|
GList *l;
|
||||||
|
|
||||||
|
for (l = menubuttons; l != NULL; l = l->next) {
|
||||||
|
GtkMenu *popup = gtk_menu_button_get_popup (GTK_MENU_BUTTON (l->data));
|
||||||
|
if (popup != NULL)
|
||||||
|
gtk_widget_set_halign (GTK_WIDGET (popup), alignment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vertical_alignment_changed (GtkComboBox *box)
|
||||||
|
{
|
||||||
|
GtkAlign alignment = gtk_combo_box_get_active (box);
|
||||||
|
GList *l;
|
||||||
|
|
||||||
|
for (l = menubuttons; l != NULL; l = l->next) {
|
||||||
|
GtkMenu *popup = gtk_menu_button_get_popup (GTK_MENU_BUTTON (l->data));
|
||||||
|
if (popup != NULL)
|
||||||
|
gtk_widget_set_valign (GTK_WIDGET (popup), alignment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
int main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
GtkWidget *grid;
|
GtkWidget *grid;
|
||||||
GtkWidget *entry;
|
GtkWidget *entry;
|
||||||
|
GtkWidget *label;
|
||||||
|
GtkWidget *combo;
|
||||||
GtkWidget *menu_widget;
|
GtkWidget *menu_widget;
|
||||||
GtkAccelGroup *accel_group;
|
GtkAccelGroup *accel_group;
|
||||||
guint i;
|
guint i;
|
||||||
|
guint row = 0;
|
||||||
GMenu *menu;
|
GMenu *menu;
|
||||||
|
|
||||||
gtk_init (&argc, &argv);
|
gtk_init (&argc, &argv);
|
||||||
@ -26,17 +60,48 @@ int main (int argc, char **argv)
|
|||||||
accel_group = gtk_accel_group_new ();
|
accel_group = gtk_accel_group_new ();
|
||||||
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
|
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
|
||||||
|
|
||||||
|
/* horizontal alignment */
|
||||||
|
label = gtk_label_new ("Horizontal Alignment:");
|
||||||
|
gtk_widget_show (label);
|
||||||
|
gtk_grid_attach (GTK_GRID (grid), label, 0, row++, 1, 1);
|
||||||
|
|
||||||
|
combo = gtk_combo_box_text_new ();
|
||||||
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Fill");
|
||||||
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Start");
|
||||||
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "End");
|
||||||
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Center");
|
||||||
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Baseline");
|
||||||
|
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), INITIAL_HALIGN);
|
||||||
|
gtk_widget_show (combo);
|
||||||
|
gtk_grid_attach_next_to (GTK_GRID (grid), combo, label, GTK_POS_RIGHT, 1, 1);
|
||||||
|
g_signal_connect (G_OBJECT (combo), "changed",
|
||||||
|
G_CALLBACK (horizontal_alignment_changed), menubuttons);
|
||||||
|
|
||||||
|
/* vertical alignment */
|
||||||
|
label = gtk_label_new ("Vertical Alignment:");
|
||||||
|
gtk_widget_show (label);
|
||||||
|
gtk_grid_attach (GTK_GRID (grid), label, 0, row++, 1, 1);
|
||||||
|
|
||||||
|
combo = gtk_combo_box_text_new ();
|
||||||
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Fill");
|
||||||
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Start");
|
||||||
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "End");
|
||||||
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Center");
|
||||||
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Baseline");
|
||||||
|
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), INITIAL_HALIGN);
|
||||||
|
gtk_widget_show (combo);
|
||||||
|
gtk_grid_attach_next_to (GTK_GRID (grid), combo, label, GTK_POS_RIGHT, 1, 1);
|
||||||
|
g_signal_connect (G_OBJECT (combo), "changed",
|
||||||
|
G_CALLBACK (vertical_alignment_changed), menubuttons);
|
||||||
|
|
||||||
/* Button next to entry */
|
/* Button next to entry */
|
||||||
entry = gtk_entry_new ();
|
entry = gtk_entry_new ();
|
||||||
gtk_grid_attach (GTK_GRID (grid),
|
gtk_grid_attach (GTK_GRID (grid), entry, 0, row++, 1, 1);
|
||||||
entry,
|
|
||||||
0, 0,
|
|
||||||
1, 1);
|
|
||||||
button = gtk_menu_button_new ();
|
button = gtk_menu_button_new ();
|
||||||
gtk_grid_attach (GTK_GRID (grid),
|
gtk_widget_set_halign (button, GTK_ALIGN_START);
|
||||||
button,
|
|
||||||
1, 0,
|
gtk_grid_attach_next_to (GTK_GRID (grid), button, entry, GTK_POS_RIGHT, 1, 1);
|
||||||
1, 1);
|
menubuttons = g_list_prepend (menubuttons, button);
|
||||||
|
|
||||||
/* Button with GtkMenu */
|
/* Button with GtkMenu */
|
||||||
menu_widget = gtk_menu_new ();
|
menu_widget = gtk_menu_new ();
|
||||||
@ -61,11 +126,10 @@ int main (int argc, char **argv)
|
|||||||
gtk_widget_show_all (menu_widget);
|
gtk_widget_show_all (menu_widget);
|
||||||
|
|
||||||
button = gtk_menu_button_new ();
|
button = gtk_menu_button_new ();
|
||||||
|
gtk_widget_set_halign (button, GTK_ALIGN_START);
|
||||||
|
menubuttons = g_list_prepend (menubuttons, button);
|
||||||
gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu_widget);
|
gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu_widget);
|
||||||
gtk_grid_attach (GTK_GRID (grid),
|
gtk_grid_attach (GTK_GRID (grid), button, 1, row++, 1, 1);
|
||||||
button,
|
|
||||||
1, 1,
|
|
||||||
1, 1);
|
|
||||||
gtk_widget_show (create_prop_editor (G_OBJECT (button), 0));
|
gtk_widget_show (create_prop_editor (G_OBJECT (button), 0));
|
||||||
|
|
||||||
/* Button with GMenuModel */
|
/* Button with GMenuModel */
|
||||||
@ -81,12 +145,12 @@ int main (int argc, char **argv)
|
|||||||
g_object_unref (item);
|
g_object_unref (item);
|
||||||
g_free (label);
|
g_free (label);
|
||||||
}
|
}
|
||||||
|
|
||||||
button = gtk_menu_button_new ();
|
button = gtk_menu_button_new ();
|
||||||
|
gtk_widget_set_halign (button, GTK_ALIGN_START);
|
||||||
|
menubuttons = g_list_prepend (menubuttons, button);
|
||||||
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), G_MENU_MODEL (menu));
|
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), G_MENU_MODEL (menu));
|
||||||
gtk_grid_attach (GTK_GRID (grid),
|
gtk_grid_attach (GTK_GRID (grid), button, 1, row++, 1, 1);
|
||||||
button,
|
|
||||||
1, 2,
|
|
||||||
1, 1);
|
|
||||||
|
|
||||||
gtk_widget_show_all (window);
|
gtk_widget_show_all (window);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user