Exemplo n.º 1
0
func createWindow(controllerManager *glfwController.ControllerManager) (window *ui.Window, content *ui.Container) {
	// Create window with size
	window = ui.NewWindow()
	window.SetScale(mgl32.Vec2{300, 0}.Vec3(0))

	// create a click and drag tab
	tab := ui.NewContainer()
	tab.SetBackgroundColor(70, 70, 170, 255)
	tab.SetHeight(40)

	// create a content container
	content = ui.NewContainer()
	content.SetBackgroundColor(200, 200, 200, 255)
	content.SetPadding(ui.NewMargin(10))

	// Add all the containers to the window
	mainContainer := ui.NewContainer()
	mainContainer.AddChildren(tab, content)
	window.SetElement(mainContainer)

	// create uiController
	uiController := ui.NewUiController(window)
	controllerManager.AddController(uiController.(glfwController.Controller))
	ui.ClickAndDragWindow(window, tab.Hitbox, uiController)

	return
}
Exemplo n.º 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}
}