Example #1
0
func buildImageDemo(event gwu.Event) gwu.Comp {
	p := gwu.NewPanel()

	p.Add(gwu.NewLabel("Google's logo:"))
	img := gwu.NewImage("Google's logo", "https://www.google.com/images/srpr/logo3w.png")
	img.Style().SetSizePx(275, 95)
	p.Add(img)

	p.AddVSpace(20)
	p.Add(gwu.NewLabel("Go's Gopher:"))
	img = gwu.NewImage("Go's Gopher", "http://golang.org/doc/gopher/frontpage.png")
	img.Style().SetSizePx(250, 340)
	state := false
	img.AddEHandlerFunc(func(e gwu.Event) {

		switch e.Type() {
		case gwu.ETYPE_CLICK:
			switch state {
			case false:
				img.SetUrl("https://www.google.com/images/srpr/logo3w.png")
				img.Style().SetSizePx(275, 95)
				state = true
			case true:
				img.SetUrl("http://golang.org/doc/gopher/frontpage.png")
				img.Style().SetSizePx(250, 340)
				state = false
			}
		}
		e.MarkDirty(img)
	}, gwu.ETYPE_CLICK)
	p.Add(img)

	return p
}
Example #2
0
func buildImageDemo(event gwu.Event) gwu.Comp {
	p := gwu.NewPanel()

	p.Add(gwu.NewLabel("Google's logo:"))
	img := gwu.NewImage("Google's logo", "https://www.google.com/images/srpr/logo3w.png")
	img.Style().SetSizePx(275, 95)
	p.Add(img)

	p.AddVSpace(20)
	p.Add(gwu.NewLabel("Go's Gopher:"))
	img = gwu.NewImage("Go's Gopher", "http://golang.org/doc/gopher/frontpage.png")
	img.Style().SetSizePx(250, 340)
	p.Add(img)

	return p
}
Example #3
0
func updateTables(tables gwu.Panel) {
	var sorted SortBySellPrice
	for card, _ := range PriceHistory {
		sorted = append(sorted, StockedItem{
			card,
			currentState.DeterminePrice(card, 1, true),
			currentState.DeterminePrice(card, 1, false),
		})
	}
	sort.Sort(sorted)

	tables.Clear()
	tables.Add(createFAQ())

	tables.AddHSpace(100)
	for rarity, rarityStr := range []string{"Commons", "Uncommons", "Rares"} {
		layout := gwu.NewPanel()
		tables.Add(layout)
		tables.AddHSpace(30)

		layout.SetHAlign(gwu.HA_CENTER)
		layout.Style().SetBackground("rgba(0,0,0,0.5)")
		layout.Style().SetWidthPx(320)

		header := gwu.NewLabel(rarityStr)
		header.Style().SetColor("rgb(255,255,255)")
		header.Style().SetFontWeight("bold")
		header.Style().SetFontSize("x-large")
		layout.Add(header)

		table := gwu.NewTable()
		layout.Add(table)

		table.SetCellPadding(5)

		row := 0
		for _, sortedItem := range sorted {
			if CardRarities[sortedItem.card] != rarity {
				continue
			}

			table.Add(gwu.NewImage("", fmt.Sprintf("images/%s.png", CardResources[sortedItem.card])), row, 0)
			table.Add(gwu.NewLabel(string(sortedItem.card)), row, 1)
			table.Add(gwu.NewLabel(fmt.Sprintf("%d", sortedItem.buy)), row, 2)
			table.Add(gwu.NewLabel(fmt.Sprintf("%d", sortedItem.sell)), row, 3)
			if row%2 == 0 {
				table.RowFmt(row).Style().SetBackground("rgba(255,255,255,0.75)")
			} else {
				table.RowFmt(row).Style().SetBackground("rgba(150,150,150,0.75)")
			}
			row++
		}
	}
}
Example #4
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)
}