Example #1
0
func (engine *EngineImpl) InitFpsDial() {
	window := ui.NewWindow()
	window.SetTranslation(mgl32.Vec3{10, 10, 1})
	window.SetScale(mgl32.Vec3{400, 0, 1})
	window.SetBackgroundColor(0, 0, 0, 0)

	container := ui.NewContainer()
	container.SetBackgroundColor(0, 0, 0, 0)
	window.SetElement(container)

	text := ui.NewTextElement("0", color.RGBA{255, 0, 0, 255}, 18, nil)
	container.AddChildren(text)
	engine.AddUpdatable(UpdatableFunc(func(dt float64) {
		fps := engine.FPS()
		text.SetText(fmt.Sprintf("%v", int(fps)))
		switch {
		case fps < 20:
			text.SetTextColor(color.RGBA{255, 0, 0, 255})
		case fps < 30:
			text.SetTextColor(color.RGBA{255, 90, 0, 255})
		case fps < 50:
			text.SetTextColor(color.RGBA{255, 255, 0, 255})
		default:
			text.SetTextColor(color.RGBA{0, 255, 0, 255})
		}
		text.ReRender()
	}))

	window.Render()
	engine.AddOrtho(window)
}
Example #2
0
func populateContent(content *ui.Container) []ui.Activatable {
	// example text title
	textElement := ui.NewTextElement("UI EXAMPLE!", color.Black, 16, nil)

	// example image element
	img, _ := assets.ImportImageCached("resources/cubemap.png")
	imageElement := ui.NewImageElement(img)
	imageElement.SetWidth(200)

	// example text field
	tf := ui.NewTextField("", color.Black, 16, nil)
	tf.SetPlaceholder("this is a placeholder")
	tf.SetBackgroundColor(255, 255, 255, 255)
	tf.SetMargin(ui.Margin{10, 0, 10, 0})

	// example hidden text field
	passwordTf := ui.NewTextField("", color.Black, 16, nil)
	passwordTf.SetHidden(true)
	passwordTf.SetBackgroundColor(255, 255, 255, 255)
	passwordTf.SetMargin(ui.Margin{0, 0, 10, 0})

	// example button
	button := ui.NewContainer()
	button.SetBackgroundColor(160, 0, 0, 254)
	button.SetPadding(ui.NewMargin(20))

	// button on click event
	button.Hitbox.AddOnClick(func(button int, release bool, position mgl32.Vec2) {
		if release {
			textElement.SetText("release").SetTextColor(color.NRGBA{254, 0, 0, 254}).ReRender()
		} else {
			textElement.SetText("click").SetTextColor(color.NRGBA{0, 254, 0, 254}).ReRender()
		}
	})

	// button on hover event
	button.Hitbox.AddOnHover(func() {
		button.SetBackgroundColor(210, 100, 100, 254)
	})
	button.Hitbox.AddOnUnHover(func() {
		button.SetBackgroundColor(160, 0, 0, 254)
	})

	// add everything to the content container
	content.AddChildren(textElement, imageElement, tf, passwordTf, button)

	// return everything that should be included in the Tabs order
	return []ui.Activatable{tf, passwordTf}
}