Exemplo n.º 1
0
func main() {
	desktop.Main(func(display driver.Display) {
		var cursors [18]driver.Cursor

		cursors[0], _ = display.NewCursor(driver.CursorArrow)
		cursors[1], _ = display.NewCursor(driver.CursorCrossHair)
		cursors[2], _ = display.NewCursor(driver.CursorHandClosed)
		cursors[3], _ = display.NewCursor(driver.CursorHandOpened)
		cursors[4], _ = display.NewCursor(driver.CursorHandTouch)
		cursors[5], _ = display.NewCursor(driver.CursorResizeLeft)
		cursors[6], _ = display.NewCursor(driver.CursorResizeRight)
		cursors[7], _ = display.NewCursor(driver.CursorResizeLeftRight)
		cursors[8], _ = display.NewCursor(driver.CursorResizeUp)
		cursors[9], _ = display.NewCursor(driver.CursorResizeDown)
		cursors[10], _ = display.NewCursor(driver.CursorResizeUpDown)
		cursors[11], _ = display.NewCursor(driver.CursorDelete)
		cursors[12], _ = display.NewCursor(driver.CursorForbid)
		cursors[13], _ = display.NewCursor(driver.CursorLink)
		cursors[14], _ = display.NewCursor(driver.CursorCopy)
		cursors[15], _ = display.NewCursor(driver.CursorMenu)
		cursors[16], _ = display.NewCursor(driver.CursorIBeam)
		cursors[17], _ = display.NewCursor(driver.CursorIBeamVertical)

		window, _ := display.NewWindow(&driver.WindowConfig{
			Size:      geom.Size{W: 200, H: 200},
			Titled:    true,
			Resizable: true,
			Closeable: true,
		})

		image := vu.NewImage(nil, cursors[0].Image())
		view := vu.NewView(image)

		i := 0

		for {
			var e interface{}

			select {
			case e = <-window.Events():
			case e = <-view.Events():
			}

			if _, ok := e.(event.MouseDown); ok {
				i = (i + 1) % len(cursors)
				image.SetImage(cursors[i].Image())
				window.Send(event.ChangeCursor{cursors[i]})
			}

			if view.Process(window, e) != nil {
				break
			}
		}
	})
}
Exemplo n.º 2
0
func main() {
	desktop.Main(func(display driver.Display) {
		window, _ := display.NewWindow(nil)

		for v := range window.Events() {
			fmt.Println(v)

			switch e := v.(type) {
			case event.Redraw:
				e.GC.Publish()
			}
		}
	})
}
Exemplo n.º 3
0
func main() {
	desktop.Main(func(display driver.Display) {
		view := vu.NewView(
			vu.NewAlignBox(1, 0,
				vu.NewImage(nil, image.NewUniform(color.RGBA{255, 0, 0, 255})),
			),
		)

		window, _ := display.NewWindow(nil)

		for event := range window.Events() {
			view.Process(window, event)
		}
	})
}
Exemplo n.º 4
0
func main() {
	desktop.Main(func(display driver.Display) {
		gopher := loadImage("samples/gopher.png")

		img0 := vu.NewImage(vu.UniformImageLayout{}, gopher)
		img0.SetSelectable(true)

		img1 := vu.NewImage(vu.FillImageLayout{}, gopher)
		img1.SetSelectable(true)

		img2 := vu.NewImage(vu.UniformFillImageLayout{}, gopher)
		img2.SetSelectable(true)

		view := vu.NewView(
			vu.NewFrame(vu.VerticalLayout{Spacing: 10},
				img0, img1, img2,
			),
		)

		window, _ := display.NewWindow(driver.MainWindowConfig(
			driver.DefaultWindowTitle(),
			view.PreferredSize(geom.Size{-1, -1}),
		))

		for {
			var event interface{}

			select {
			case event = <-window.Events():
			case event = <-view.Events():
			}

			if view.Process(window, event) != nil {
				break
			}
		}
	})
}
Exemplo n.º 5
0
func main() {
	desktop.Main(func(display driver.Display) {
		f0 := text.BasicFont()
		defer f0.Close()

		f1 := text.TTF(clearSans, text.FaceData{Size: 12})
		defer f1.Close()

		f2 := text.TTF(clearSansBoldItalic, text.FaceData{Size: 12})
		defer f2.Close()

		monaco, _ := display.NewFont("Monaco")
		f3 := monaco.Face(text.FaceData{})
		defer f3.Close()

		t1 := vu.NewText("Hello World!\nHow are you doing?", f0, nil)
		t1.SetWrappable(true)
		t1.SetSelectable(true)

		t2 := vu.NewText("How are you doing?", f1, text.Left)
		t2.SetWrappable(true)
		t2.SetSelectable(true)

		t3 := vu.NewText("How are you doing?", f3, text.Center)
		t3.SetWrappable(true)
		t3.SetSelectable(true)
		t3.SetForeground(image.NewUniform(color.RGBA{255, 0, 0, 255}))
		t3.SetBackground(image.NewUniform(color.RGBA{255, 255, 0, 255}))

		t4 := vu.NewText("How are you doing?", f1, text.Right)
		t4.SetWrappable(true)
		t4.SetSelectable(true)
		t4.SetDirection(text.RightToLeft)

		t5 := vu.NewText("How are you doing?", f1, text.Justify)
		t5.SetWrappable(true)
		t5.SetSelectable(true)

		t6 := vu.NewText("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890", f2, nil)
		t6.SetWrappable(true)
		t6.SetSelectable(true)
		t6.SetSelection(text.Range{10, 10})

		view := vu.NewView(
			vu.NewMarginBox(geom.MakeMargin(10),
				vu.NewFrame(nil, t1, t2, t3, t4, t5, t6),
			),
		)

		window, _ := display.NewWindow(driver.MainWindowConfig(
			driver.DefaultWindowTitle(),
			view.PreferredSize(geom.Size{-1, -1}),
		))

		for {
			var event interface{}

			select {
			case event = <-window.Events():
			case event = <-view.Events():
			}

			if view.Process(window, event) != nil {
				break
			}
		}
	})
}