Re: GtkRevealer not Working properly




I don't have any experience with Vala. One day I will get around to spending some time with it. I have never used the GTK revealer either so I figured I would give it a try. It is tough... I still don't understand how to get the settings correct to make it work for the different containers. Got something to work in C though. You can give it a try and see if it is helpful. I just used a drawing area to expand into but it should work with a treeview also. Tried to make it simple so that I could figure the settings out.

Eric


/*
    With Ubuntu16.04 and GTK3.18.
    gcc -Wall revealer1.c -o revealer1 `pkg-config --cflags --libs gtk+-3.0`
*/
#include<gtk/gtk.h>

static gboolean draw_circle(GtkWidget *da, cairo_t *cr, gpointer data)
  {
    gint width=gtk_widget_get_allocated_width(da);
    gint height=gtk_widget_get_allocated_height(da);

    cairo_set_source_rgba(cr, 0.0, 0.0, 1.0, 1.0);
    cairo_paint(cr);
    cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 1.0);
    cairo_set_line_width(cr, 8);
    cairo_arc(cr, width/2, height/2, 100.0*(gdouble)height/400.0, 0.0, 2*G_PI);
    cairo_stroke(cr);
    return FALSE;
  }
static void reveal_button(GtkWidget *widget, gpointer data)
  {
    if(gtk_revealer_get_reveal_child(GTK_REVEALER(data)))
      {
        gtk_revealer_set_reveal_child(GTK_REVEALER(data), FALSE);
      }
    else gtk_revealer_set_reveal_child(GTK_REVEALER(data), TRUE);
  }
int main(int argc, char *argv[])
  {
    gtk_init(&argc, &argv);

    GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Revealer");
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    GtkWidget *da=gtk_drawing_area_new();
    gtk_widget_set_hexpand(da, TRUE);
    gtk_widget_set_vexpand(da, TRUE);
    g_signal_connect(da, "draw", G_CALLBACK(draw_circle), NULL); 

    GtkWidget *button1=gtk_button_new_with_label("Revealer Button");
   
    GtkWidget *button2=gtk_button_new_with_label("Show Revealer Button");
    gtk_widget_set_hexpand(button2, TRUE);

    GtkWidget *revealer=gtk_revealer_new();
    gtk_revealer_set_transition_type(GTK_REVEALER(revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT);
    gtk_revealer_set_reveal_child(GTK_REVEALER(revealer), FALSE);
    //Slow it down a little.
    gtk_revealer_set_transition_duration(GTK_REVEALER(revealer), 2000);
    gtk_container_add(GTK_CONTAINER(revealer), button1);

    g_signal_connect(button2, "clicked", G_CALLBACK(reveal_button), revealer);

    GtkWidget *box=gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
    gtk_box_set_spacing(GTK_BOX(box), 0);
    gtk_box_pack_start(GTK_BOX(box), revealer, TRUE, FALSE, 0);

    GtkWidget *grid=gtk_grid_new();
    gtk_grid_attach(GTK_GRID(grid), box, 0, 0, 1, 5);
    gtk_grid_attach(GTK_GRID(grid), da, 1, 0, 4, 4);
    gtk_grid_attach(GTK_GRID(grid), button2, 1, 4, 4, 1);
    gtk_container_add(GTK_CONTAINER(window), grid);

    gtk_widget_show_all(window);
    gtk_main();
    return 0;  
  }





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]