示例#1
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
}
示例#2
0
func buildLinkDemo(event gwu.Event) gwu.Comp {
	p := gwu.NewPanel()
	p.SetCellPadding(3)

	p.Add(gwu.NewLink("Visit Gowut Home page", "https://sites.google.com/site/gowebuitoolkit/"))
	p.Add(gwu.NewLink("Visit Gowut Project page", "http://code.google.com/p/gowut/"))

	row := gwu.NewHorizontalPanel()
	row.SetCellPadding(3)
	row.Add(gwu.NewLabel("Discussion forum:"))
	row.Add(gwu.NewLink("https://groups.google.com/d/forum/gowebuitoolkit", "https://groups.google.com/d/forum/gowebuitoolkit"))
	p.Add(row)

	row = gwu.NewHorizontalPanel()
	row.SetCellPadding(3)
	row.Add(gwu.NewLabel("Send e-mail to the Gowut author:"))
	email := "iczaaa" + "@" + "gmail.com"
	row.Add(gwu.NewLink("András Belicza <"+email+">", "mailto:"+email))
	p.Add(row)

	return p
}
示例#3
0
func createFAQ() gwu.Panel {
	panel := gwu.NewPanel()
	panel.Style().SetBackground("rgba(255,255,255,0.75)")

	addHeader := func(text string) {
		label := gwu.NewLabel(text)
		label.Style().SetColor("rgb(0,0,0)")
		label.Style().SetFontWeight("bold")
		label.Style().SetFontSize("large")
		panel.Add(label)
	}

	addText := func(text string) {
		label := gwu.NewLabel(text)
		label.Style().SetColor("rgb(0,0,0)")
		panel.Add(label)
	}

	addHeader("What is this?")
	addText("This site displays the prices for which the ClockworkAgent, a trading bot for the game Scrolls, will buy and sell cards for.")

	addHeader("How do I engage in trading with the bot?")
	addText("Just join the ingame channel 'clockwork' and say '!trade'. You will then be queued up for interaction with the bot in a trade.")

	addHeader("Why are these prices so different from Scrollsguide prices?")
	addText("Scrollsguide prices are determined from WTB and WTS messages in the Trading-channel. Thus they reflect what people expect to " +
		"pay/get for a card, not necessarily what the card is actually traded for. Since most people adjust their expectations to what " +
		"the current Scrollsguide price is, this can lead to a self-fulfilling prophecy. Also, it is pretty easy to manipulate the prices " +
		"for cards that are traded less often, enabling a way to scam the bot if it would use these prices.")

	addHeader("How then are these prices calculated?")
	addText("The price starts at 1500 for rares, 750 for uncommons and 187 for commons. Each time a card is sold to the bot, it will assume " +
		"that the card is less valuable, reducing the price by 100 / 50 / 12.5 depending on rarity. Each time a card is bought from the bot, " +
		"the price will	go up again.")

	addHeader("Why does the buy price fluctuate, when the sell price remains constant?")
	addText("If the bot has less than 2000 gold, the buy prices will be lowered down to a minimum of 50%. This way the bot can aquire more cards, " +
		"balancing out the fact that it had to overpay for most cards in order to determine the price, as well as new additions and general price deflation.")

	addHeader("Who created the bot, and where can I find the source code?")
	addText("Ingame: redefiance")
	addText("Reddit: lando-garner")
	panel.Add(gwu.NewLink("Source", "https://github.com/redefiance/ScrollsTradeBot"))

	return panel
}
示例#4
0
func buildShowcaseWin(sess gwu.Session) {
	win := gwu.NewWindow("show", "Showcase of Features - Gowut")
	win.Style().SetFullSize()
	win.AddEHandlerFunc(func(e gwu.Event) {
		switch e.Type() {
		case gwu.ETYPE_WIN_LOAD:
			fmt.Println("LOADING window:", e.Src().Id())
		case gwu.ETYPE_WIN_UNLOAD:
			fmt.Println("UNLOADING window:", e.Src().Id())
		}
	}, gwu.ETYPE_WIN_LOAD, gwu.ETYPE_WIN_UNLOAD)

	hiddenPan := gwu.NewNaturalPanel()
	sess.SetAttr("hiddenPan", hiddenPan)

	header := gwu.NewHorizontalPanel()
	header.Style().SetFullWidth().SetBorderBottom2(2, gwu.BRD_STYLE_SOLID, "#777777")
	l := gwu.NewLabel("Gowut - Showcase of Features")
	l.Style().SetFontWeight(gwu.FONT_WEIGHT_BOLD).SetFontSize("120%")
	header.Add(l)
	header.AddHConsumer()
	header.Add(gwu.NewLabel("Theme:"))
	themes := gwu.NewListBox([]string{"default", "debug"})
	themes.AddEHandlerFunc(func(e gwu.Event) {
		win.SetTheme(themes.SelectedValue())
		e.ReloadWin("show")
	}, gwu.ETYPE_CHANGE)
	header.Add(themes)
	header.AddHSpace(10)
	reset := gwu.NewLink("Reset", "#")
	reset.SetTarget("")
	reset.AddEHandlerFunc(func(e gwu.Event) {
		e.RemoveSess()
		e.ReloadWin("show")
	}, gwu.ETYPE_CLICK)
	header.Add(reset)
	setNoWrap(header)
	win.Add(header)

	content := gwu.NewHorizontalPanel()
	content.SetCellPadding(1)
	content.SetVAlign(gwu.VA_TOP)
	content.Style().SetFullSize()

	demoWrapper := gwu.NewPanel()
	demoWrapper.Style().SetPaddingLeftPx(5)
	demoWrapper.AddVSpace(10)
	demoTitle := gwu.NewLabel("")
	demoTitle.Style().SetFontWeight(gwu.FONT_WEIGHT_BOLD).SetFontSize("110%")
	demoWrapper.Add(demoTitle)
	demoWrapper.AddVSpace(10)

	links := gwu.NewPanel()
	links.SetCellPadding(1)
	links.Style().SetPaddingRightPx(5)

	demos := make(map[string]pdemo)
	var selDemo pdemo

	selectDemo := func(d pdemo, e gwu.Event) {
		if selDemo != nil {
			selDemo.link.Style().SetBackground("")
			if e != nil {
				e.MarkDirty(selDemo.link)
			}
			demoWrapper.Remove(selDemo.comp)
		}
		selDemo = d
		d.link.Style().SetBackground("#88ff88")
		demoTitle.SetText(d.link.Text())
		if d.comp == nil {
			d.comp = d.buildFunc(e)
		}
		demoWrapper.Add(d.comp)
		if e != nil {
			e.MarkDirty(d.link, demoWrapper)
		}
	}

	createDemo := func(name string, buildFunc func(gwu.Event) gwu.Comp) pdemo {
		link := gwu.NewLabel(name)
		link.Style().SetFullWidth().SetCursor(gwu.CURSOR_POINTER).SetDisplay(gwu.DISPLAY_BLOCK).SetColor(gwu.CLR_BLUE)
		demo := &demo{link: link, buildFunc: buildFunc}
		link.AddEHandlerFunc(func(e gwu.Event) {
			selectDemo(demo, e)
		}, gwu.ETYPE_CLICK)
		links.Add(link)
		demos[name] = demo
		return demo
	}

	links.Style().SetFullHeight().SetBorderRight2(2, gwu.BRD_STYLE_SOLID, "#777777")
	links.AddVSpace(5)
	homeDemo := createDemo("Home", buildHomeDemo)
	selectDemo(homeDemo, nil)
	links.AddVSpace(5)
	l = gwu.NewLabel("Component Palette")
	l.Style().SetFontWeight(gwu.FONT_WEIGHT_BOLD).SetFontSize("110%")
	links.Add(l)
	links.AddVSpace(5)
	l = gwu.NewLabel("Containers")
	l.Style().SetFontWeight(gwu.FONT_WEIGHT_BOLD)
	links.Add(l)
	createDemo("Expander", buildExpanderDemo)
	createDemo("Link (as Container)", buildLinkContainerDemo)
	createDemo("Panel", buildPanelDemo)
	createDemo("Table", buildTableDemo)
	createDemo("TabPanel", buildTabPanelDemo)
	createDemo("Window", buildWindowDemo)
	links.AddVSpace(5)
	l = gwu.NewLabel("Input components")
	l.Style().SetFontWeight(gwu.FONT_WEIGHT_BOLD).SetDisplay(gwu.DISPLAY_BLOCK)
	links.Add(l)
	createDemo("CheckBox", buildCheckBoxDemo)
	createDemo("ListBox", buildListBoxDemo)
	createDemo("TextBox", buildTextBoxDemo)
	createDemo("PasswBox", buildPasswBoxDemo)
	createDemo("RadioButton", buildRadioButtonDemo)
	createDemo("SwitchButton", buildSwitchButtonDemo)
	links.AddVSpace(5)
	l = gwu.NewLabel("Other components")
	l.Style().SetFontWeight(gwu.FONT_WEIGHT_BOLD)
	links.Add(l)
	createDemo("Button", buildButtonDemo)
	createDemo("Html", buildHtmlDemo)
	createDemo("Image", buildImageDemo)
	createDemo("Label", buildLabelDemo)
	createDemo("Link", buildLinkDemo)
	createDemo("Timer", buildTimerDemo)
	links.AddVConsumer()
	setNoWrap(links)
	content.Add(links)
	content.Add(demoWrapper)
	content.CellFmt(demoWrapper).Style().SetFullWidth()

	win.Add(content)
	win.CellFmt(content).Style().SetFullSize()

	footer := gwu.NewHorizontalPanel()
	footer.Style().SetFullWidth().SetBorderTop2(2, gwu.BRD_STYLE_SOLID, "#777777")
	footer.Add(hiddenPan)
	footer.AddHConsumer()
	l = gwu.NewLabel("Copyright © 2013 András Belicza. All rights reserved.")
	l.Style().SetFontStyle(gwu.FONT_STYLE_ITALIC).SetFontSize("95%")
	footer.Add(l)
	footer.AddHSpace(10)
	link := gwu.NewLink("Visit Gowut Home page", "https://sites.google.com/site/gowebuitoolkit/")
	link.Style().SetFontStyle(gwu.FONT_STYLE_ITALIC).SetFontSize("95%")
	footer.Add(link)
	setNoWrap(footer)
	win.Add(footer)

	sess.AddWin(win)
}
示例#5
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)
}