ListIcon Selected Row Highlight

Windows specific forum
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

ListIcon Selected Row Highlight

Post by IdeasVacuum »

When you select a ListIcon row (mouse click) it is highlighted by default with the system highlight colour #COLOR_HIGHLIGHT.
However, when a row is selected programmatically, the highlight colour is a faint, dull grey instead. I think it should use #COLOR_HIGHLIGHT. Yes, I can apply the colour myself and keep track of row selections (or just unhighlight the whole list when a different row is selected), but that is a pita if a few cells have their own individual colour.

Is there a really simple way to get PB to use #COLOR_HIGHLIGHT when SetGadgetItemState() is applied?

Code: Select all

Enumeration
#Win
#Panel
#Btn
#List
EndEnumeration

Global iRow.i, iCol.i, iExit.i = #False, iRow05.i = 5
Global sRow.s

Procedure PfSetListRowColours(iList.i, iRowColourEven.i, iRowColourOdd.i)
;#-----------------------------------------------------------------------
Protected       iRow.i
Protected  iRowIsOdd.i = #False
Protected iTotalRows.i = CountGadgetItems(iList)

              For iRow = 0 To (iTotalRows - 1)

                           If(iRowIsOdd = #True)

                                   SetGadgetItemColor(iList, iRow, #PB_Gadget_BackColor, iRowColourOdd, #PB_All)
                                   iRowIsOdd = #False
                           Else
                                   SetGadgetItemColor(iList, iRow, #PB_Gadget_BackColor, iRowColourEven, #PB_All)
                                   iRowIsOdd = #True
                           EndIf
              Next iRow
EndProcedure

If OpenWindow(#Win, 0, 0, 530, 300, "ListIcon Highlight Row", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

          PanelGadget(#Panel, 5, 5, 520, 290)

                  AddGadgetItem(#Panel, 0, "Tab 00")

                              ButtonGadget(#Btn,  10, 10, 200,  30, "Select Row 05")
                            ListIconGadget(#List, 10, 50, 490, 205, "Col 00", 100, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_FullRowSelect)

                           AddGadgetColumn(#List,  1, "Col 01", 100)
                           AddGadgetColumn(#List,  2, "Col 02", 100)
                           AddGadgetColumn(#List,  3, "Col 03", 100)
                           AddGadgetColumn(#List,  4, "Col 04", 100)

                  For iRow = 0 To 10

                         sRow = ""

                         For iCol = 0 To 4

                                sRow = sRow + "Row" + RSet(Str(iRow),2,"0") + " Col" + RSet(Str(iCol),2,"0") + #LF$
                         Next

                         AddGadgetItem(#List, -1, sRow)
                  Next

                  PfSetListRowColours(#List, RGB(210,255,255), RGB(175,215,255))

                  AddGadgetItem(#Panel, 1, "Tab 01")

       CloseGadgetList() ;#Panel

       Repeat
                 Select WaitWindowEvent(1)

                        Case #PB_Event_CloseWindow: iExit = #True

                        Case #PB_Event_Gadget

                              Select EventGadget()

                                     Case #Btn

                                            SetGadgetItemState(#List, iRow05, #PB_ListIcon_Selected)
                                                  SetActiveGadget(#List) ;<---- Solution!
                              EndSelect
                 EndSelect

       Until iExit = #True
EndIf
End
[/size]
Last edited by IdeasVacuum on Sun Jul 16, 2017 1:37 am, edited 2 times in total.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: ListIcon Selected Row Highlight

Post by RASHAD »

Hi IdeasVacuum :P
I am afraid when you know the answer you will kill yourself :mrgreen:

http://www.purebasic.fr/english/viewtop ... =5&t=68655

Code: Select all

                                     Case #Btn

                                            SetGadgetItemState(#List, iRow05, #PB_ListIcon_Selected)
                                            SetActiveGadget(#List)
Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: ListIcon Selected Row Highlight

Post by IdeasVacuum »

:oops: I just don't drink enough coffee Rashad!
Mind you, it is technically a work-around.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: [Solved] ListIcon Selected Row Highlight

Post by RASHAD »

:mrgreen:
Not a workaround but maybe Fred should add SetFocus_() to the native command

BTW:
http://www.purebasic.fr/english/viewtop ... =3&t=68774
No such command for ListIcon()
So you are asking for a new one
Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: [Solved] ListIcon Selected Row Highlight

Post by IdeasVacuum »

ah, GetGadgetText() is officially available for ListIcon (see help), but as-is it is pointless.
Yes yes yes, SetFocus_() should be incorporated :)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: ListIcon Selected Row Highlight

Post by IdeasVacuum »

eek! No no no - neither SetActiveGadget() nor SetFocus_() are the real answer. What PB currently does, which is to change the background colour of the item most recently picked (#PB_ListIcon_AlwaysShowSelection), is correct.

For example, one of my apps has three ListIcons (single column), one each for Day, Month and Year selection, a la Android and the Web. All three ListIcons have a row pre-selected programmatically and all should be highlighted - and indeed they are, but not with #COLOR_HIGHLIGHT. SetActiveGadget()/SetFocus_() can only yield the desired result for one of them.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: [Solved] ListIcon Selected Row Highlight

Post by Dude »

RASHAD wrote:maybe Fred should add SetFocus_() to the native command
Why? What if I want to change the selected item while keeping the gadget focus elsewhere? Example: my user clicks a button to highlight a matching item in the listicon, but the button shouldn't lose the focus after doing it, because the user may want to repeatedly click the button (or press it with Space) to highlight the next match -- like pressing the "Find Next" button with Space in Notepad to find the next occurrence of something in the text. Flipping the focus back and forth would be a pain in the ass. The focus should never change unless the user specifically initiated it.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: ListIcon Selected Row Highlight

Post by RASHAD »

@Dude
SetFocus_() changed all the times with mouse click or changing the focused gadget, right?
SetFocus_() do not act for a single item but the all control SetFocus(hwnd)

Adding SetFocus_() will be only for SetGadgetItemState()(Manually select an item)

@IdeasVacuum
Your request is not available even with Windows API
But only with code

Code: Select all

LoadFont(0,"Arial",12)
If OpenWindow(0, 0, 0, 640, 500, "Keep Selction", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0,  10,  10, 310, 200, "Column 0", 100,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
  SetGadgetFont(0,FontID(0))
  AddGadgetColumn(0, 1, "Column 1" , 150)
  AddGadgetColumn(0, 2, "Column 2" , 150)
  For x = 0 To 100
    AddGadgetItem(0, x, "Item "+Str(x)+Chr(10)+"Item "+Str(x)+Chr(10)+"Item "+Str(x))
  Next
  
  ListIconGadget(1,  320,  10, 310, 200, "Column 0", 100,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
  SetGadgetFont(1,FontID(0))
  AddGadgetColumn(1, 1, "Column 1" , 150)
  AddGadgetColumn(1, 2, "Column 2" , 150)
  For x = 0 To 100
    AddGadgetItem(1, x, "Item "+Str(x)+Chr(10)+"Item "+Str(x)+Chr(10)+"Item "+Str(x))
  Next
  
  ListIconGadget(2,  10,  220, 310, 200, "Column 0", 100,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
  SetGadgetFont(2,FontID(0))
  AddGadgetColumn(2, 1, "Column 1" , 150)
  AddGadgetColumn(2, 2, "Column 2" , 150)
  For x = 0 To 100
    AddGadgetItem(2, x, "Item "+Str(x)+Chr(10)+"Item "+Str(x)+Chr(10)+"Item "+Str(x))
  Next
  
  ListIconGadget(3,  320,  220, 310, 200, "Column 0", 100,#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
  SetGadgetFont(3,FontID(0))
  AddGadgetColumn(3, 1, "Column 1" , 150)
  AddGadgetColumn(3, 2, "Column 2" , 150)
  For x = 0 To 100
    AddGadgetItem(3, x, "Item "+Str(x)+Chr(10)+"Item "+Str(x)+Chr(10)+"Item "+Str(x))
  Next
  
  Dim olditem(3)
  ButtonGadget(4,10,470,100,20,"Select LI 0 Row 5")

EndIf
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0 To 3
            titem = GetGadgetState(EventGadget())
            SetGadgetItemColor(EventGadget(),olditem(EventGadget()), #PB_Gadget_BackColor,$FFFFFF)
            SetGadgetItemColor(EventGadget(),olditem(EventGadget()), #PB_Gadget_FrontColor,$0)             
            SetGadgetItemColor(EventGadget(),titem, #PB_Gadget_BackColor,GetSysColor_(#COLOR_HIGHLIGHT))
            SetGadgetItemColor(EventGadget(),titem, #PB_Gadget_FrontColor,$FFFFFF)
            olditem(EventGadget()) = titem
            If litem > 0
              SetActiveGadget(EventGadget())
            EndIf
            
        Case 4
            titem = 5
            SetGadgetItemColor(0,olditem(0), #PB_Gadget_BackColor,$FFFFFF)
            SetGadgetItemColor(0,olditem(0), #PB_Gadget_FrontColor,$0)             
            SetGadgetItemColor(0,titem, #PB_Gadget_BackColor,GetSysColor_(#COLOR_HIGHLIGHT))
            SetGadgetItemColor(0,titem, #PB_Gadget_FrontColor,$FFFFFF)
            olditem(0) = titem
            
      EndSelect
  EndSelect
Until Quit = 1
Egypt my love
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: ListIcon Selected Row Highlight

Post by Dude »

SetFocus_() is the same as SetActiveGadget(), so I wouldn't want the active gadget to be changed just because I manually set a listicon item.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: ListIcon Selected Row Highlight

Post by IdeasVacuum »

Yeah, agreed Dude. Currently PB 'highlights' a programmatically picked item (#PB_ListIcon_AlwaysShowSelection) with a dull grey colour that is at best difficult to see. That is what I believe should be changed - just common sense.
http://www.purebasic.fr/english/viewtop ... 13&t=68737

Hi Rashad, beat you to it and incorporated that method for my Day/Month/Year ListIcon trio, but there are two points about that. (1) Shouldn't really have to do it, the only reason it is necessary is the poor quality of the current arrangement.
(2) It gets a bit complicated when individual cells of a large ListIcon temporarily have their own background colour, defined at runtime by the User.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply