Exemplo n.º 1
0
func buildPanelDemo(event gwu.Event) gwu.Comp {
	p := gwu.NewPanel()

	p.Add(gwu.NewLabel("Panel with horizontal layout:"))
	h := gwu.NewHorizontalPanel()
	for i := 1; i <= 5; i++ {
		h.Add(gwu.NewButton("Button " + strconv.Itoa(i)))
	}
	p.Add(h)

	p.AddVSpace(20)
	p.Add(gwu.NewLabel("Panel with vertical layout:"))
	v := gwu.NewVerticalPanel()
	for i := 1; i <= 5; i++ {
		v.Add(gwu.NewButton("Button " + strconv.Itoa(i)))
	}
	p.Add(v)

	p.AddVSpace(20)
	p.Add(gwu.NewLabel("Panel with natural layout:"))
	n := gwu.NewNaturalPanel()
	for i := 1; i <= 20; i++ {
		n.Add(gwu.NewButton("LONG BUTTON " + strconv.Itoa(i)))
	}
	p.Add(n)

	return p
}
Exemplo n.º 2
0
func buildButtonDemo(event gwu.Event) gwu.Comp {
	p := gwu.NewPanel()

	l := gwu.NewLabel("")

	btnp := gwu.NewHorizontalPanel()
	b := gwu.NewButton("Normal Button")
	b.AddEHandlerFunc(func(e gwu.Event) {
		switch e.Type() {
		case gwu.ETYPE_MOUSE_OVER:
			l.SetText("Mouse is over...")
		case gwu.ETYPE_MOUSE_OUT:
			l.SetText("Mouse is out.")
		case gwu.ETYPE_CLICK:
			x, y := e.Mouse()
			l.SetText(fmt.Sprintf("Clicked at x=%d, y=%d", x, y))
		}
		e.MarkDirty(l)
	}, gwu.ETYPE_CLICK, gwu.ETYPE_MOUSE_OVER, gwu.ETYPE_MOUSE_OUT)
	btnp.Add(b)

	b = gwu.NewButton("Disabled Button")
	b.SetEnabled(false)
	btnp.Add(b)

	p.Add(btnp)

	p.Add(l)

	return p
}
Exemplo n.º 3
0
func buildLabelDemo(event gwu.Event) gwu.Comp {
	p := gwu.NewPanel()

	p.Add(gwu.NewLabel("This is a Label."))
	p.Add(gwu.NewLabel("世界 And another one. ㅈㅈ"))
	p.Add(gwu.NewLabel("Nothing special about them, but they may be the mostly used components."))

	p.AddVSpace(20)
	p.Add(gwu.NewLabel("You can change their text:"))
	b := gwu.NewButton("Change!")
	b.AddEHandlerFunc(func(e gwu.Event) {
		for i := 0; i < p.CompsCount(); i++ {
			if l, ok := p.CompAt(i).(gwu.Label); ok && l != b {
				reversed := []rune(l.Text())
				for i, j := 0, len(reversed)-1; i < j; i, j = i+1, j-1 {
					reversed[i], reversed[j] = reversed[j], reversed[i]
				}
				l.SetText(string(reversed))
			}
		}
		e.MarkDirty(p)
	}, gwu.ETYPE_CLICK)
	p.Add(b)

	return p
}
Exemplo n.º 4
0
func main() {
	// Create GUI server
	//server := gwu.NewServer("guitest", "")
	server := gwu.NewServerTLS("guitest", "", "test_tls/cert.pem", "test_tls/key.pem")
	server.SetText("Test GUI Application")

	server.AddSessCreatorName("login", "Login Window")
	server.AddSHandler(SessHandler{})

	win := gwu.NewWindow("home", "Home Window")
	l := gwu.NewLabel("Home, sweet home of " + server.Text())
	l.Style().SetFontWeight(gwu.FONT_WEIGHT_BOLD).SetFontSize("130%")
	win.Add(l)
	win.Add(gwu.NewLabel("Click on the button to login:"******"Login")
	b.AddEHandlerFunc(func(e gwu.Event) {
		e.ReloadWin("login")
	}, gwu.ETYPE_CLICK)
	win.Add(b)

	server.AddWin(win)

	server.SetLogger(log.New(os.Stdout, "", log.LstdFlags))

	// Start GUI server
	if err := server.Start(); err != nil {
		fmt.Println("Error: Cound not start GUI server:", err)
		return
	}
}
Exemplo n.º 5
0
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
}
Exemplo n.º 6
0
func buildLinkContainerDemo(event gwu.Event) gwu.Comp {
	p := gwu.NewPanel()

	link := gwu.NewLink("An obvious link, to Google Home", "https://google.com/")
	inside := gwu.NewPanel()
	inside.Style().SetBorder2(1, gwu.BRD_STYLE_SOLID, gwu.CLR_GRAY)
	inside.Add(gwu.NewLabel("Everything inside this box also links to Google!"))
	inside.Add(gwu.NewButton("Me too!"))
	link.SetComp(inside)
	p.Add(link)

	return p
}
Exemplo n.º 7
0
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
}
Exemplo n.º 8
0
func buildTabPanelDemo(event gwu.Event) gwu.Comp {
	p := gwu.NewPanel()

	t := gwu.NewTabPanel()
	t.Style().SetSizePx(500, 300)

	table := gwu.NewTable()
	table.SetCellPadding(2)
	table.EnsureSize(3, 2)
	table.Add(gwu.NewLabel("Change tab bar placement:"), 0, 0)
	table.Add(gwu.NewLabel("Tab bar horizontal align:"), 1, 0)
	table.Add(gwu.NewLabel("Tab bar vertical align:"), 2, 0)

	placemslb := gwu.NewListBox([]string{"Top", "Right", "Bottom", "Left"})
	placems := []gwu.TabBarPlacement{gwu.TB_PLACEMENT_TOP, gwu.TB_PLACEMENT_RIGHT, gwu.TB_PLACEMENT_BOTTOM, gwu.TB_PLACEMENT_LEFT}
	halignslb := gwu.NewListBox([]string{"Left", "Center", "Right"})
	haligns := []gwu.HAlign{gwu.HA_LEFT, gwu.HA_CENTER, gwu.HA_RIGHT}
	valignslb := gwu.NewListBox([]string{"Top", "Middle", "Bottom"})
	valigns := []gwu.VAlign{gwu.VA_TOP, gwu.VA_MIDDLE, gwu.VA_BOTTOM}
	placemslb.Style().SetFullWidth()
	halignslb.Style().SetFullWidth()
	valignslb.Style().SetFullWidth()
	table.Add(placemslb, 0, 1)
	table.Add(halignslb, 1, 1)
	table.Add(valignslb, 2, 1)

	placemslb.AddEHandlerFunc(func(e gwu.Event) {
		t.SetTabBarPlacement(placems[placemslb.SelectedIdx()])
		e.MarkDirty(t)
	}, gwu.ETYPE_CHANGE)
	halignslb.AddEHandlerFunc(func(e gwu.Event) {
		t.TabBarFmt().SetHAlign(haligns[halignslb.SelectedIdx()])
		e.MarkDirty(t)
	}, gwu.ETYPE_CHANGE)
	valignslb.AddEHandlerFunc(func(e gwu.Event) {
		t.TabBarFmt().SetVAlign(valigns[valignslb.SelectedIdx()])
		e.MarkDirty(t)
	}, gwu.ETYPE_CHANGE)

	p.Add(table)

	fix := gwu.NewCheckBox("Fixed size")
	fix.SetState(true)
	fix.AddEHandlerFunc(func(e gwu.Event) {
		if fix.State() {
			t.Style().SetSizePx(500, 300)
		} else {
			t.Style().SetSize("", "")
		}
		e.MarkDirty(t)
	}, gwu.ETYPE_CLICK)
	p.Add(fix)

	p.AddVSpace(10)
	l := gwu.NewLabel("Click on tabs...")
	l.Style().SetColor(gwu.CLR_GREEN)
	p.Add(l)
	t.AddEHandlerFunc(func(e gwu.Event) {
		l.SetText("Clicked on tab: " + strconv.Itoa(t.Selected()))
		e.MarkDirty(l)
	}, gwu.ETYPE_STATE_CHANGE)
	p.AddVSpace(10)
	c := gwu.NewPanel()
	c.Add(gwu.NewLabel("This is a TabPanel."))
	c.Add(gwu.NewLabel("Click on other tabs to see their content."))
	c.AddVSpace(15)
	c.Add(gwu.NewLabel("Or click here to see what's in the Hollow:"))
	b := gwu.NewButton("Take me to the Hollow!")
	b.AddEHandlerFunc(func(e gwu.Event) {
		t.SetSelected(3)
		e.MarkDirty(t)
	}, gwu.ETYPE_CLICK)
	c.Add(b)
	t.AddString("Home", c)
	c = gwu.NewPanel()
	c.Add(gwu.NewLabel("You have no new messages."))
	t.AddString("Inbox", c)
	c = gwu.NewPanel()
	c.Add(gwu.NewLabel("You have no sent messages."))
	t.AddString("Sent", c)
	c = gwu.NewPanel()
	c.Add(gwu.NewLabel("There is nothing in the hollow."))
	t.AddString("Hollow", c)
	c = gwu.NewPanel()
	tb := gwu.NewTextBox("Click to edit this comment.")
	tb.SetRows(10)
	tb.SetCols(40)
	c.Add(tb)
	t.AddString("Comment", c)
	p.Add(t)

	return p
}
Exemplo n.º 9
0
func main() {

	os.Mkdir("wikiPages", os.FileMode(os.ModeDir|0777))
	LoadFile("wikiFile.txt")
	fileName = "wikiFile.txt"

	// Create and build a window
	win := gwu.NewWindow("main", "AlfaWiki")
	//win.Style().SetFullWidth()
	win.SetHAlign(gwu.HA_CENTER)
	win.SetCellPadding(2)

	p := gwu.NewHorizontalPanel()
	//p.Style().SetBorder2(1, gwu.BRD_STYLE_SOLID, gwu.CLR_BLACK)
	p.SetCellPadding(2)

	p = gwu.NewHorizontalPanel()
	//p.Style().Set("width","100%")
	//p.Style().SetFullHeight()
	win.Add(p)

	html = gwu.NewHtml(fmt.Sprintf("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM%v", string(blackfriday.MarkdownCommon([]byte(wikiText)))))
	html.Style().Set("width", "40%")
	html.Style().Set("min-width", "40%")
	html.Style().Set("word-break", "break-all")

	tb = gwu.NewTextBox(wikiText)
	tb.SetRows(50)
	tb.SetCols(80)
	//tb.Style().Set("width","100%")
	//tb.Style().Set("min-width","20em")
	tb.AddSyncOnETypes(gwu.ETYPE_KEY_UP)
	p.Add(tb)
	p.Add(html)

	v := gwu.NewPanel()
	//v.Style().SetFullHeight().SetBorderRight2(2, gwu.BRD_STYLE_SOLID, "#777777")
	//v.Style().Set("width","20%")
	p.Add(v)

	tb.AddEHandlerFunc(func(e gwu.Event) {
		wikiText = tb.Text()
		html.SetHtml(fmt.Sprintf("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM%v", string(blackfriday.MarkdownCommon([]byte(tb.Text())))))
		e.MarkDirty(html)
		ioutil.WriteFile(
			fmt.Sprintf("wikiPages/%s", fileName),
			[]byte(wikiText), os.FileMode(os.O_WRONLY|os.O_CREATE|os.O_TRUNC|0777))
	}, gwu.ETYPE_CHANGE, gwu.ETYPE_KEY_UP)

	newPageBox = gwu.NewTextBox("New Page Name")
	newPageBox.SetRows(1)
	newPageBox.SetCols(20)
	v.Add(newPageBox)

	newPageButt := gwu.NewButton("New Page")
	newPageButt.AddEHandler(&NewPageHandler{text: "Not used"}, gwu.ETYPE_CLICK)
	v.Add(newPageButt)
	v.AddVSpace(20)

	files, _ := ioutil.ReadDir("wikiPages")
	for i, f := range files {
		b := gwu.NewButton(f.Name() + " " + strconv.Itoa(i))
		b.AddEHandler(&MyButtonHandler2{text: f.Name()}, gwu.ETYPE_CLICK)
		v.Add(b)
	}

	v.AddVSpace(1000)

	// Create and start a GUI server (omitting error check)
	server := gwu.NewServer("guitest", "localhost:8081")
	server.SetText("AlfaWiki")
	win.SetTheme("debug")
	win.AddHeadHtml(`<link rel="stylesheet" type="text/css" href="/mystyle.css">`)
	server.AddWin(win)

	server.Start("main") // Also opens windows list in browser

	for {

	}

}
Exemplo n.º 10
0
func buildPrivateWins(s gwu.Session) {
	// Create and build a window
	win := gwu.NewWindow("main", "Main Window")
	win.Style().SetFullWidth()
	win.SetCellPadding(2)

	p := gwu.NewPanel()
	p.SetLayout(gwu.LAYOUT_HORIZONTAL)
	p.SetCellPadding(2)
	p.Add(gwu.NewLabel("I'm a label! Try clicking on the button=>"))
	p.Add(gwu.NewLink("Google Home", "https://google.com"))
	img := gwu.NewImage("", "https://www.google.com/images/srpr/logo3w.png")
	img.Style().SetSize("25%", "25%")
	p.Add(img)
	win.Add(p)
	button := gwu.NewButton("Click me")
	button.AddEHandler(&MyButtonHandler{text: ":-)"}, gwu.ETYPE_CLICK)
	win.Add(button)
	extraBtns := gwu.NewPanel()
	extraBtns.SetLayout(gwu.LAYOUT_NATURAL)
	button.AddEHandlerFunc(func(e gwu.Event) {
		extraBtn := gwu.NewButton("Extra #" + strconv.Itoa(extraBtns.CompsCount()))
		extraBtn.AddEHandlerFunc(func(e gwu.Event) {
			extraBtn.Parent().Remove(extraBtn)
			e.MarkDirty(extraBtns)
		}, gwu.ETYPE_CLICK)
		extraBtns.Insert(extraBtn, 0)
		e.MarkDirty(extraBtns)
	}, gwu.ETYPE_CLICK)
	win.Add(extraBtns)

	p = gwu.NewPanel()
	p.SetLayout(gwu.LAYOUT_HORIZONTAL)
	p.SetCellPadding(2)
	p.Style().SetBorder2(1, gwu.BRD_STYLE_SOLID, gwu.CLR_BLACK)
	p.Add(gwu.NewLabel("A drop-down list being"))
	wideListBox := gwu.NewListBox([]string{"50", "100", "150", "200", "250"})
	wideListBox.Style().SetWidth("50")
	wideListBox.AddEHandlerFunc(func(e gwu.Event) {
		wideListBox.Style().SetWidth(wideListBox.SelectedValue() + "px")
		e.MarkDirty(wideListBox)
	}, gwu.ETYPE_CHANGE)
	p.Add(wideListBox)
	p.Add(gwu.NewLabel("pixel wide. And a multi-select list:"))
	listBox := gwu.NewListBox([]string{"First", "Second", "Third", "Forth", "Fifth", "Sixth"})
	listBox.SetMulti(true)
	listBox.SetRows(4)
	p.Add(listBox)
	countLabel := gwu.NewLabel("Selected count: 0")
	listBox.AddEHandlerFunc(func(e gwu.Event) {
		selCount := len(listBox.SelectedIndices())
		countLabel.SetText("Selected count: " + strconv.Itoa(selCount))
		e.MarkDirty(countLabel)
	}, gwu.ETYPE_CHANGE)
	p.Add(countLabel)
	win.Add(p)

	greenCheckBox := gwu.NewCheckBox("I'm a check box. When checked, I'm green!")
	greenCheckBox.AddEHandlerFunc(func(e gwu.Event) {
		if greenCheckBox.State() {
			greenCheckBox.Style().SetBackground(gwu.CLR_GREEN)
		} else {
			greenCheckBox.Style().SetBackground("")
		}
		e.MarkDirty(greenCheckBox)
	}, gwu.ETYPE_CLICK)
	greenCheckBox.AddEHandler(greenHandler, gwu.ETYPE_CLICK)
	win.Add(greenCheckBox)

	table := gwu.NewTable()
	table.SetCellPadding(2)
	table.Style().SetBorder2(1, gwu.BRD_STYLE_SOLID, gwu.CLR_BLACK)
	table.EnsureSize(2, 4)
	table.Add(gwu.NewLabel("TAB-"), 0, 0)
	table.Add(gwu.NewLabel("LE"), 0, 1)
	table.Add(gwu.NewLabel("DE-"), 0, 2)
	table.Add(gwu.NewLabel("MO"), 0, 3)
	table.Add(gwu.NewLabel("Enter your name:"), 1, 0)
	tb := gwu.NewTextBox("")
	tb.AddSyncOnETypes(gwu.ETYPE_KEY_UP)
	table.Add(tb, 1, 1)
	table.Add(gwu.NewLabel("You entered:"), 1, 2)
	nameLabel := gwu.NewLabel("")
	nameLabel.Style().SetColor(gwu.CLR_RED)
	tb.AddEHandlerFunc(func(e gwu.Event) {
		nameLabel.SetText(tb.Text())
		e.MarkDirty(nameLabel)
	}, gwu.ETYPE_CHANGE, gwu.ETYPE_KEY_UP)
	table.Add(nameLabel, 1, 3)
	win.Add(table)

	table = gwu.NewTable()
	table.Style().SetBorder2(1, gwu.BRD_STYLE_SOLID, gwu.CLR_BLACK)
	table.SetAlign(gwu.HA_RIGHT, gwu.VA_TOP)
	table.EnsureSize(5, 5)
	for row := 0; row < 5; row++ {
		group := gwu.NewRadioGroup(strconv.Itoa(row))
		for col := 0; col < 5; col++ {
			radio := gwu.NewRadioButton("= "+strconv.Itoa(col)+" =", group)
			radio.AddEHandlerFunc(func(e gwu.Event) {
				radios := []gwu.RadioButton{radio, radio.Group().PrevSelected()}
				for _, radio := range radios {
					if radio != nil {
						if radio.State() {
							radio.Style().SetBackground(gwu.CLR_GREEN)
						} else {
							radio.Style().SetBackground("")
						}
						e.MarkDirty(radio)
					}
				}
			}, gwu.ETYPE_CLICK)
			table.Add(radio, row, col)
		}
	}
	table.SetColSpan(2, 1, 2)
	table.SetRowSpan(3, 1, 2)
	table.CellFmt(2, 2).Style().SetSizePx(150, 80)
	table.CellFmt(2, 2).SetAlign(gwu.HA_RIGHT, gwu.VA_BOTTOM)
	table.RowFmt(2).Style().SetBackground("#808080")
	table.RowFmt(2).SetAlign(gwu.HA_DEFAULT, gwu.VA_MIDDLE)
	table.RowFmt(3).Style().SetBackground("#d0d0d0")
	table.RowFmt(4).Style().SetBackground("#b0b0b0")
	win.Add(table)

	tabPanel := gwu.NewTabPanel()
	tabPanel.SetTabBarPlacement(gwu.TB_PLACEMENT_TOP)
	for i := 0; i < 6; i++ {
		if i == 3 {
			img := gwu.NewImage("", "https://www.google.com/images/srpr/logo3w.png")
			img.Style().SetWidthPx(100)
			tabPanel.Add(img, gwu.NewLabel("This is some long content, random="+strconv.Itoa(rand.Int())))
			continue
		}
		tabPanel.AddString(strconv.Itoa(i)+". tab", gwu.NewLabel("This is some long content, random="+strconv.Itoa(rand.Int())))
	}
	win.Add(tabPanel)
	tabPanel = gwu.NewTabPanel()
	tabPanel.SetTabBarPlacement(gwu.TB_PLACEMENT_LEFT)
	tabPanel.TabBarFmt().SetVAlign(gwu.VA_BOTTOM)
	for i := 7; i < 11; i++ {
		l := gwu.NewLabel("This is some long content, random=" + strconv.Itoa(rand.Int()))
		if i == 9 {
			img := gwu.NewImage("", "https://www.google.com/images/srpr/logo3w.png")
			img.Style().SetWidthPx(100)
			tabPanel.Add(img, l)
			tabPanel.CellFmt(l).Style().SetSizePx(400, 400)
			continue
		}
		tabPanel.AddString(strconv.Itoa(i)+". tab", l)
		tabPanel.CellFmt(l).Style().SetSizePx(400, 400)
	}
	win.Add(tabPanel)
	s.AddWin(win)

	win2 := gwu.NewWindow("main2", "Main2 Window")
	win2.Add(gwu.NewLabel("This is just a test 2nd window."))
	back := gwu.NewButton("Back")
	back.AddEHandlerFunc(func(e gwu.Event) {
		e.ReloadWin(win.Name())
	}, gwu.ETYPE_CLICK)
	win2.Add(back)
	s.AddWin(win2)
}
Exemplo n.º 11
0
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)
}
Exemplo n.º 12
0
func main() {
	// Create and build a window
	win := gwu.NewWindow("main", "Test GUI Window")
	win.Style().SetFullWidth()
	win.SetHAlign(gwu.HA_CENTER)
	win.SetCellPadding(2)

	// Button which changes window content
	win.Add(gwu.NewLabel("I'm a label! Try clicking on the button=>"))
	btn := gwu.NewButton("Click me")
	btn.AddEHandler(&MyButtonHandler{text: ":-)"}, gwu.ETYPE_CLICK)
	win.Add(btn)
	btnsPanel := gwu.NewNaturalPanel()
	btn.AddEHandlerFunc(func(e gwu.Event) {
		// Create and add a new button...
		newbtn := gwu.NewButton("Extra #" + strconv.Itoa(btnsPanel.CompsCount()))
		newbtn.AddEHandlerFunc(func(e gwu.Event) {
			btnsPanel.Remove(newbtn) // ...which removes itself when clicked
			e.MarkDirty(btnsPanel)
		}, gwu.ETYPE_CLICK)
		btnsPanel.Insert(newbtn, 0)
		e.MarkDirty(btnsPanel)
	}, gwu.ETYPE_CLICK)
	win.Add(btnsPanel)

	// ListBox examples
	p := gwu.NewHorizontalPanel()
	p.Style().SetBorder2(1, gwu.BRD_STYLE_SOLID, gwu.CLR_BLACK)
	p.SetCellPadding(2)
	p.Add(gwu.NewLabel("A drop-down list being"))
	widelb := gwu.NewListBox([]string{"50", "100", "150", "200", "250"})
	widelb.Style().SetWidth("50")
	widelb.AddEHandlerFunc(func(e gwu.Event) {
		widelb.Style().SetWidth(widelb.SelectedValue() + "px")
		e.MarkDirty(widelb)
	}, gwu.ETYPE_CHANGE)
	p.Add(widelb)
	p.Add(gwu.NewLabel("pixel wide. And a multi-select list:"))
	listBox := gwu.NewListBox([]string{"First", "Second", "Third", "Forth", "Fifth", "Sixth"})
	listBox.SetMulti(true)
	listBox.SetRows(4)
	p.Add(listBox)
	countLabel := gwu.NewLabel("Selected count: 0")
	listBox.AddEHandlerFunc(func(e gwu.Event) {
		countLabel.SetText("Selected count: " + strconv.Itoa(len(listBox.SelectedIndices())))
		e.MarkDirty(countLabel)
	}, gwu.ETYPE_CHANGE)
	p.Add(countLabel)
	win.Add(p)

	// Self-color changer check box
	greencb := gwu.NewCheckBox("I'm a check box. When checked, I'm green!")
	greencb.AddEHandlerFunc(func(e gwu.Event) {
		if greencb.State() {
			greencb.Style().SetBackground(gwu.CLR_GREEN)
		} else {
			greencb.Style().SetBackground("")
		}
		e.MarkDirty(greencb)
	}, gwu.ETYPE_CLICK)
	win.Add(greencb)

	// TextBox with echo
	p = gwu.NewHorizontalPanel()
	p.Add(gwu.NewLabel("Enter your name:"))
	tb := gwu.NewTextBox("")
	tb.AddSyncOnETypes(gwu.ETYPE_KEY_UP)
	p.Add(tb)
	p.Add(gwu.NewLabel("You entered:"))
	nameLabel := gwu.NewLabel("")
	nameLabel.Style().SetColor(gwu.CLR_RED)
	tb.AddEHandlerFunc(func(e gwu.Event) {
		nameLabel.SetText(tb.Text())
		e.MarkDirty(nameLabel)
	}, gwu.ETYPE_CHANGE, gwu.ETYPE_KEY_UP)
	p.Add(nameLabel)
	win.Add(p)

	// Create and start a GUI server (omitting error check)
	server := gwu.NewServer("guitest", "localhost:8081")
	server.SetText("Test GUI App")
	server.AddWin(win)
	server.Start("") // Also opens windows list in browser
}