ListIconGadget: Better selection color when gadget inactive?

Just starting out? Need help? Post your questions and find answers here.
novablue
Enthusiast
Enthusiast
Posts: 165
Joined: Sun Nov 27, 2016 6:38 am

ListIconGadget: Better selection color when gadget inactive?

Post by novablue »

Hi, when i select an item in the ListIconGadget and it becomes not the active gadget then the selection is barely visible (light grey). How can i change the color of it so it stays always good visible as if the gadget was active?

Code: Select all

EnableExplicit

Define Event, Timer = ElapsedMilliseconds(), State

If OpenWindow(0, 100, 100, 300, 150, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(0, 5, 5, 295, 20, "Test")
    ListIconGadget(1, 5, 25, 290, 120, "Name", 270, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
    AddGadgetItem(1, -1, "Line 1")
    AddGadgetItem(1, -1, "Line 2")
    AddGadgetItem(1, -1, "Line 3")
    SetGadgetState(1, 1)
    
    Repeat
        Event = WaitWindowEvent(10)
        If (ElapsedMilliseconds() - Timer > 1000)
           State ! 1
           SetActiveGadget(State) 
           Timer = ElapsedMilliseconds()
        EndIf
    Until Event = #PB_Event_CloseWindow
EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: ListIconGadget: Better selection color when gadget inactive?

Post by RASHAD »

Simple for Windows
Tested with Windows 11

Code: Select all

Import "UxTheme.lib"
  SetWindowTheme(hWnd, Body.p-unicode, pszSubIdList)
EndImport

Define Event, Timer = ElapsedMilliseconds(), State

If OpenWindow(0, 100, 100, 300, 150, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(0, 5, 5, 295, 20, "Test")
    ListIconGadget(1, 5, 25, 290, 120, "Name", 270, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
    AddGadgetItem(1, -1, "Line 1")
    AddGadgetItem(1, -1, "Line 2")
    AddGadgetItem(1, -1, "Line 3")
    SetGadgetState(1, 1)
    SetWindowTheme(GadgetID(1), "EXPLORER", 0)
    Repeat
        Event = WaitWindowEvent(10)
        If (ElapsedMilliseconds() - Timer > 1000)
           State ! 1
           SetActiveGadget(State)
           Timer = ElapsedMilliseconds()
        EndIf
        
        
    Until Event = #PB_Event_CloseWindow
EndIf
Or use Dark Mode :lol:

Code: Select all

Define Event, Timer = ElapsedMilliseconds(), State

If OpenWindow(0, 100, 100, 300, 150, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(0, 5, 5, 295, 20, "Test")
    ListIconGadget(1, 5, 25, 290, 120, "Name", 270, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
    SetGadgetColor(1,#PB_Gadget_BackColor ,$000000)
    SetGadgetColor(1,#PB_Gadget_FrontColor ,$FFFFFF)
    AddGadgetItem(1, -1, "Line 1")
    AddGadgetItem(1, -1, "Line 2")
    AddGadgetItem(1, -1, "Line 3")
    SetGadgetState(1, 1)
    Repeat
        Event = WaitWindowEvent(10)
        If (ElapsedMilliseconds() - Timer > 1000)
           State ! 1
           SetActiveGadget(State)
           Timer = ElapsedMilliseconds()
        EndIf
        
        
    Until Event = #PB_Event_CloseWindow
EndIf
Or search the forum for Keep ListIcon Selection
Egypt my love
novablue
Enthusiast
Enthusiast
Posts: 165
Joined: Sun Nov 27, 2016 6:38 am

Re: ListIconGadget: Better selection color when gadget inactive?

Post by novablue »

Thanks i like the first solution. Any way to change the color completely? :D
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: ListIconGadget: Better selection color when gadget inactive?

Post by ChrisR »

A way to change the color

Code: Select all

Import ""
  PB_Object_EnumerateStart( PB_Objects )
  PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
  PB_Object_EnumerateAbort( PB_Objects )
EndImport
  
Procedure SetExplorerTheme(Theme.s)
  Protected Gadget
  PB_Object_EnumerateStart(PB_Gadget_Objects)
  While PB_Object_EnumerateNext(PB_Gadget_Objects, @Gadget)
    ;Select GadgetType(Gadget)
    ;  Case #PB_GadgetType_ScrollArea, #PB_GadgetType_ScrollBar, #PB_GadgetType_Tree, #PB_GadgetType_ComboBox
        SetWindowTheme_(GadgetID(Gadget), @Theme, 0)
    ;EndSelect
  Wend
  PB_Object_EnumerateAbort(PB_Gadget_Objects)
EndProcedure

If DarkTheme And OSVersion() >= #PB_OS_Windows_10
  BackGroundColor =  $202020
  SetExplorerTheme("DarkMode_Explorer")
Else
  BackGroundColor =  $FFEEE8 
  SetExplorerTheme("Explorer")
EndIf
SetWindowColor(#Window, BackGroundColor)
SetGadgetColor(#Container, #PB_Gadget_BackColor, BackGroundColor)
novablue
Enthusiast
Enthusiast
Posts: 165
Joined: Sun Nov 27, 2016 6:38 am

Re: ListIconGadget: Better selection color when gadget inactive?

Post by novablue »

ChrisR wrote: Fri Jan 28, 2022 3:26 pm A way to change the color

Code: Select all

Import ""
  PB_Object_EnumerateStart( PB_Objects )
  PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
  PB_Object_EnumerateAbort( PB_Objects )
EndImport
  
Procedure SetExplorerTheme(Theme.s)
  Protected Gadget
  PB_Object_EnumerateStart(PB_Gadget_Objects)
  While PB_Object_EnumerateNext(PB_Gadget_Objects, @Gadget)
    ;Select GadgetType(Gadget)
    ;  Case #PB_GadgetType_ScrollArea, #PB_GadgetType_ScrollBar, #PB_GadgetType_Tree, #PB_GadgetType_ComboBox
        SetWindowTheme_(GadgetID(Gadget), @Theme, 0)
    ;EndSelect
  Wend
  PB_Object_EnumerateAbort(PB_Gadget_Objects)
EndProcedure

If DarkTheme And OSVersion() >= #PB_OS_Windows_10
  BackGroundColor =  $202020
  SetExplorerTheme("DarkMode_Explorer")
Else
  BackGroundColor =  $FFEEE8 
  SetExplorerTheme("Explorer")
EndIf
SetWindowColor(#Window, BackGroundColor)
SetGadgetColor(#Container, #PB_Gadget_BackColor, BackGroundColor)
I can't get this to work, IMA on line 9 "PB_Object_EnumerateStart(PB_Gadget_Objects)". Can you post a code with a full example?
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: ListIconGadget: Better selection color when gadget inactive?

Post by ChrisR »

The piece of code was not intended to be functional and PB_Gadget_Objects was missing in import.
Here is an example

Code: Select all

Import ""
  PB_Object_EnumerateStart(PB_Objects)
  PB_Object_EnumerateNext(PB_Objects, *ID.Integer )
  PB_Object_EnumerateAbort(PB_Objects)
  PB_Gadget_Objects
EndImport

Procedure SetExplorerTheme(Theme.s)
  Protected Gadget
  PB_Object_EnumerateStart(PB_Gadget_Objects)
  While PB_Object_EnumerateNext(PB_Gadget_Objects, @Gadget)
    SetWindowTheme_(GadgetID(Gadget), @Theme, 0)
  Wend
  PB_Object_EnumerateAbort(PB_Gadget_Objects)
EndProcedure

Procedure ChangeTheme(DarkTheme = #False)
  If DarkTheme And OSVersion() >= #PB_OS_Windows_10
    BackGroundColor =  $404040
    FrontColor = #White
    SetExplorerTheme("DarkMode_Explorer")
  Else 
    BackGroundColor =  $FFFFFF
    FrontColor = #Black
    SetExplorerTheme("Explorer")
  EndIf
  SetWindowColor(0, BackGroundColor)
  SetGadgetColor(1, #PB_Gadget_BackColor, BackGroundColor)
  SetGadgetColor(1, #PB_Gadget_FrontColor, FrontColor)
  SetGadgetColor(2, #PB_Gadget_BackColor, BackGroundColor)
  SetGadgetColor(2, #PB_Gadget_FrontColor, FrontColor)
EndProcedure

Define Event

If OpenWindow(0, 100, 100, 300, 230, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(0, 5, 5, 290, 25, "Change Theme", #PB_Button_Toggle)
  ListIconGadget(1, 5, 30, 290, 120, "Name", 270, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
  AddGadgetItem(1, -1, "Line 1") 
  AddGadgetItem(1, -1, "Line 2")
  AddGadgetItem(1, -1, "Line 3")
  SetGadgetState(1, 1)
  TreeGadget(2, 5, 150, 290, 75, #PB_Tree_AlwaysShowSelection)
  AddGadgetItem(2, -1, "Node", 0,  0)
  AddGadgetItem(2, -1, "Sub-element", 0,  1)
  AddGadgetItem(2, -1, "Element", 0,  0)
  SetGadgetItemState(2, 0, #PB_Tree_Expanded)
  SetGadgetState(2, 1)
  ChangeTheme()
  
  Repeat 
    Event = WaitWindowEvent()
    Select Event
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            ChangeTheme(GetGadgetState(0))
        EndSelect
    EndSelect
  Until Event = #PB_Event_CloseWindow
EndIf
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: ListIconGadget: Better selection color when gadget inactive?

Post by BarryG »

novablue wrote: Fri Jan 28, 2022 11:22 amHi, when i select an item in the ListIconGadget and it becomes not the active gadget then the selection is barely visible (light grey).
In case you're not aware, that's because of your system's color scheme that you've selected. It's not a PureBasic color choice. PureBasic's listicons just use the colors set by the OS.
Post Reply