Sidebar

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

Sidebar

Post by Peter »

Hello,

this is a simple example who to implement a Sidebar with SpiderBasic:

Code: Select all

EnableExplicit

Enumeration
  #Sidebar
  #ControlWindow
  #ControlWindow_cmdSlideIn
  #ControlWindow_cmdSlideOut
EndEnumeration

Procedure SlideIn(Window)
  
  Protected WID = WindowID(Window)
  
  ! $(v_wid.element).animate({
  !   left: 0
  ! });
  
EndProcedure

Procedure SlideOut(Window)
  
  Protected WID = WindowID(Window)
  Protected WindowWidth = WindowWidth(Window)
  
  ! $(v_wid.element).animate({
  !   left: -v_windowwidth
  ! });
  
EndProcedure

Procedure ButtonEvent()
  
  Select EventGadget()
      
    Case #ControlWindow_cmdSlideIn
      SlideIn(#Sidebar)
      
    Case #ControlWindow_cmdSlideOut
      SlideOut(#Sidebar)
      
  EndSelect
  
EndProcedure

OpenWindow  (#ControlWindow, 0, 0, 120, 100, "SidebarTest", #PB_Window_ScreenCentered)
ButtonGadget(#ControlWindow_cmdSlideIn,  10, 10, 100, 30, "Slide in")
ButtonGadget(#ControlWindow_cmdSlideOut, 10, 50, 100, 30, "Slide out")

BindGadgetEvent(#ControlWindow_cmdSlideIn , @ButtonEvent())
BindGadgetEvent(#ControlWindow_cmdSlideOut, @ButtonEvent())

; Create an example-'Sidebar' on the left side

ExamineDesktops()
OpenWindow(#Sidebar, 0, 0, 200, DesktopHeight(0), "", #PB_Window_BorderLess)

Define newY = 10
Define Counter 
For Counter = 0 To 9
  ButtonGadget(#PB_Any, 10, newY, 180, 50, "Button " + Str(Counter +1))
  newY + 60
Next
Image

Greetings ... Peter
Dirk Geppert
Posts: 282
Joined: Fri Sep 22, 2017 7:02 am

Re: Sidebar

Post by Dirk Geppert »

Nice! :D Simple & clever - good to know. Thx for sharing
Post Reply