A drawer is a navigation panel that slides in from the edge of the screen, typically from the left, to reveal additional options or content.
Here are the available methods of the Drawer Component.
Examples ##
Example - Drawer Implementation
class Main extends App
{
onStart()
{
this.main = ui.addLayout( "main", "Linear", "VCenter,FillXY")
this.apb = ui.addAppBar(this.main, "My App", "Menu,Fixed")
this.apb.setOnMenu( this.openDrawer )
ui.addText(this.main, "<---- Swipe left ----->", "Center");
this.drawerLay = ui.addLayout(null, "Linear")
this.drawer = ui.addDrawer(this.drawerLay, "left", 0.7)
this.drawer.setOnClose( this.onClose )
var lst1 = [
[ "music_note", "Audios" ],
[ "movie", "Videos" ],
[ "insert_drive_file", "Documents" ]
]
this.lstMenu1 = ui.addList( this.drawerLay, lst1, "Icon", 1 )
this.lstMenu1.label = "Main navigation"
this.lstMenu1.setOnTouch( this.onSelect )
ui.addDivider( this.drawerLay, 1 )
var lst2 = [
[ "mail", "All Mail" ],
[ "inbox", "Inbox" ],
[ "drafts", "Outbox" ],
[ "send", "Sent" ]
]
this.lstMenu2 = ui.addList( this.drawerLay, lst2, "Icon", 1 )
this.lstMenu2.label = "Secondary navigation"
this.lstMenu2.setOnTouch( this.onSelect )
}
openDrawer()
{
this.drawer.show()
}
onSelect(title)
{
this.apb.text = title
ui.showPopup( title )
this.drawer.hide()
}
onClose()
{
ui.showPopup('Drawer is close', "bottom")
}
}
from hybrid import ui
def OnStart():
main = ui.addLayout("main", "Linear", "VCenter,FillXY")
apb = ui.addAppBar(main, "My App", "Menu,Fixed")
apb.setOnMenu(openDrawer)
ui.addText(main, "<---- Swipe left ----->", "Center")
drawerLay = ui.addLayout(None, "Linear")
drawer = ui.addDrawer(drawerLay, "left", 0.7)
drawer.setOnClose(onClose)
lst1 = [
["music_note", "Audios"],
["movie", "Videos"],
["insert_drive_file", "Documents"]
]
lstMenu1 = ui.addList(drawerLay, lst1, "Icon", 1)
lstMenu1.label = "Main navigation"
lstMenu1.setOnTouch(onSelect)
ui.addDivider(drawerLay, 1)
lst2 = [
["mail", "All Mail"],
["inbox", "Inbox"],
["drafts", "Outbox"],
["send", "Sent"]
]
lstMenu2 = ui.addList(drawerLay, lst2, "Icon", 1)
lstMenu2.label = "Secondary navigation"
lstMenu2.setOnTouch(onSelect)
def openDrawer():
drawer.show()
def onSelect(
Example - Drawer Anchor Positions
class Main extends App
{
onStart()
{
this.main = ui.addLayout( "main", "Linear", "VCenter,FillXY")
this.sel = ui.addSelect(this.main, ["Left", "Top", "Right", "Bottom"], "Radio,Outlined", 0.7)
this.sel.label = "Select anchor position"
this.sel.setOnChange(this.onSelect)
this.drawerLay = ui.addLayout( null, "Linear" )
this.drawer = ui.addDrawer( this.drawerLay, "left" )
var lst1 = [
[ "music_note", "Audios" ],
[ "movie", "Videos" ],
[ "insert_drive_file", "Documents" ]
]
this.lstMenu1 = ui.addList( this.drawerLay, lst1, "Icon", 1 )
this.lstMenu1.setOnTouch( this.closeDrawer )
this.lstMenu1.label = "Main navigation"
ui.addDivider( this.drawerLay, 1 )
var lst2 = [
[ "mail", "All Mail" ],
[ "inbox", "Inbox" ],
[ "drafts", "Outbox" ],
[ "send", "Sent" ]
]
this.lstMenu2 = ui.addList( this.drawerLay, lst2, "Icon", 1 )
this.lstMenu2.label = "Secondary navigation"
this.lstMenu2.setOnTouch( this.closeDrawer )
}
openDrawer()
{
this.drawer.show()
}
closeDrawer( title )
{
ui.showPopup( title )
this.drawer.hide()
}
onSelect( value )
{
this.drawer.anchor = value
if(value == "Top" || value == "Bottom") {
this.drawer.width = 0.5
} else {
this.drawer.width = 0.7
}
this.drawer.show()
}
}
class Main extends App
onStart()
this.main = ui.addLayout( "main", "Linear", "VCenter,FillXY")
this.sel = ui.addSelect(this.main, ["Left", "Top", "Right", "Bottom"], "Radio,Outlined", 0.7)
this.sel.label = "Select anchor position"
this.sel.setOnChange(this.onSelect)
this.drawerLay = ui.addLayout( null, "Linear" )
this.drawer = ui.addDrawer( this.drawerLay, "left" )
lst1 = [
[ "music_note", "Audios" ],
[ "movie", "Videos" ],
[ "insert_drive_file", "Documents" ]
]
this.lstMenu1 = ui.addList( this.drawerLay, lst1, "Icon", 1 )
this.lstMenu1.setOnTouch( this.closeDrawer )
this.lstMenu1.label = "Main navigation"
ui.addDivider( this.drawerLay, 1 )
lst2 = [
[ "mail", "All Mail" ],
[ "inbox", "Inbox" ],
[ "drafts", "Outbox" ],
[ "send", "Sent" ]
]
this.lstMenu2 = ui.addList( this.drawerLay, lst2, "Icon", 1 )
this.lstMenu2.label = "Secondary navigation"
this.lstMenu2.setOnTouch( this.closeDrawer )
openDrawer()
this.drawer.show()
closeDrawer( title )
ui.showPopup( title )
this.drawer.hide()
onSelect( value )
this.drawer.anchor = value
if value == "Top" || value == "Bottom":
this.drawer.width = 0.5else
this.drawer.width = 0.7
this.drawer.show()
Properties
The following properties are available on the Drawer object:
Methods
The following methods are available on the Drawer object: