Share your advanced knowledge/code with the community.
User avatar
Peter
 
Posts: 625
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Module ListIconGadgetEx: RenderCell()

by Peter Sat Oct 12, 2019 10:21 am

Howdy,

maybe you already know my module ListIconGadgetEx, which offers several functions that SpiderBasic does not support natively.

https://github.com/spiderbytes/ListIconGadgetEx

A new procedure called RenderCell() has been added, which allows to manipulate the data output. This allows you to influence the appearance of your data.

Example:
Code: Select all
EnableExplicit

XIncludeFile "ListIconGadgetEx.sbi"

Enumeration
  #Window
  #ListIconGadget
EndEnumeration

Procedure.s RenderCell(Row, Col, Text.s, TD, ListIconGadget)
 
  ; We want to set the text color depending on the amount:
 
  Protected TextColor.s
 
  If Val(Text) > 0
   
    ; incomming -> that's good! :-)
    TextColor = "green"
   
  ElseIf Val(Text) < 0
   
    ; outgoing  -> that's bad :-(
    TextColor = "red"
   
  ElseIf Val(Text) = 0
   
    ; 0 -> neutral
    TextColor = "black"
   
  EndIf
 
  ! $(v_td).css("color", v_textcolor)
 
  ! $(v_td).css("text-align", "right"); // the column is right-aligned
 
  ; Now we change the output text:
 
  ; Please keep in mind that this only affects the *output*
  ; and GetGadget(Item)Text() still returns the Amount (without the '€'-sign)
 
  Text + " €"
 
  ! $(v_td).text(v_text);
 
EndProcedure

OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 250, 200, "RenderCell Demo 1", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ListIconGadget(#ListIconGadget, 0, 0, WindowWidth(#Window), WindowHeight(#Window), "Description", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)

AddGadgetColumn(#ListIconGadget, 1, "Amount", 100)

AddGadgetItem(#ListIconGadget, -1, "Salary"        + #LF$ + "2000")
AddGadgetItem(#ListIconGadget, -1, "Food & Drinks" + #LF$ + "-500")
AddGadgetItem(#ListIconGadget, -1, "Car Petrol"    + #LF$ + "-160")
AddGadgetItem(#ListIconGadget, -1, "Internet"      + #LF$ + "-50")

ListIconGadgetEx::RenderCell(#ListIconGadget, 1, @RenderCell()) ; we want to render the Amount-Column


Image

Greetings ... Peter
User avatar
Paul
 
Posts: 57
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada

Re: Module ListIconGadgetEx: RenderCell()

by Paul Sat Oct 12, 2019 2:10 pm

Very nice Peter !!

Thanks.
Return to Tricks 'n' Tips

Who is online

Users browsing this forum: No registered users and 2 guests