2013-08-27 03:06:04 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
row_unrevealed (GObject *revealer, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *row, *list;
|
|
|
|
|
|
|
|
row = gtk_widget_get_parent (GTK_WIDGET (revealer));
|
|
|
|
list = gtk_widget_get_parent (row);
|
|
|
|
|
2020-05-08 06:19:18 +00:00
|
|
|
gtk_list_box_remove (GTK_LIST_BOX (list), row);
|
2013-08-27 03:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_this_row (GtkButton *button, GtkWidget *child)
|
|
|
|
{
|
|
|
|
GtkWidget *row, *revealer;
|
|
|
|
|
|
|
|
row = gtk_widget_get_parent (child);
|
|
|
|
revealer = gtk_revealer_new ();
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE);
|
2016-10-12 17:46:23 +00:00
|
|
|
g_object_ref (child);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_remove (GTK_BOX (gtk_widget_get_parent (child)), child);
|
2020-05-02 21:02:42 +00:00
|
|
|
gtk_revealer_set_child (GTK_REVEALER (revealer), child);
|
2016-10-12 17:46:23 +00:00
|
|
|
g_object_unref (child);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (row), revealer);
|
2013-08-27 03:06:04 +00:00
|
|
|
g_signal_connect (revealer, "notify::child-revealed",
|
|
|
|
G_CALLBACK (row_unrevealed), NULL);
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *create_row (const gchar *label);
|
|
|
|
|
|
|
|
static void
|
|
|
|
row_revealed (GObject *revealer, GParamSpec *pspec, gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *row, *child;
|
|
|
|
|
|
|
|
row = gtk_widget_get_parent (GTK_WIDGET (revealer));
|
2020-05-02 21:02:42 +00:00
|
|
|
child = gtk_revealer_get_child (GTK_REVEALER (revealer));
|
2013-08-27 03:06:04 +00:00
|
|
|
g_object_ref (child);
|
2020-05-02 21:02:42 +00:00
|
|
|
gtk_revealer_set_child (GTK_REVEALER (revealer), NULL);
|
2020-05-09 12:26:52 +00:00
|
|
|
|
2020-05-09 14:33:02 +00:00
|
|
|
gtk_widget_unparent (GTK_WIDGET (revealer));
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (row), child);
|
2013-08-27 03:06:04 +00:00
|
|
|
g_object_unref (child);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_row_below (GtkButton *button, GtkWidget *child)
|
|
|
|
{
|
|
|
|
GtkWidget *revealer, *row, *list;
|
|
|
|
gint index;
|
|
|
|
|
|
|
|
row = gtk_widget_get_parent (child);
|
|
|
|
index = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (row));
|
|
|
|
list = gtk_widget_get_parent (row);
|
|
|
|
row = create_row ("Extra row");
|
|
|
|
revealer = gtk_revealer_new ();
|
2020-05-02 21:02:42 +00:00
|
|
|
gtk_revealer_set_child (GTK_REVEALER (revealer), row);
|
2013-08-27 03:06:04 +00:00
|
|
|
g_signal_connect (revealer, "notify::child-revealed",
|
|
|
|
G_CALLBACK (row_revealed), NULL);
|
|
|
|
gtk_list_box_insert (GTK_LIST_BOX (list), revealer, index + 1);
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_separator (GtkListBoxRow *row, GtkListBoxRow *before, gpointer data)
|
|
|
|
{
|
|
|
|
if (!before)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_list_box_row_set_header (row, gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
create_row (const gchar *text)
|
|
|
|
{
|
|
|
|
GtkWidget *row, *label, *button;
|
|
|
|
|
|
|
|
row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
|
|
|
label = gtk_label_new (text);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (row), label);
|
2013-08-27 03:06:04 +00:00
|
|
|
button = gtk_button_new_with_label ("x");
|
|
|
|
gtk_widget_set_hexpand (button, TRUE);
|
|
|
|
gtk_widget_set_halign (button, GTK_ALIGN_END);
|
|
|
|
gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (row), button);
|
2013-08-27 03:06:04 +00:00
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (remove_this_row), row);
|
|
|
|
button = gtk_button_new_with_label ("+");
|
|
|
|
gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (row), button);
|
2013-08-27 03:06:04 +00:00
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (add_row_below), row);
|
|
|
|
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2013-08-27 03:06:04 +00:00
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *window, *list, *sw, *row;
|
|
|
|
gint i;
|
|
|
|
gchar *text;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2013-08-27 03:06:04 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2013-08-27 03:06:04 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2013-08-27 03:06:04 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 300, 300);
|
|
|
|
|
|
|
|
list = gtk_list_box_new ();
|
|
|
|
gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
|
|
|
|
gtk_list_box_set_header_func (GTK_LIST_BOX (list), add_separator, NULL, NULL);
|
2020-06-24 15:25:09 +00:00
|
|
|
sw = gtk_scrolled_window_new ();
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), sw);
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
|
2013-08-27 03:06:04 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 20; i++)
|
|
|
|
{
|
|
|
|
text = g_strdup_printf ("Row %d", i);
|
|
|
|
row = create_row (text);
|
|
|
|
gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
|
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2013-08-27 03:06:04 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2013-08-27 03:06:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|