Is there a way to color a panel?

Just starting out? Need help? Post your questions and find answers here.
Stefan
Posts: 250
Joined: Mon Feb 05, 2018 9:44 pm

Is there a way to color a panel?

Post by Stefan »

Is there a way to color a panel?
User avatar
Peter
Posts: 1198
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Is there a way to color a panel?

Post by Peter »

Here is a code that can be used to colour individual tabs:

Code: Select all

Enumeration
  #Window
  #PanelGadget
EndEnumeration

Procedure SetPanelItemColor(Gadget, Item, ColorType, Color)
  
  If GadgetType(Gadget) <> #PB_GadgetType_Panel
    ProcedureReturn
  EndIf
  
  ! try {
  
  !   const tabHeader = spider_GadgetID(v_gadget).gadget.getChildren()[v_item].controlButton.innerDiv;
  !   const tabBody   = spider_GadgetID(v_gadget).gadget.getChildren()[v_item].containerNode;
  
  Select ColorType
    Case #PB_Gadget_FrontColor
      ! $(tabHeader).css("color", spider_helper_ColorToHtml(v_color));
    Case #PB_Gadget_BackColor
      ! $(tabHeader).css("background-color", spider_helper_ColorToHtml(v_color));
      ! $(tabBody).css("background-color", spider_helper_ColorToHtml(v_color));
  EndSelect
  
  ! } catch (e) {
  !   console.error(e);
  ! }
  
EndProcedure

If OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 300, 150, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  PanelGadget(#PanelGadget, 10, 10, WindowWidth(#Window) - 20, WindowHeight(#Window) - 20)
    AddGadgetItem(#PanelGadget, -1, "Red")
    AddGadgetItem(#PanelGadget, -1, "Green")
    AddGadgetItem(#PanelGadget, -1, "Blue")
  CloseGadgetList()
EndIf

SetPanelItemColor(#PanelGadget, 0, #PB_Gadget_BackColor, #Red)
SetPanelItemColor(#PanelGadget, 0, #PB_Gadget_FrontColor, #White)

SetPanelItemColor(#PanelGadget, 1, #PB_Gadget_BackColor, #Green)
SetPanelItemColor(#PanelGadget, 1, #PB_Gadget_FrontColor, #Black)

SetPanelItemColor(#PanelGadget, 2, #PB_Gadget_BackColor, #Blue)
SetPanelItemColor(#PanelGadget, 2, #PB_Gadget_FrontColor, #White)
Image
Stefan
Posts: 250
Joined: Mon Feb 05, 2018 9:44 pm

Re: Is there a way to color a panel?

Post by Stefan »

Great!
Thank you so much!
Post Reply