/* gcc -g revealer.c $(pkg-config --cflags --libs gtk+-3.0) */

#include <gtk/gtk.h>

static GtkWidget *
create_list_box_row (void)
{
  GtkWidget *grid;
  GtkWidget *label;
  GtkWidget *list_box_row;
  GtkWidget *revealer;

  list_box_row = gtk_list_box_row_new ();

  grid = gtk_grid_new ();
  gtk_orientable_set_orientation (GTK_ORIENTABLE (grid),
                                  GTK_ORIENTATION_VERTICAL);
  gtk_container_add (GTK_CONTAINER (list_box_row), grid);

  label = gtk_label_new ("Click me");
  gtk_container_add (GTK_CONTAINER (grid), label);

  revealer = gtk_revealer_new ();
  gtk_revealer_set_transition_type (GTK_REVEALER (revealer),
                                    GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
  gtk_container_add (GTK_CONTAINER (grid), revealer);

  label = gtk_label_new ("A whole lot of text to read...");
  gtk_container_add (GTK_CONTAINER (revealer), label);

  g_object_set_data (G_OBJECT (list_box_row), "revealer", revealer);
  return list_box_row;
}

static void
list_box_row_activated (GtkListBox *list_box, GtkListBoxRow *list_box_row)
{
  GtkWidget *revealer;

  revealer = g_object_get_data (G_OBJECT (list_box_row), "revealer");
  gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE);
}

static gboolean
slide_in (gpointer user_data)
{
  GtkWidget *revealer = GTK_WIDGET (user_data);

  gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE);
  return G_SOURCE_REMOVE;
}

gint
main (gint argc, gchar *argv[])
{
  GtkSettings *settings;
  GtkWidget *filler;
  GtkWidget *grid;
  GtkWidget *list_box;
  GtkWidget *list_box_row;
  GtkWidget *revealer;
  GtkWidget *window;

  gtk_init (NULL, NULL);

  settings = gtk_settings_get_default ();
  g_object_set (settings, "gtk-enable-animations", FALSE, NULL);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 1000, 575);
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

  grid = gtk_grid_new ();
  gtk_orientable_set_orientation (GTK_ORIENTABLE (grid),
                                  GTK_ORIENTATION_HORIZONTAL);
  gtk_container_add (GTK_CONTAINER (window), grid);

  filler = gtk_text_view_new ();
  gtk_widget_set_hexpand (filler, TRUE);
  gtk_widget_set_vexpand (filler, TRUE);
  gtk_container_add (GTK_CONTAINER (grid), filler);

  revealer = gtk_revealer_new ();
  gtk_revealer_set_transition_type (GTK_REVEALER (revealer),
                                    GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT);
  gtk_container_add (GTK_CONTAINER (grid), revealer);

  list_box = gtk_list_box_new ();
  gtk_widget_set_vexpand (list_box, TRUE);
  gtk_container_add (GTK_CONTAINER (revealer), list_box);
  g_signal_connect (list_box,
                    "row-activated",
                    G_CALLBACK (list_box_row_activated),
                    NULL);

  list_box_row = create_list_box_row ();
  gtk_container_add (GTK_CONTAINER (list_box), list_box_row);

  list_box_row = create_list_box_row ();
  gtk_container_add (GTK_CONTAINER (list_box), list_box_row);

  gtk_widget_show_all (window);
  g_timeout_add_seconds (2, slide_in, revealer);

  gtk_main ();

  return 0;
}
