Page 1 of 1

ListIconGadget - Column alignment

Posted: Thu Jan 28, 2010 9:59 am
by lnxque
Is an example for the column alignment in ListIconGadget available?

Re: ListIconGadget - Column alignment

Posted: Thu Jan 28, 2010 4:34 pm
by Rook Zimbabwe
I am confused by the term... do you mean a way to automatically expand the column to the length of the largest entry?

Or how ot CENTER text in each column header?

:D

Re: ListIconGadget - Column alignment

Posted: Thu Jan 28, 2010 5:09 pm
by lnxque
The last one.

How can i align the text in columns in a ListIconGadget in the middle (center) and right (under Linux)?

Re: ListIconGadget - Column alignment

Posted: Thu Jan 28, 2010 7:15 pm
by freak
The underlying GtkTreeView is quite a beast, so these things are not as simple as in Windows.

Here it is though:

Code: Select all

ImportC ""
  g_object_set_double(*Object, Property.p-ascii, Value.d, NULL) As "g_object_set"
EndImport

; Set Column alignment for given #Gadget and Column
; Alignment should be between 0 and 1
;
Procedure SetColumnAlign(Gadget, Column, Alignment.d)
  Protected *Column, *CellRenderers, Count, Index
 
  *Column = gtk_tree_view_get_column_(GadgetID(Gadget), Column)  
  If *Column
    ; This only aligns the title text
    gtk_tree_view_column_set_alignment_(*Column, Alignment)
 
    ; Align the text renderers as well
    *CellRenderers = gtk_tree_view_column_get_cell_renderers_(*Column)
    If *CellRenderers
      Count = g_list_length_(*CellRenderers)
      For Index = 0 To Count-1
        g_object_set_double(g_list_nth_data_(*CellRenderers, Index), "xalign", Alignment, #Null)
      Next Index         
      g_list_free_(*CellRenderers)
    EndIf
  EndIf
EndProcedure

If OpenWindow(0, 0, 0, 500, 300, "ListIcon Columns", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ListIconGadget(0, 10, 10, 480, 280, "Left", 150)
  AddGadgetColumn(0, 1, "Center", 150)
  AddGadgetColumn(0, 2, "Right", 150)
  
  SetColumnAlign(0, 0, 0.0)
  SetColumnAlign(0, 1, 0.5)
  SetColumnAlign(0, 2, 1.0)
  
  For i = 1 To 10
    AddGadgetItem(0, -1, RSet("", i, "A")+Chr(10)+RSet("", i, "A")+Chr(10)+RSet("", i, "A"))
  Next i

  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: ListIconGadget - Column alignment

Posted: Fri Jan 29, 2010 9:47 am
by lnxque
This was, what i am looking for. Thank you (für Tannenbäumchen ;-)