2012-02-06 16:26:57 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
overlay_get_child_position (GtkOverlay *overlay,
|
|
|
|
GtkWidget *child,
|
|
|
|
GdkRectangle *allocation,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *custom_child = user_data;
|
|
|
|
GtkRequisition req;
|
|
|
|
|
|
|
|
if (child != custom_child)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gtk_widget_get_preferred_size (child, NULL, &req);
|
|
|
|
|
|
|
|
allocation->x = 120;
|
|
|
|
allocation->y = 0;
|
|
|
|
allocation->width = req.width;
|
|
|
|
allocation->height = req.height;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *win, *overlay, *grid, *main_child, *child, *label, *sw;
|
2014-10-12 03:08:54 +00:00
|
|
|
GtkCssProvider *provider;
|
2012-02-06 16:26:57 +00:00
|
|
|
gchar *str;
|
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2012-02-06 16:26:57 +00:00
|
|
|
|
2014-10-12 03:08:54 +00:00
|
|
|
provider = gtk_css_provider_new ();
|
|
|
|
gtk_css_provider_load_from_data (provider,
|
2018-08-27 16:13:01 +00:00
|
|
|
"label { border: 3px solid black; border-radius: 5px; padding: 2px; }"
|
|
|
|
".top { border-top-style: none; border-top-right-radius: 0px; border-top-left-radius: 0px; }"
|
2014-10-12 03:08:54 +00:00
|
|
|
".bottom { border-bottom-style: none; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; }"
|
|
|
|
".left { border-left-style: none; border-top-left-radius: 0px; border-bottom-left-radius: 0px; }"
|
|
|
|
".right { border-right-style: none; border-top-right-radius: 0px; border-bottom-right-radius: 0px; }",
|
2016-10-17 14:09:12 +00:00
|
|
|
-1);
|
2017-10-31 01:35:21 +00:00
|
|
|
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
|
|
|
GTK_STYLE_PROVIDER (provider),
|
|
|
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
2014-10-12 03:08:54 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
win = gtk_window_new ();
|
2012-02-06 16:26:57 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (win), 600, 600);
|
|
|
|
|
|
|
|
grid = gtk_grid_new ();
|
|
|
|
label = gtk_label_new ("Out of overlay");
|
2017-08-01 22:49:42 +00:00
|
|
|
gtk_widget_set_hexpand (label, TRUE);
|
|
|
|
gtk_widget_set_vexpand (label, TRUE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (grid), label);
|
2012-02-06 16:26:57 +00:00
|
|
|
|
|
|
|
overlay = gtk_overlay_new ();
|
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
|
|
|
GTK_POLICY_ALWAYS,
|
|
|
|
GTK_POLICY_ALWAYS);
|
2020-05-03 14:32:24 +00:00
|
|
|
gtk_overlay_set_child (GTK_OVERLAY (overlay), sw);
|
2012-02-06 16:26:57 +00:00
|
|
|
|
2017-08-01 22:49:42 +00:00
|
|
|
main_child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), main_child);
|
2012-02-06 16:26:57 +00:00
|
|
|
gtk_widget_set_hexpand (main_child, TRUE);
|
|
|
|
gtk_widget_set_vexpand (main_child, TRUE);
|
|
|
|
label = gtk_label_new ("Main child");
|
2014-10-12 03:08:54 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
2012-02-06 16:26:57 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (main_child), label);
|
|
|
|
|
|
|
|
child = gtk_label_new (NULL);
|
|
|
|
str = g_strdup_printf ("%p", child);
|
|
|
|
gtk_label_set_text (GTK_LABEL (child), str);
|
|
|
|
g_free (str);
|
|
|
|
g_print ("Bottom/Right child: %p\n", child);
|
|
|
|
gtk_widget_set_halign (child, GTK_ALIGN_END);
|
|
|
|
gtk_widget_set_valign (child, GTK_ALIGN_END);
|
|
|
|
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child);
|
|
|
|
|
|
|
|
child = gtk_label_new (NULL);
|
|
|
|
str = g_strdup_printf ("%p", child);
|
|
|
|
gtk_label_set_text (GTK_LABEL (child), str);
|
|
|
|
g_free (str);
|
|
|
|
g_print ("Left/Top child: %p\n", child);
|
|
|
|
gtk_widget_set_halign (child, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (child, GTK_ALIGN_START);
|
|
|
|
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child);
|
|
|
|
|
|
|
|
child = gtk_label_new (NULL);
|
|
|
|
str = g_strdup_printf ("%p", child);
|
|
|
|
gtk_label_set_text (GTK_LABEL (child), str);
|
|
|
|
g_free (str);
|
|
|
|
g_print ("Right/Center child: %p\n", child);
|
|
|
|
gtk_widget_set_halign (child, GTK_ALIGN_END);
|
|
|
|
gtk_widget_set_valign (child, GTK_ALIGN_CENTER);
|
|
|
|
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child);
|
|
|
|
|
|
|
|
child = gtk_label_new (NULL);
|
|
|
|
str = g_strdup_printf ("%p", child);
|
|
|
|
gtk_label_set_text (GTK_LABEL (child), str);
|
|
|
|
g_free (str);
|
2013-11-14 22:31:17 +00:00
|
|
|
gtk_widget_set_margin_start (child, 55);
|
2012-02-06 16:26:57 +00:00
|
|
|
gtk_widget_set_margin_top (child, 4);
|
|
|
|
g_print ("Left/Top margined child: %p\n", child);
|
|
|
|
gtk_widget_set_halign (child, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (child, GTK_ALIGN_START);
|
|
|
|
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child);
|
|
|
|
|
|
|
|
child = gtk_label_new (NULL);
|
|
|
|
str = g_strdup_printf ("%p", child);
|
|
|
|
gtk_label_set_text (GTK_LABEL (child), str);
|
|
|
|
g_free (str);
|
|
|
|
g_print ("Custom get-child-position child: %p\n", child);
|
|
|
|
gtk_widget_set_halign (child, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (child, GTK_ALIGN_START);
|
|
|
|
gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child);
|
|
|
|
|
|
|
|
g_signal_connect (overlay, "get-child-position",
|
|
|
|
G_CALLBACK (overlay_get_child_position), child);
|
|
|
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), overlay, 1, 0, 1, 3);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (win), grid);
|
2012-02-06 16:26:57 +00:00
|
|
|
|
|
|
|
g_print ("\n");
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (win);
|
2012-02-06 16:26:57 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (TRUE)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2012-02-06 16:26:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|