ListIconGadget - right align a column's content

Just starting out? Need help? Post your questions and find answers here.
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

ListIconGadget - right align a column's content

Post by the.weavster »

Is it possible to right align the contents of a particular column of a ListIconGadget?

Thanks
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: ListIconGadget - right align a column's content

Post by the.weavster »

Bump.

I have the potential of a large project looming and this is going to be important for me.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: ListIconGadget - right align a column's content

Post by Peter »

Hi,

here are two procedures (SetColumnHeaderAlignment() and SetColumnAlignment()) that should solve your problem:

Code: Select all

Enumeration
  #Window
  #ListIconGadget
EndEnumeration

Procedure SetColumnHeaderAlignment(Column, Alignment.s)
  ! $("<style/>", {text: ".dgrid-cell.dgrid-column-" + v_column + "[role='columnheader'] {text-align: " + v_alignment + ";}"}).appendTo('head');    
EndProcedure

Procedure SetColumnAlignment(Column, Alignment.s)
  ! $("<style/>", {text: ".dgrid-cell.dgrid-column-" + v_column + "[role='gridcell'] {text-align: " + v_alignment + ";}"}).appendTo('head');    
EndProcedure

OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 800, 400, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(#ListIconGadget, 0, 0, 800, 400, "Column 0", 300, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)

AddGadgetColumn(#ListIconGadget, 1, "Column 1", 400)

SetColumnHeaderAlignment(0, "center")
SetColumnAlignment(0, "right")

SetColumnHeaderAlignment(1, "right")
SetColumnAlignment(1, "center")

Define Counter

For Counter = 0 To 9
  AddGadgetItem(#ListIconGadget, -1, "Column 0 / Row " + Counter + #LF$ + "Column 1 / Row " + Counter)
Next

Greetings ... Peter
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: ListIconGadget - right align a column's content

Post by the.weavster »

Thank you very much, Peter :D
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: ListIconGadget - right align a column's content

Post by the.weavster »

Peter, may I ask where you found the reference documents that enable you to figure this out? I'd really like to see what enhancements are possible for the ListIconGadget.

Is it possible to refine your function from this:
SetColumnAlignment(Column, Alignment.s)

to this:
SetColumnAlignment(GadgetID,Column, Alignment.s)

I also like to put a window's event handlers in its own code file, so for example I handle gadget events like this:

Code: Select all

Procedure HandleGadgetEvents()
  evWindow = EventWindow() 
  evGadget = EventGadget()
  evType   = EventType()
  evX      = 0 : evY = 0
  If GadgetType(evGadget) = #PB_GadgetType_Canvas
    evX = GetGadgetAttribute(evGadget,#PB_Canvas_MouseX)
    evY = GetGadgetAttribute(evGadget,#PB_Canvas_MouseY)
  ElseIf GadgetType(evGadget) = #PB_GadgetType_ListIcon
    ; how to set evX and evY to the cell clicked by the user?
  EndIf
  Select evWindow
    Case #frmHeadings
      frmHeadings_GadgetEvents(evGadget,evType,evX,evY)
   ; etc...   
  EndSelect  
EndProcedure

BindEvent(#PB_Event_Gadget,@HandleGadgetEvents())
So I need to figure out how to get the row and column of the cell the user clicked in the ListIconGadget.

Thanks.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: ListIconGadget - right align a column's content

Post by Peter »

the.weavster wrote:Is it possible to refine your function from this: [...] to this:
SetColumnAlignment(GadgetID,Column, Alignment.s)
[X] Done. It's now integrated in my ListIconGadgetEx-Module (see below).
the.weavster wrote:So I need to figure out how to get the row and column of the cell the user clicked in the ListIconGadget.
please take a look at this repository: https://github.com/spiderbytes/ListIconGadgetEx (BindCellClick)

Greetings ... Peter
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: ListIconGadget - right align a column's content

Post by the.weavster »

Thanks again, Peter.

Sorry to be a pain in the neck but would it be possible to to enhance the row color commands so the colors can be set on a gadget by gadget basis?

i.e.

Code: Select all

SetEvenRowColor(RowColor.s, SelectedRowColor.s, TextColor.s, SelectedTextColor.s)
becomes:

Code: Select all

SetEvenRowColor(Gadget, RowColor.s, SelectedRowColor.s, TextColor.s, SelectedTextColor.s)
Thanks.
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: ListIconGadget - right align a column's content

Post by Peter »

the.weavster wrote:would it be possible to to enhance the row color commands so the colors can be set on a gadget by gadget basis?
[X] Done: https://github.com/spiderbytes/ListIconGadgetEx

Greetings ... Peter
the.weavster
Posts: 220
Joined: Sat Mar 01, 2014 3:02 pm

Re: ListIconGadget - right align a column's content

Post by the.weavster »

Thank you, Peter :D
Dirk Geppert
Posts: 282
Joined: Fri Sep 22, 2017 7:02 am

Re: ListIconGadget - right align a column's content

Post by Dirk Geppert »

Thank you Peter. Would it be possible to extend the ListiconGadget() that you can sort with it?
Post Reply