gtk2/tests/testscrolltofocus.c
Matthias Clasen 67759d4c3e Use gtk_scrolled_window_set_child throughout
Replace all uses of gtk_container_add on popovers
by gtk_scrolled_window_set_child.
2020-05-04 22:53:07 -04:00

44 lines
1.3 KiB
C

#include <gtk/gtk.h>
int main (int argc, char *argv[])
{
GtkWidget *window, *sw, *viewport, *grid;
GtkWidget *entry;
int i, j;
char *text;
gtk_init ();
window = gtk_window_new ();
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (window), sw);
viewport = gtk_viewport_new (gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (sw)),
gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (sw)));
gtk_viewport_set_scroll_to_focus (GTK_VIEWPORT (viewport), TRUE);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), viewport);
grid = gtk_grid_new ();
gtk_widget_set_margin_start (grid, 20);
gtk_widget_set_margin_end (grid, 20);
gtk_widget_set_margin_top (grid, 20);
gtk_widget_set_margin_bottom (grid, 20);
gtk_viewport_set_child (GTK_VIEWPORT (viewport), grid);
for (i = 0; i < 20; i++)
for (j = 0; j < 20; j++)
{
entry = gtk_entry_new ();
text = g_strdup_printf ("(%d, %d)", i, j);
gtk_editable_set_text (GTK_EDITABLE (entry), text);
g_free (text);
gtk_editable_set_width_chars (GTK_EDITABLE (entry), 6);
gtk_grid_attach (GTK_GRID (grid), entry, i, j, 1, 1);
}
gtk_window_present (GTK_WINDOW (window));
while (1)
g_main_context_iteration (NULL, FALSE);
return 0;
}