Popover is very useful on showing additional info or displaying instructions especially when the control is click or hovered.
These are the methods available for the Popover Component.
Example - Positioning
class Main extends App
{
onStart()
{
this.aorigin = "tl"
this.torigin = "tl"
this.main = ui.addLayout("main", "Linear", "VCenter,FillXY")
this.main.setChildMargins(null, 2, null, 2, "rem")
var lay = ui.addLayout(this.main, "Linear", "Horizontal", 1)
lay.childSpacing = "around"
var sels = "Top-Left,Top-Center,Top-Right,Center-Left,Center-Center,Center-Right,Bottom-Left,Bottom-Center,Bottom-Right"
this.selAOrigin = ui.addSelect(lay, sels.split(","), "Filled", 0.4)
this.selAOrigin.label = "anchorOrigin"
this.selAOrigin.setOnTouch(m => {
m = m.toLowerCase()
var c = m.split("-")
this.aorigin = c[0][0]+c[1][0]
this.update()
})
this.selTOrigin = ui.addSelect(lay, sels.split(","), "Filled", 0.4)
this.selTOrigin.label = "transformOrigin"
this.selTOrigin.setOnTouch(m => {
m = m.toLowerCase()
var c = m.split("-")
this.torigin = c[0][0]+c[1][0]
this.update()
})
this.posTxt = ui.addText(this.main, "Position: tl,tl")
this.btn = ui.addButton(this.main, "Show here")
}
update() {
var pos = this.aorigin+","+this.torigin
this.posTxt.text = "Position: "+pos
this.pop = ui.showPopover(this.btn, "This is a popover message", pos)
setTimeout(() => {
this.pop.hide()
}, 1000)
}
}
from hybrid import ui
def OnStart():
main = ui.addLayout("main", "Linear", "VCenter,Horizontal", 1, 1)
lay1 = ui.addLayout(main, "Linear", "VCenter", 0.5, 1)
lay1.setChildMargins(0, 0.05)
ui.addText(lay1, "Position on parent", "h5")
btn = ui.addButton(lay1, "Top-Left")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "tl,tl"))
btn = ui.addButton(lay1, "Top-Center")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "tc,tl"))
btn = ui.addButton(lay1, "Top-Right")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "tr,tl"))
btn = ui.addButton(lay1, "Center-Left")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "cl,tl"))
btn = ui.addButton(lay1, "Center-Center")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "cc,tl"))
btn = ui.addButton(lay1, "Center-Right")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "cr,tl"))
btn = ui.addButton(lay1, "Bottom-Left")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "bl,tl"))
btn = ui.addButton(lay1, "Bottom-Center")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "bc,tl"))
btn = ui.addButton(lay1, "Bottom-Right")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "br,tl"))
lay2 = ui.addLayout(main, "Linear", "VCenter", 0.5, 1)
lay2.setChildMargins(0, 0.05)
ui.addText(lay2, "Origin on popover", "h5")
btn = ui.addButton(lay2, "Top-Left")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "tl,tl"))
btn = ui.addButton(lay2, "Top-Center")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "tl,tc"))
btn = ui.addButton(lay2, "Top-Right")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "tl,tr"))
btn = ui.addButton(lay2, "Center-Left")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "tl", "cl"))
btn = ui.addButton(lay2, "Center-Center")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "tl,cc"))
btn = ui.addButton(lay2, "Center-Right")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "tl,cr"))
btn = ui.addButton(lay2, "Bottom-Left")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "tl,bl"))
btn = ui.addButton(lay2, "Bottom-Center")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "tl,bc"))
btn = ui.addButton(lay2, "Bottom-Right")
btn.setOnTouch(lambda event: ui.showPopover("This is a popover message", "tl,br"))
Example - Advanced
class Main extends App
{
onStart()
{
this.main = ui.addLayout( "main", "Linear", "VCenter", 1, 1 )
this.btn = ui.addButton( this.main, "Show Popover" )
this.btn.setOnTouch( this.onTouch )
}
onTouch() {
var lay = ui.addLayout(null, "Linear", "VCenter,Left")
lay.setChildMargins(0.1, 0.05, 0.1, 0.05)
ui.addText(lay, "Header", "h5")
ui.addText(lay, "This is a very long text to display in this popover", "Left")
this.popBtn = ui.addButton(lay, "Close", "Outlined", "Secondary")
this.popBtn.setOnTouch( this.closePopover )
this.pop = ui.showPopover( this.btn, lay, "bl,tr")
}
closePopover() {
this.pop.hide()
}
}
from hybrid import ui
def OnStart():
global btn
main = ui.addLayout("main", "Linear", "VCenter", 1, 1)
btn = ui.addButton(main, "Show Popover")
btn.setOnTouch(onTouch)
def onTouch(event):
lay = ui.addLayout(None, "Linear", "VCenter,Left")
lay.setChildMargins(0.1, 0.05, 0.1, 0.05)
ui.addText(lay, "Header", "h5")
ui.addText(lay, "This is a very long text to display in this popover", "Left")
ui.addButton(lay, "Outlined Button", "Outlined", "Secondary")
ui.showPopover(btn, lay, "bl,tr")