Example #1
1
func createBitmap() *walk.Bitmap {
	bounds := walk.Rectangle{Width: 200, Height: 200}

	bmp, _ := walk.NewBitmap(bounds.Size())

	succeeded := false
	defer func() {
		if !succeeded {
			bmp.Dispose()
		}
	}()

	canvas, _ := walk.NewCanvasFromImage(bmp)
	defer canvas.Dispose()

	brushBmp, _ := walk.NewBitmapFromFile("../img/plus.png")
	defer brushBmp.Dispose()

	brush, _ := walk.NewBitmapBrush(brushBmp)
	defer brush.Dispose()

	canvas.FillRectangle(brush, bounds)

	font, _ := walk.NewFont("Times New Roman", 40, walk.FontBold|walk.FontItalic)
	defer font.Dispose()

	canvas.DrawText("Walk Drawing Example", font, walk.RGB(0, 0, 0), bounds, walk.TextWordbreak)

	succeeded = true
	return bmp
}
Example #2
0
func main() {
	var mw *walk.MainWindow
	var c1 *walk.Composite
	var c2 *walk.Composite

	bmp, err := walk.NewBitmapFromFile("../../img/plus.png")
	if err != nil {
		panic(err)
	}
	defer bmp.Dispose()

	MainWindow{
		AssignTo: &mw,
		Title:    "Background Example",
		Layout:   VBox{MarginsZero: true},
		MinSize:  Size{300, 400},
		Children: []Widget{
			Composite{
				AssignTo: &c1,
				Layout:   VBox{},
				Children: []Widget{
					TextEdit{},
				},
			},
			Composite{
				AssignTo: &c2,
				Layout:   VBox{},
				Children: []Widget{
					TextEdit{},
				},
			},
			ImageView{
				Image: bmp,
			},
		},
	}.Create()

	scb, err := walk.NewSolidColorBrush(walk.RGB(255, 0, 0))
	if err != nil {
		panic(err)
	}
	defer scb.Dispose()

	c1.SetBackground(scb)

	bmb, err := walk.NewBitmapBrush(bmp)
	if err != nil {
		panic(err)
	}
	defer bmb.Dispose()

	c2.SetBackground(bmb)

	mw.Show()
	mw.Run()
}