widgeten

package module
v0.0.0-...-03ac94d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

Widgeten

This Go package provides a set of reusable UI elements (widgets) for creating user interfaces with the Ebitengine.

Features

  • Buttons: Create clickable buttons with text, images, or both.

Usage

See the examples folder for how to setup and use different widgets.

Contributing

Contributions to this project! Please open issues for any feature requests or bugs.

License

This package is licensed under the Apache License 2.0. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Button

type Button struct {
	// text is the text displayed on the button.
	Text string

	// fontSize sets the size of the text displayed on the button.
	FontSize int

	// rect defines the rectangular area occupied by the button on the screen.
	Rect image.Rectangle

	// image (optional) is an ebiten image to be drawn on the button.
	// If set, takes precedence over Text for rendering.
	Image *ebiten.Image

	// alpha is the opacity of the button (0.0 to 1.0).
	Alpha float32
	// contains filtered or unexported fields
}

button represents a clickable button element for your user interface. It can display text, an image, or both, and supports callbacks for pressed, hover, and leave events.

func (*Button) Draw

func (b *Button) Draw(dst *ebiten.Image)

Draw renders the button onto the provided destination image (`dst`). It handles scaling the button image (if set) to fit the button's rectangle, applying the specified alpha, and positioning it correctly. If Text and GoTextFaceSource are set, the method also draws the text centered within the button rectangle with the specified font size and color.

func (*Button) Update

func (b *Button) Update()

Update handles user interaction with the button. It checks for mouse hover and leave events based on the current cursor position. If the button is hovered over and the OnMouseHover callback is set, it calls the callback function. Similarly, if the mouse leaves the button and the OnMouseLeave callback is set, it calls the callback function. Additionally, it detects mouse button presses and releases. If the button is pressed within its area, it sets the internal mouseDown flag and calls the OnPressed callback function (if set). Finally, it resets the mouseDown flag on button release.

type ButtonBuilder

type ButtonBuilder interface {
	SetText(string) ButtonBuilder
	SetFontSize(int) ButtonBuilder
	SetRect(image.Rectangle) ButtonBuilder
	SetImage(*ebiten.Image) ButtonBuilder
	SetAlpha(float32) ButtonBuilder
	SetGoTextFaceSource(*text.GoTextFaceSource) ButtonBuilder
	SetOnPressed(func(b *Button)) ButtonBuilder
	SetOnMouseHover(func(b *Button)) ButtonBuilder
	SetOnMouseLeave(func(b *Button)) ButtonBuilder
	Build() *Button
}

func NewButtonBuilder

func NewButtonBuilder() ButtonBuilder

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL