Re: Gdk.color GTree.column ?

Sebastien Ferre <[email protected]>
Newsgroups gmane.comp.lang.ocaml.lib.gtk
Organization IRISA
Message-ID <[email protected]>
In fact, I need to set arbitrary colors from their RGB code.
Is it possible to represent any color as a string ? I only
know the common colors as strings (e.g., white, blue, ...).

---
Sébastien

Eddy2 wrote:
> Hi,
> 
> If you *really* want to use Gdk.color I cannot help you. But if you just
> want to add colors to your treeview, then I have a solution : you may use a
> #RRGGBB string in conjunction with "background" property. Here is a little
> working example :
> 
> -----
> let cols = new GTree.column_list
> let text = cols#add Gobject.Data.string
> let bg_color = cols#add Gobject.Data.string (* We use the well-known string
> type *)
> let model = GTree.list_store cols
> 
> let cell = GTree.cell_renderer_text [`WEIGHT `BOLD; `FOREGROUND "white"]
> 
> let vcol = 
>   let vcol = GTree.view_column ~title:"Exemple" () in
>   vcol#pack cell;
>   vcol#add_attribute cell "text" text;
>   vcol#add_attribute cell "background" bg_color;
>   vcol
> 
> let window = GWindow.window
>   ~title:"Color Demo"
>   ~position:`CENTER 
>   ~width:200
>   ~height:550 ()
> 
> let view =
>   let view = GTree.view ~model ~packing:window#add () in
>   view#append_column vcol;
>   view
> 
> let to_string r g b = Printf.sprintf "#%02x%02x%02x" r g b
> 
> let _ =
>   window#connect#destroy GMain.quit;
>   for i = 0 to 20 do
>     let j = 5 * i in
>     let row = model#append () in
>     model#set ~row ~column:text (Printf.sprintf "Blue %i%%" j);
>     model#set ~row ~column:bg_color (to_string 0 0 j)
>   done;
>   window#show ();
>   GMain.main ()
> -----
> 
> Hope this helps,
> Eddy
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.