Example #1
0
func (tb ToolButton) Create(builder *Builder) error {
	w, err := walk.NewToolButton(builder.Parent())
	if err != nil {
		return err
	}

	return builder.InitWidget(tb, w, func() error {
		img := tb.Image
		if s, ok := img.(string); ok {
			var err error
			if img, err = walk.NewImageFromFile(s); err != nil {
				return err
			}
		}
		if img != nil {
			if err := w.SetImage(img.(walk.Image)); err != nil {
				return err
			}
		}

		if tb.OnClicked != nil {
			w.Clicked().Attach(tb.OnClicked)
		}

		if tb.AssignTo != nil {
			*tb.AssignTo = w
		}

		return nil
	})
}
Example #2
0
func (tb ToolButton) Create(builder *Builder) error {
	w, err := walk.NewToolButton(builder.Parent())
	if err != nil {
		return err
	}

	return builder.InitWidget(tb, w, func() error {
		if tb.OnClicked != nil {
			w.Clicked().Attach(tb.OnClicked)
		}

		if tb.AssignTo != nil {
			*tb.AssignTo = w
		}

		return nil
	})
}
Example #3
0
func (tb ToolButton) Create(parent walk.Container) error {
	w, err := walk.NewToolButton(parent)
	if err != nil {
		return err
	}

	return InitWidget(tb, w, func() error {
		if err := w.SetText(tb.Text); err != nil {
			return err
		}

		if tb.OnClicked != nil {
			w.Clicked().Attach(tb.OnClicked)
		}

		if tb.AssignTo != nil {
			*tb.AssignTo = w
		}

		return nil
	})
}