Exemplo n.º 1
0
func NewFooModel() *FooModel {
	m := new(FooModel)
	m.evenBitmap, _ = walk.NewBitmapFromFile("../img/open.png")
	m.oddIcon, _ = walk.NewIconFromFile("../img/x.ico")
	m.ResetRows()
	return m
}
Exemplo n.º 2
0
func createBitmap() (*walk.Bitmap, error) {
	bounds := walk.Rectangle{Width: 200, Height: 200}

	bmp, err := walk.NewBitmap(bounds.Size())
	if err != nil {
		return nil, err
	}

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

	canvas, err := walk.NewCanvasFromImage(bmp)
	if err != nil {
		return nil, err
	}
	defer canvas.Dispose()

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

	brush, err := walk.NewBitmapBrush(brushBmp)
	if err != nil {
		return nil, err
	}
	defer brush.Dispose()

	if err := canvas.FillRectangle(brush, bounds); err != nil {
		return nil, err
	}

	font, err := walk.NewFont("Times New Roman", 40, walk.FontBold|walk.FontItalic)
	if err != nil {
		return nil, err
	}
	defer font.Dispose()

	if err := canvas.DrawText("Walk Drawing Example", font, walk.RGB(0, 0, 0), bounds, walk.TextWordbreak); err != nil {
		return nil, err
	}

	succeeded = true

	return bmp, nil
}
Exemplo n.º 3
0
func setActionImage(action *walk.Action, image interface{}) (err error) {
	var img *walk.Bitmap

	switch image := image.(type) {
	case nil:
		return nil

	case *walk.Bitmap:
		img = image

	case string:
		if img, err = walk.NewBitmapFromFile(image); err != nil {
			return
		}

	default:
		return errors.New("invalid type for Image")
	}

	return action.SetImage(img)
}