C

c
mail@pastecode.io avatar
unknown
c_cpp
2 years ago
2.7 kB
1
Indexable
Never
// Include gtk
#include <gtk/gtk.h>

  GtkWidget *label1;
  GtkWidget *label2;
  GtkWidget *label3;

// Handler to change the appearance of the widgets from their original
void button_clicked (GtkButton * button, gpointer   user_data)
{

    // names are defined in the .CSS
    gtk_widget_set_name( GTK_WIDGET(label1) , "" );
    gtk_widget_set_name( GTK_WIDGET(label2) , "menu1" );
    gtk_widget_set_name( GTK_WIDGET(label3) , "" );
}

// Set the style provider for the widgets
static void apply_css_provider (GtkWidget * widget, GtkCssProvider * cssstyleProvider)
{
    gtk_style_context_add_provider ( gtk_widget_get_style_context(widget), GTK_STYLE_PROVIDER(cssstyleProvider) , GTK_STYLE_PROVIDER_PRIORITY_USER );

    // For container widgets, apply to every child widget on the container
    if (GTK_IS_CONTAINER (widget))
    {
        gtk_container_forall( GTK_CONTAINER (widget), (GtkCallback)apply_css_provider , cssstyleProvider);
    }
}


static void on_activate (GtkApplication *app)
{
  GtkWidget *window = gtk_application_window_new (app);

  gtk_window_set_position (GTK_WINDOW(window),GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(window), 400,50);
  gtk_container_set_border_width(GTK_CONTAINER(window),100);
 
  GtkWidget *boxwindows = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
  label1 = gtk_label_new("Nivel 1");
  label2 = gtk_label_new("Nivel 2");
  label3 = gtk_label_new("Nivel 3");
  GtkWidget *btn =  gtk_button_new_with_label ("Siguiente");
  //gtk_widget_set_sensitive(list, FALSE);

  gtk_box_pack_start(GTK_BOX(boxwindows), label1, FALSE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(boxwindows), label2, FALSE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(boxwindows), label3, FALSE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(boxwindows), btn, FALSE, TRUE, 0);


  gtk_container_add(GTK_CONTAINER(window), boxwindows);

  gtk_widget_set_name( label1 , "menu1" );

  GtkCssProvider *cssProvider = gtk_css_provider_new();
  gtk_css_provider_load_from_path(cssProvider, "estilo.css", NULL);
  gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(cssProvider), GTK_STYLE_PROVIDER_PRIORITY_USER);

  g_signal_connect(btn, "clicked", G_CALLBACK(button_clicked), NULL );
  g_signal_connect_swapped (G_OBJECT(window), "destroy", G_CALLBACK (gtk_window_close), window);
  gtk_widget_show_all (window);

}

int main (int argc, char *argv[]) 
{

  GtkApplication *app = gtk_application_new ("By.Cristo.Arcris",
                                             G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
  return g_application_run (G_APPLICATION (app), argc, argv);
}