本文整理匯總了Golang中github.com/icza/gowut/gwu.Event.Session方法的典型用法代碼示例。如果您正苦於以下問題:Golang Event.Session方法的具體用法?Golang Event.Session怎麽用?Golang Event.Session使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/icza/gowut/gwu.Event
的用法示例。
在下文中一共展示了Event.Session方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: buildTimerDemo
func buildTimerDemo(event gwu.Event) gwu.Comp {
p := gwu.NewPanel()
p.SetCellPadding(3)
// Add timers to a panel which is always attached instead of our panel
// because the user can switch to another component demo causing this panel to be removed
// and that way timer events would address components that are not part of the window (returning error).
hiddenPan := event.Session().Attr("hiddenPan").(gwu.Panel)
p.Add(gwu.NewLabel("A Timer is used to detonate a bomb after 3 seconds."))
p.AddVSpace(10)
defText := "You can defuse the bomb with the button below. Tick... Tack..."
l := gwu.NewLabel(defText)
p.Add(l)
t := gwu.NewTimer(3 * time.Second)
b := gwu.NewButton("Defuse!")
t.AddEHandlerFunc(func(e gwu.Event) {
l.SetText("BOOOOM! You were too slow!")
l.Style().SetColor(gwu.CLR_RED)
b.SetEnabled(false)
e.MarkDirty(l, b)
}, gwu.ETYPE_STATE_CHANGE)
hiddenPan.Add(t)
row := gwu.NewHorizontalPanel()
b.AddEHandlerFunc(func(e gwu.Event) {
t.SetActive(false)
l.SetText("Bomb defused! Phew! Good Job!")
l.Style().SetColor(gwu.CLR_GREEN)
b.SetEnabled(false)
e.MarkDirty(t, l, b)
}, gwu.ETYPE_CLICK)
row.Add(b)
b2 := gwu.NewButton("Plant a new Bomb!")
b2.AddEHandlerFunc(func(e gwu.Event) {
t.SetActive(true)
t.Reset()
l.SetText(defText)
l.Style().SetColor("")
b.SetEnabled(true)
e.MarkDirty(t, l, b)
}, gwu.ETYPE_CLICK)
row.Add(b2)
p.Add(row)
p.AddVSpace(20)
p.Add(gwu.NewLabel("A Timer is used to refresh the time below repeatedly in every second for half a minute."))
tl := gwu.NewLabel("")
p.Add(tl)
t2 := gwu.NewTimer(time.Second)
t2.SetRepeat(true)
counter := 30
t2.AddEHandlerFunc(func(e gwu.Event) {
counter--
tl.SetText(fmt.Sprintf("%s (%d remaining)", time.Now().Format("2006-01-02 15:04:05"), counter))
e.MarkDirty(tl)
if counter <= 0 {
t2.SetActive(false)
e.MarkDirty(t2)
}
}, gwu.ETYPE_STATE_CHANGE)
hiddenPan.Add(t2)
b3 := gwu.NewButton("Restart")
b3.AddEHandlerFunc(func(e gwu.Event) {
counter = 30
t2.SetActive(true)
e.MarkDirty(t2)
}, gwu.ETYPE_CLICK)
p.Add(b3)
event.MarkDirty(hiddenPan)
return p
}