2015-07-29 02:47:07 +00:00
|
|
|
/* Overlay/Interactive Overlay
|
2020-09-13 18:59:33 +00:00
|
|
|
* #Keywords: GtkOverlay
|
2011-05-19 16:53:05 +00:00
|
|
|
*
|
2015-06-20 00:08:15 +00:00
|
|
|
* Shows widgets in static positions over a main widget.
|
|
|
|
*
|
2020-08-21 12:41:13 +00:00
|
|
|
* The overlaid widgets can be interactive controls such
|
2015-06-20 00:08:15 +00:00
|
|
|
* as the entry in this example, or just decorative, like
|
|
|
|
* the big blue label.
|
2011-05-19 16:53:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2015-06-19 22:13:34 +00:00
|
|
|
static void
|
|
|
|
do_number (GtkButton *button, GtkEntry *entry)
|
|
|
|
{
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (entry), gtk_button_get_label (button));
|
2015-06-19 22:13:34 +00:00
|
|
|
}
|
|
|
|
|
2011-05-19 16:53:05 +00:00
|
|
|
GtkWidget *
|
|
|
|
do_overlay (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
GtkWidget *overlay;
|
2015-06-19 22:13:34 +00:00
|
|
|
GtkWidget *grid;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *vbox;
|
2011-05-19 16:53:05 +00:00
|
|
|
GtkWidget *label;
|
2015-06-19 22:13:34 +00:00
|
|
|
GtkWidget *entry;
|
|
|
|
int i, j;
|
|
|
|
char *text;
|
2011-05-19 16:53:05 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2015-06-19 22:13:34 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 500, 510);
|
2015-07-29 02:47:07 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Interactive Overlay");
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
|
|
overlay = gtk_overlay_new ();
|
2015-06-19 22:13:34 +00:00
|
|
|
grid = gtk_grid_new ();
|
2020-05-03 14:32:24 +00:00
|
|
|
gtk_overlay_set_child (GTK_OVERLAY (overlay), grid);
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
|
|
entry = gtk_entry_new ();
|
|
|
|
|
2015-06-19 22:13:34 +00:00
|
|
|
for (j = 0; j < 5; j++)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
text = g_strdup_printf ("%d", 5*j + i);
|
|
|
|
button = gtk_button_new_with_label (text);
|
|
|
|
g_free (text);
|
|
|
|
gtk_widget_set_hexpand (button, TRUE);
|
|
|
|
gtk_widget_set_vexpand (button, TRUE);
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (do_number), entry);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), button, i, j, 1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
|
2019-04-07 21:36:40 +00:00
|
|
|
gtk_widget_set_can_target (vbox, FALSE);
|
2020-03-28 02:57:10 +00:00
|
|
|
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), vbox);
|
2015-06-19 22:13:34 +00:00
|
|
|
gtk_widget_set_halign (vbox, GTK_ALIGN_CENTER);
|
2020-03-28 02:57:10 +00:00
|
|
|
gtk_widget_set_valign (vbox, GTK_ALIGN_START);
|
2015-06-19 22:13:34 +00:00
|
|
|
|
|
|
|
label = gtk_label_new ("<span foreground='blue' weight='ultrabold' font='40'>Numbers</span>");
|
|
|
|
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
|
2020-03-28 02:57:10 +00:00
|
|
|
gtk_widget_set_can_target (label, FALSE);
|
2016-10-02 15:37:22 +00:00
|
|
|
gtk_widget_set_margin_top (label, 8);
|
2020-03-28 02:57:10 +00:00
|
|
|
gtk_widget_set_margin_bottom (label, 8);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), label);
|
2015-06-19 22:13:34 +00:00
|
|
|
|
2017-10-07 01:35:21 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
|
|
|
|
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), vbox);
|
|
|
|
gtk_widget_set_halign (vbox, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (vbox, GTK_ALIGN_CENTER);
|
2020-03-28 02:57:10 +00:00
|
|
|
|
2015-06-19 22:13:34 +00:00
|
|
|
gtk_entry_set_placeholder_text (GTK_ENTRY (entry), "Your Lucky Number");
|
2020-03-28 02:57:10 +00:00
|
|
|
gtk_widget_set_margin_top (entry, 8);
|
2016-10-02 15:37:22 +00:00
|
|
|
gtk_widget_set_margin_bottom (entry, 8);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), entry);
|
2011-05-19 16:53:05 +00:00
|
|
|
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), overlay);
|
2020-05-09 16:03:11 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2011-05-19 16:53:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (window))
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_widget_show (window);
|
2011-05-19 16:53:05 +00:00
|
|
|
else
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|