func buildPasswBoxDemo(event gwu.Event) gwu.Comp { p := gwu.NewPanel() p.Add(gwu.NewLabel("Enter your password:"******"")) return p }
func buildTableDemo(event gwu.Event) gwu.Comp { p := gwu.NewPanel() l := gwu.NewLabel("Tip: Switch to the 'debug' theme (top right) to see cell borders.") l.Style().SetColor(gwu.CLR_RED).SetFontStyle(gwu.FONT_STYLE_ITALIC) p.Add(l) p.AddVSpace(20) p.Add(gwu.NewLabel("A simple form aligned with a table:")) p.AddVSpace(10) t := gwu.NewTable() t.SetCellPadding(2) t.EnsureSize(2, 2) var c gwu.Comp t.Add(gwu.NewLabel("User name:"), 0, 0) c = gwu.NewTextBox("") c.Style().SetWidthPx(160) t.Add(c, 0, 1) t.Add(gwu.NewLabel("Password:"******"") c.Style().SetWidthPx(160) t.Add(c, 1, 1) t.Add(gwu.NewLabel("Go to:"), 2, 0) c = gwu.NewListBox([]string{"Inbox", "User preferences", "Last visited page"}) c.Style().SetWidthPx(160) t.Add(c, 2, 1) p.Add(t) p.AddVSpace(30) p.Add(gwu.NewLabel("Advanced table structure with modified alignment, row and col spans:")) p.AddVSpace(10) t = gwu.NewTable() t.Style().SetBorder2(1, gwu.BRD_STYLE_SOLID, gwu.CLR_GREY) t.SetAlign(gwu.HA_RIGHT, gwu.VA_TOP) t.EnsureSize(5, 5) for row := 0; row < 5; row++ { for col := 0; col < 5; col++ { t.Add(gwu.NewButton("Button "+strconv.Itoa(row)+strconv.Itoa(col)), row, col) } } t.SetColSpan(2, 1, 2) t.SetRowSpan(3, 1, 2) t.CellFmt(2, 2).Style().SetSizePx(150, 80) t.CellFmt(2, 2).SetAlign(gwu.HA_RIGHT, gwu.VA_BOTTOM) t.RowFmt(2).SetAlign(gwu.HA_DEFAULT, gwu.VA_MIDDLE) t.CompAt(2, 1).Style().SetFullSize() t.CompAt(4, 2).Style().SetFullWidth() t.RowFmt(0).Style().SetBackground(gwu.CLR_RED) t.RowFmt(1).Style().SetBackground(gwu.CLR_GREEN) t.RowFmt(2).Style().SetBackground(gwu.CLR_BLUE) t.RowFmt(3).Style().SetBackground(gwu.CLR_GREY) t.RowFmt(4).Style().SetBackground(gwu.CLR_TEAL) p.Add(t) return p }
func buildLoginWin(s gwu.Session) { win := gwu.NewWindow("login", "Login Window") win.Style().SetFullSize() win.SetAlign(gwu.HA_CENTER, gwu.VA_MIDDLE) p := gwu.NewPanel() p.SetHAlign(gwu.HA_CENTER) p.SetCellPadding(2) l := gwu.NewLabel("Test GUI Login Window") l.Style().SetFontWeight(gwu.FONT_WEIGHT_BOLD).SetFontSize("150%") p.Add(l) l = gwu.NewLabel("Login") l.Style().SetFontWeight(gwu.FONT_WEIGHT_BOLD).SetFontSize("130%") p.Add(l) p.CellFmt(l).Style().SetBorder2(1, gwu.BRD_STYLE_DASHED, gwu.CLR_NAVY) l = gwu.NewLabel("user/pass: admin/a") l.Style().SetFontSize("80%").SetFontStyle(gwu.FONT_STYLE_ITALIC) p.Add(l) errL := gwu.NewLabel("") errL.Style().SetColor(gwu.CLR_RED) p.Add(errL) table := gwu.NewTable() table.SetCellPadding(2) table.EnsureSize(2, 2) table.Add(gwu.NewLabel("User name:"), 0, 0) tb := gwu.NewTextBox("") tb.Style().SetWidthPx(160) table.Add(tb, 0, 1) table.Add(gwu.NewLabel("Password:"******"") pb.Style().SetWidthPx(160) table.Add(pb, 1, 1) p.Add(table) b := gwu.NewButton("OK") b.AddEHandlerFunc(func(e gwu.Event) { if tb.Text() == "admin" && pb.Text() == "a" { e.Session().RemoveWin(win) // Login win is removed, password will not be retrievable from the browser buildPrivateWins(e.Session()) e.ReloadWin("main") } else { e.SetFocusedComp(tb) errL.SetText("Invalid user name or password!") e.MarkDirty(errL) } }, gwu.ETYPE_CLICK) p.Add(b) l = gwu.NewLabel("") p.Add(l) p.CellFmt(l).Style().SetHeightPx(200) win.Add(p) win.SetFocusedCompId(tb.Id()) p = gwu.NewPanel() p.SetLayout(gwu.LAYOUT_HORIZONTAL) p.SetCellPadding(2) p.Add(gwu.NewLabel("Here's an ON/OFF switch which enables/disables the other one:")) sw := gwu.NewSwitchButton() sw.SetOnOff("ENB", "DISB") sw.SetState(true) p.Add(sw) p.Add(gwu.NewLabel("And the other one:")) sw2 := gwu.NewSwitchButton() sw2.SetEnabled(true) sw2.Style().SetWidthPx(100) p.Add(sw2) sw.AddEHandlerFunc(func(e gwu.Event) { sw2.SetEnabled(sw.State()) e.MarkDirty(sw2) }, gwu.ETYPE_CLICK) win.Add(p) s.AddWin(win) }