[gtkada] Changing the color of a label

Jean-Etienne Doucet doucet at laas.fr
Tue Jun 24 11:49:20 CEST 2003


From: "Jean-Pierre Rosen" <rosen.adalog at wanadoo.fr>
| 
| >    1) [Gtkada 2.0] 
| I want Windows compatibility, so I'm under 1.x
| 
| >    2) [GtkAda 1.X-2.0] put a Evenbox first and then put the label in the
| >       Eventbox. Now you can set the background of the Eventbox. Labels
| >       don't have backgrounds. (I think this works in GtkAda 2.0 too, but
| >       I haven't checked.)
| > 
| > Example for GtkAda 1.x:
| > 
| >       Gtk_New (Background_Eventbox);
| >       Set_Border_Width (Background_Eventbox, 1);
| >       Add (Some_Box, Background_Eventbox);
| > 
| >       Gtk_New (Title_Label, "Title");
| >       Set_Alignment (Title_Label, 0.0, 0.5);
| >       Set_Justify (Title_Label, Justify_Left);
| >       Set_Padding (Title_Label, 3, 1);
| >       Set_Line_Wrap (Title_Label, False);
| >       Add (Background_Eventbox, Title_Label);
| 
| I thought an EventBox was for attaching events, but why not...
| Until this point, I understand.
|  
| >       Background_Eventbox_Style :=
| >                Copy (Get_Style (Background_Eventbox));
| > 
| >       -- Now you can set the background colour on the Eventbox.
| ?? I'm lost here. What is this Background_Eventbox_Style variable?
| And how can I set the background colour of the EventBox? I didn't find a
| procedure for that in the RM...

Thw whole thing should look like this:


with Gtk.Main;       use Gtk.Main;
with Gtk.Widget;     use Gtk.Widget;
with Gtk.Window;     use Gtk.Window;
with Gtk.Box;        use Gtk.Box;
with Gtk.Event_Box;  use Gtk.Event_Box;
with Gtk.Label;      use Gtk.Label;
with Gtk.Style;      use Gtk.Style;
with Gtk.Enums;      use Gtk.Enums;
with Gdk.Color;      use Gdk.Color;


procedure Fond_Blanc is

   Window : Gtk_Window;
   Boite  : Gtk_Box;
   Ev_Box : Gtk_Event_Box;
   Label  : Gtk_Label;
   Blanc  : Gtk_Style;

begin -- Fond_Blanc
   Gtk.Main.Init;
   
   -- create a style with white background
   Blanc := Copy(Get_Default_Style);
   Set_Background (Blanc, State_Normal, White(Get_System));
   
   Gtk_New (Window);
   
   Gtk_New_Vbox (Boite);
   Add (Window, Boite);
   
   Gtk_New (Label, "Fond gris");
   Add (Boite, Label);
   Set_Padding (Label, 20, 10);
   
   -- make the "white" style the current style
   Push_Style (Blanc);
   
   -- create the event box (with the white style)
   Gtk_New (Ev_Box);
   Add (Boite, Ev_Box);
   
   Gtk_New (Label, "Fond blanc");
   Add (Ev_Box, Label);
   Set_Padding (Label, 20, 10);
   
   -- return to the preceding style
   Pop_Style;
   
   Gtk_New (Label, "Fond gris");
   Add (Boite, Label);
   Set_Padding (Label, 20, 10);
   
   Show_All (Window);
   Gtk.Main.Main;
end Fond_Blanc;



More information about the gtkada mailing list