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