Page 1 of 1

Sidebar

Posted: Fri Jun 04, 2021 8:07 am
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

Re: Sidebar

Posted: Fri Jun 04, 2021 8:11 am
by Dirk Geppert
Nice! :D Simple & clever - good to know. Thx for sharing