c

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

  GtkWidget *label1;
  GtkWidget *label2;

// Handler to change the appearance of the widgets from their original
void button_clicked1 (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" );
}

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

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

// 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),20);*/
 
  GtkWidget *boxwindows = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
  GtkWidget *box_izquierda = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
  GtkWidget *box_centro = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
  GtkWidget *box_derecha = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);

  label1 = gtk_label_new("Nivel 1");
  label2 = gtk_label_new("Nivel 2");

  GtkWidget *btn_sig =  gtk_button_new_with_label ("Siguiente");
  GtkWidget *btn_ant =  gtk_button_new_with_label ("Anterior");
  //gtk_widget_set_sensitive(list, FALSE);

  gtk_box_pack_start(GTK_BOX(boxwindows), box_izquierda, FALSE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(boxwindows), box_centro, FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(boxwindows), box_derecha, TRUE, FALSE, 0);

  gtk_box_pack_start(GTK_BOX(box_izquierda), label1, FALSE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(box_izquierda), label2, FALSE, TRUE, 0);
  gtk_widget_set_size_request (box_izquierda,150, 100);

  GtkWidget *separador = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
  gtk_box_pack_start(GTK_BOX(box_centro), separador, TRUE, TRUE, 0);
  //gtk_widget_set_size_request (separador,10, 0);


  gtk_box_pack_start(GTK_BOX(box_derecha), btn_ant, FALSE, TRUE, 10);
  gtk_box_pack_start(GTK_BOX(box_derecha), btn_sig, FALSE, TRUE, 10);
  gtk_widget_set_size_request (btn_ant,150, 20);
  gtk_widget_set_size_request (btn_sig,150, 20);
  gtk_container_set_border_width(GTK_CONTAINER(box_derecha),50);


  gtk_container_add(GTK_CONTAINER(window), boxwindows);

  gtk_widget_set_name( label1 , "menu1" );
  gtk_widget_set_name( separador , "box_centro" );
  gtk_widget_set_name( box_izquierda , "box_izquierda" );


  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_sig, "clicked", G_CALLBACK(button_clicked1), NULL );
  g_signal_connect(btn_ant, "clicked", G_CALLBACK(button_clicked2), 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);
}








/* https://gist.github.com/heckflosse/99d747c9bb5a7601fd92542b486b2f34 */

window {
    background-color: #191919;

}

#menu1 {
    background-color: rgba(255,255,255,.20);
    color: #ffffff;
    font: 13px Sans;
    border-width:20px;
    padding-top: 8px;
    padding-bottom: 8px; 
    border-radius: 0px;
    border-color: #202020;
    font-weight : 600;
}

#box_centro {
    background-color: #000000;
    padding: 1px;
}


#box_izquierda {
    background-color: #1E2832;
    box-shadow: none;
    color: #ffffff;
    font: 12px Sans;
    border-width:20px;
    padding-top: 20px;
    border-color: #202020;
    font-weight : 500;
}