gonutz / wui

Windows GUI library for Go (Golang). Comes with a graphical UI designer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provide some example of code

bogus43 opened this issue · comments

Hi, could you provide some example of code of UI elements and events (onClick and other)? I will be grateful.

Yes, I have actually just thought about that the other day. Due to a shortage of hours in the day this might take me some time, though. But rest assured that I plan to make this thing usable :-)

Ok I am looking forward to it :).

Any update?

Nope, no spare time as of yet. But keep an eye on this issue and thank you for your interest.

Hi, any good news?

No, only work for me right now.

I too would be grateful for what @bogus43 has asked for. But here is a sample of what I've managed so far:

package main

import (
	"fmt"

	"github.com/gonutz/wui/v2"
)

func main() {
	windowFont, _ := wui.NewFont(wui.FontDesc{
		Name:   "Tahoma",
		Height: -11,
	})

	window := wui.NewWindow()
	window.SetFont(windowFont)
	window.SetTitle("Window")

	button1 := wui.NewButton()
	button1.SetBounds(10, 8, 85, 25)
	button1.SetText("Press Me")
	button1.SetOnClick(func() {
		Clicked()

	})
	window.Add(button1)

	textEdit1 := wui.NewTextEdit()
	textEdit1.SetBounds(14, 39, 575, 342)
	// textEdit1.SetText("Text Edit")
	window.Add(textEdit1)

	window.Show()
}

func Clicked() {
	fmt.Println("Hello World")
}

Hey cool, thanks for contributing. I am really sorry for not having much time right now. I will try to win the lottery to have more time for working on my open source projects, including this.

Again, I will look into this once I have time but I cannot tell you when that will be. :-)

No worries, work comes first of course (for me too). I like that idea of winning the lottery, I'll take your advice. 👍
A marginally more useful example (barely) that resets button text when pressed:

package main

import (
	"github.com/gonutz/wui/v2"
)

func main() {
	windowFont, _ := wui.NewFont(wui.FontDesc{
		Name:   "Tahoma",
		Height: -11,
	})

	window := wui.NewWindow()
	window.SetFont(windowFont)
	window.SetTitle("Window")

	button1 := wui.NewButton()
	button1.SetBounds(10, 8, 85, 25)
	button1.SetText("Press Me")
	button1.SetOnClick(func() {
		Clicked(button1)
	})
	window.Add(button1)

	textEdit1 := wui.NewTextEdit()
	textEdit1.SetBounds(14, 39, 575, 342)
	// textEdit1.SetText("Text Edit")
	window.Add(textEdit1)

	window.Show()
}

func Clicked(button *wui.Button) {
	button.SetText("Pressed")
}

I compiled the designer and used it to create the skeleton of the form. Very useful, thank you!

Nice, cool to hear! The designer is also still a work in progress but I have created some useful things with it myself already. Cool to see other people use it! :-)

@gonutz I hope you will win on the lottery and can focus only on this very usefull tools :).