ebui

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 15 Imported by: 0

README

EBUI - Ebitengine UI Framework

EBUI is a UI framework for Ebitengine, providing a set of components and layouts for building game interfaces and tools.

Features

  • Component-Based Architecture: Build UIs using reusable, composable components
  • Flexible Layout System: Arrange components using various layout strategies
  • Event System: Handle user interactions with a flexible event system
  • Component Library:
    • Labels with text alignment options
    • Buttons with customizable colors and states
    • Text inputs with selection and clipboard support
    • Scrollable content containers
    • Windows with drag-and-drop functionality

Installation

go get github.com/cbodonnell/ebui

Quick Start

package main

import (
	"image/color"
	"log"

	"github.com/cbodonnell/ebui"
	"github.com/hajimehoshi/ebiten/v2"
)

type Game struct {
	ui *ebui.Manager
}

func NewGame() *Game {
	// Create a root container
	root := ebui.NewLayoutContainer(
		ebui.WithSize(800, 600),
		ebui.WithLayout(ebui.NewVerticalStackLayout(0, ebui.AlignCenter)),
	)

	// Create a label
	label := ebui.NewLabel(
		"Welcome to EBUI!",
		ebui.WithSize(800, 40),
		ebui.WithColor(color.White),
	)

	// Create a button
	button := ebui.NewButton(
		ebui.WithSize(120, 40),
		ebui.WithLabelText("Click Me"),
		ebui.WithClickHandler(func() {
			log.Println("Button clicked!")
		}),
	)

	// Create a container to center the button
	buttonContainer := ebui.NewLayoutContainer(
		ebui.WithSize(800, 40),
		ebui.WithLayout(ebui.NewHorizontalStackLayout(0, ebui.AlignCenter)),
	)

	// Add button to button container
	buttonContainer.AddChild(button)

	// Add label and button container to root
	root.AddChild(label)
	root.AddChild(buttonContainer)

	return &Game{
		// Create a UI manager using the root component
		ui: ebui.NewManager(root),
	}
}

func (g *Game) Update() error {
	return g.ui.Update()
}

func (g *Game) Draw(screen *ebiten.Image) {
	g.ui.Draw(screen)
}

func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
	return 800, 600
}

func main() {
	ebiten.SetWindowSize(800, 600)
	ebiten.SetWindowTitle("EBUI Example")
	if err := ebiten.RunGame(NewGame()); err != nil {
		log.Fatal(err)
	}
}

More comprehensive examples can be found in the examples directory.

Core Concepts

Components

Components are the building blocks of EBUI. Every UI element implements the Component interface:

type Component interface {
    Identifiable
    EbitenLifecycle
    SetPosition(pos Position)
    GetPosition() Position
    SetSize(size Size)
    GetSize() Size
    SetParent(parent Container)
    GetParent() Container
    SetPadding(padding Padding)
    GetPadding() Padding
    Contains(x, y float64) bool
    GetAbsolutePosition() Position
}
Containers

Containers are components that can hold other components. EBUI provides several types of containers:

  • BaseContainer: Basic container with no layout management
  • LayoutContainer: Container that arranges children using a layout strategy
  • ScrollableContainer: Container with scrolling capability
  • ZIndexedContainer: Container that manages component layering
  • WindowManager: Special container for managing multiple windows
Layouts

EBUI provides flexible layout options:

  • Vertical Stack Layout: Arrange components vertically
  • Horizontal Stack Layout: Arrange components horizontally
  • Custom layouts can be implemented by implementing the Layout interface
Event System

The event system supports:

  • Mouse events (click, hover, drag)
  • Keyboard input
  • Focus management
  • Event bubbling and capturing

Components

Label
label := ebui.NewLabel(
    "Hello World",
    ebui.WithSize(200, 40),
    ebui.WithJustify(ebui.JustifyCenter),
    ebui.WithColor(color.Black),
    ebui.WithFont(basicfont.Face7x13), // Default font
)
Button
button := ebui.NewButton(
    ebui.WithSize(120, 40),
    ebui.WithLabelText("Click Me"),
    ebui.WithButtonColors(ebui.ButtonColors{
        Default: color.RGBA{200, 200, 200, 255},
        Hovered: color.RGBA{220, 220, 220, 255},
        Pressed: color.RGBA{170, 170, 170, 255},
    }),
)
Text Input
input := ebui.NewTextInput(
    ebui.WithSize(200, 40),
    ebui.WithInitialText("Hello"),
    ebui.WithOnChange(func(text string) {
        println("Text changed:", text)
    }),
)
Scrollable Container
scrollable := ebui.NewScrollableContainer(
    ebui.WithSize(300, 400),
    ebui.WithLayout(ebui.NewVerticalStackLayout(10, ebui.AlignStart)),
)
Window
windowManager := ebui.NewWindowManager(
	ebui.WithSize(800, 600),
)
window := windowManager.CreateWindow(400, 300,
    ebui.WithWindowTitle("My Window"),
    ebui.WithWindowColors(ebui.WindowColors{
        Background: color.RGBA{240, 240, 240, 255},
        Header:     color.RGBA{200, 200, 200, 255},
        Border:     color.RGBA{0, 0, 0, 255},
    }),
)

Debugging

EBUI includes a debug mode that visualizes component bounds and layout information. Set the global Debug variable to true to enable debug mode:

ebui.Debug = true

Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Debug = false
)

Functions

func GenerateID

func GenerateID() uint64

Types

type Alignment

type Alignment int

Alignment represents horizontal or vertical alignment options

const (
	AlignStart Alignment = iota
	AlignCenter
	AlignEnd
)

type BaseComponent

type BaseComponent struct {
	*BaseTooltipable
	// contains filtered or unexported fields
}

BaseComponent provides common functionality for all components

func NewBaseComponent

func NewBaseComponent(opts ...ComponentOpt) *BaseComponent

func (*BaseComponent) Contains

func (b *BaseComponent) Contains(x, y float64) bool

func (*BaseComponent) Disable added in v0.0.4

func (b *BaseComponent) Disable()

func (*BaseComponent) Draw

func (b *BaseComponent) Draw(screen *ebiten.Image)

func (*BaseComponent) Enable added in v0.0.4

func (b *BaseComponent) Enable()

func (*BaseComponent) GetAbsolutePosition

func (b *BaseComponent) GetAbsolutePosition() Position

func (*BaseComponent) GetBackground

func (b *BaseComponent) GetBackground() color.Color

func (*BaseComponent) GetID

func (b *BaseComponent) GetID() uint64

func (*BaseComponent) GetPadding

func (b *BaseComponent) GetPadding() Padding

func (*BaseComponent) GetParent

func (b *BaseComponent) GetParent() Container

func (*BaseComponent) GetPosition

func (b *BaseComponent) GetPosition() Position

func (*BaseComponent) GetSize

func (b *BaseComponent) GetSize() Size

func (*BaseComponent) Hide added in v0.0.15

func (b *BaseComponent) Hide()

func (*BaseComponent) IsDisabled added in v0.0.4

func (b *BaseComponent) IsDisabled() bool

func (*BaseComponent) IsHidden added in v0.0.15

func (b *BaseComponent) IsHidden() bool

func (*BaseComponent) SetBackground

func (b *BaseComponent) SetBackground(color color.Color)

func (*BaseComponent) SetPadding

func (b *BaseComponent) SetPadding(padding Padding)

func (*BaseComponent) SetParent

func (b *BaseComponent) SetParent(parent Container)

func (*BaseComponent) SetPosition

func (b *BaseComponent) SetPosition(pos Position)

func (*BaseComponent) SetSize

func (b *BaseComponent) SetSize(size Size)

func (*BaseComponent) Show added in v0.0.15

func (b *BaseComponent) Show()

func (*BaseComponent) Update

func (b *BaseComponent) Update() error

type BaseContainer

type BaseContainer struct {
	*BaseComponent
	// contains filtered or unexported fields
}

func NewBaseContainer

func NewBaseContainer(opts ...ComponentOpt) *BaseContainer

func (*BaseContainer) AddChild

func (c *BaseContainer) AddChild(child Component)

func (*BaseContainer) ClearChildren added in v0.0.29

func (c *BaseContainer) ClearChildren()

func (*BaseContainer) Draw

func (c *BaseContainer) Draw(screen *ebiten.Image)

func (*BaseContainer) GetChildren

func (c *BaseContainer) GetChildren() []Component

func (*BaseContainer) RemoveChild

func (c *BaseContainer) RemoveChild(child Component)

func (*BaseContainer) Update

func (c *BaseContainer) Update() error

type BaseFocusable

type BaseFocusable struct {
	*BaseInteractive
	// contains filtered or unexported fields
}

func NewBaseFocusable

func NewBaseFocusable() *BaseFocusable

func (*BaseFocusable) GetTabIndex

func (b *BaseFocusable) GetTabIndex() int

func (*BaseFocusable) IsFocusable

func (b *BaseFocusable) IsFocusable() bool

func (*BaseFocusable) SetFocusable

func (b *BaseFocusable) SetFocusable(focusable bool)

func (*BaseFocusable) SetTabIndex

func (b *BaseFocusable) SetTabIndex(index int)

type BaseInteractive

type BaseInteractive struct {
	// contains filtered or unexported fields
}

BaseInteractive is a base struct that implements the Interactive interface

func NewBaseInteractive

func NewBaseInteractive() *BaseInteractive

func (*BaseInteractive) AddEventListener

func (bi *BaseInteractive) AddEventListener(eventType EventType, handler EventHandler) HandlerID

func (*BaseInteractive) HandleEvent

func (bi *BaseInteractive) HandleEvent(event *Event)

func (*BaseInteractive) RemoveEventListener added in v0.2.1

func (bi *BaseInteractive) RemoveEventListener(eventType EventType, handlerID HandlerID)

type BaseTooltipable added in v0.2.0

type BaseTooltipable struct {
	// contains filtered or unexported fields
}

BaseTooltipable is a base struct that implements the Tooltipable interface

func NewBaseTooltipable added in v0.2.0

func NewBaseTooltipable() *BaseTooltipable

NewBaseTooltipable creates a new base for tooltipable components

func (*BaseTooltipable) ClearTooltip added in v0.2.0

func (b *BaseTooltipable) ClearTooltip()

ClearTooltip clears the tooltip for the component

func (*BaseTooltipable) GetTooltip added in v0.2.0

func (b *BaseTooltipable) GetTooltip() *Tooltip

GetTooltip returns the tooltip for the component

func (*BaseTooltipable) SetTooltip added in v0.2.0

func (b *BaseTooltipable) SetTooltip(tooltip *Tooltip)

SetTooltip sets the tooltip for the component

type Button

type Button struct {
	*ButtonContainer
	// contains filtered or unexported fields
}

func NewButton

func NewButton(opts ...ComponentOpt) *Button

func (*Button) GetLabel

func (b *Button) GetLabel() string

func (*Button) SetLabel

func (b *Button) SetLabel(text string)

type ButtonColors

type ButtonColors struct {
	Default     color.Color
	Hovered     color.Color
	Pressed     color.Color
	FocusBorder color.Color
}

func DefaultButtonColors added in v0.0.6

func DefaultButtonColors() ButtonColors

type ButtonContainer added in v0.0.19

type ButtonContainer struct {
	*LayoutContainer
	*BaseFocusable
	// contains filtered or unexported fields
}

func NewButtonContainer added in v0.0.19

func NewButtonContainer(opts ...ComponentOpt) *ButtonContainer

func (*ButtonContainer) Draw added in v0.0.19

func (b *ButtonContainer) Draw(screen *ebiten.Image)

func (*ButtonContainer) SetClickHandler added in v0.0.19

func (b *ButtonContainer) SetClickHandler(handler func())

func (*ButtonContainer) Update added in v0.0.19

func (b *ButtonContainer) Update() error

type Component

type Component interface {
	Identifiable
	EbitenLifecycle
	SetPosition(pos Position)
	GetPosition() Position
	SetSize(size Size)
	GetSize() Size
	SetParent(parent Container)
	GetParent() Container
	SetPadding(padding Padding)
	GetPadding() Padding
	Contains(x, y float64) bool
	GetAbsolutePosition() Position
	Disable()
	Enable()
	IsDisabled() bool
	Hide()
	Show()
	IsHidden() bool
}

Component is the base interface that all UI elements must implement

type ComponentOpt

type ComponentOpt func(c Component)

func WithBackground

func WithBackground(color color.Color) ComponentOpt

func WithBackgroundColor added in v0.2.0

func WithBackgroundColor(col color.Color) ComponentOpt

func WithBorderColor added in v0.2.0

func WithBorderColor(col color.Color) ComponentOpt

func WithButtonColors

func WithButtonColors(colors ButtonColors) ComponentOpt

func WithChangeHandler

func WithChangeHandler(handler func(string)) ComponentOpt

func WithClickHandler

func WithClickHandler(handler func()) ComponentOpt

func WithColor

func WithColor(color color.Color) ComponentOpt

func WithFont

func WithFont(font font.Face) ComponentOpt

func WithHidden added in v0.0.15

func WithHidden() ComponentOpt

func WithInitialText

func WithInitialText(text string) ComponentOpt

func WithJustify

func WithJustify(justify Justify) ComponentOpt

func WithLabelColor added in v0.0.7

func WithLabelColor(color color.Color) ComponentOpt

func WithLabelText

func WithLabelText(text string) ComponentOpt

func WithLayout

func WithLayout(layout Layout) ComponentOpt

func WithLineSpacing added in v0.0.28

func WithLineSpacing(spacing int) ComponentOpt

func WithMaxValue added in v0.0.18

func WithMaxValue(max float64) ComponentOpt

WithMaxValue sets the maximum value for the slider

func WithMinValue added in v0.0.18

func WithMinValue(min float64) ComponentOpt

WithMinValue sets the minimum value for the slider

func WithOnChangeHandler added in v0.0.18

func WithOnChangeHandler(handler func(value float64)) ComponentOpt

WithOnChangeHandler sets the handler for value changes

func WithPadding

func WithPadding(top, right, bottom, left float64) ComponentOpt

func WithPasswordMasking

func WithPasswordMasking() ComponentOpt

func WithPosition

func WithPosition(pos Position) ComponentOpt

func WithScrollableColors added in v0.0.11

func WithScrollableColors(colors ScrollableColors) ComponentOpt

func WithShowValue added in v0.0.18

func WithShowValue() ComponentOpt

WithShowValue makes the slider display its current value

func WithSize

func WithSize(width, height float64) ComponentOpt

func WithSliderColors added in v0.0.18

func WithSliderColors(colors SliderColors) ComponentOpt

WithSliderColors sets the colors for the slider

func WithStepSize added in v0.0.18

func WithStepSize(step float64) ComponentOpt

WithStepSize sets the step size for the slider

func WithSubmitHandler

func WithSubmitHandler(handler func(string)) ComponentOpt

func WithTabIndex

func WithTabIndex(index int) ComponentOpt

func WithTextInputColors

func WithTextInputColors(colors TextInputColors) ComponentOpt

func WithTextWrap added in v0.0.6

func WithTextWrap() ComponentOpt

func WithThumbSize added in v0.0.18

func WithThumbSize(width, height float64) ComponentOpt

WithThumbSize sets the size of the slider thumb

func WithTooltipColors added in v0.2.0

func WithTooltipColors(colors TooltipColors) ComponentOpt

func WithTooltipOffset added in v0.2.0

func WithTooltipOffset(x, y float64) ComponentOpt

func WithTooltipPosition added in v0.2.0

func WithTooltipPosition(position TooltipPosition) ComponentOpt

func WithTrackHeight added in v0.0.18

func WithTrackHeight(height float64) ComponentOpt

WithTrackHeight sets the height of the slider track

func WithTransitionSpeed added in v0.0.17

func WithTransitionSpeed(speed float64) ComponentOpt

func WithValue added in v0.0.18

func WithValue(value float64) ComponentOpt

WithValue sets the initial value for the slider

func WithValueSuffix added in v0.0.18

func WithValueSuffix(suffix string) ComponentOpt

WithValueSuffix sets a suffix for the displayed value (e.g., "%", "px")

type Container

type Container interface {
	Component
	AddChild(child Component)
	RemoveChild(child Component)
	GetChildren() []Component
	ClearChildren()
}

type EbitenLifecycle

type EbitenLifecycle interface {
	Update() error
	Draw(screen *ebiten.Image)
}

type Event

type Event struct {
	Type                     EventType
	Target                   InteractiveComponent
	CurrentTarget            InteractiveComponent
	RelatedTarget            InteractiveComponent
	MouseX, MouseY           float64
	MouseDeltaX, MouseDeltaY float64
	WheelDeltaX, WheelDeltaY float64
	MouseButton              ebiten.MouseButton
	Timestamp                int64
	Bubbles                  bool
	Phase                    EventPhase
	Path                     []InteractiveComponent
}

type EventBoundary

type EventBoundary interface {
	IsWithinBounds(x, y float64) bool
}

EventBoundary represents a component that controls event propagation

type EventDispatcher

type EventDispatcher struct {
	// contains filtered or unexported fields
}

EventDispatcher manages event subscriptions and dispatching

func NewEventDispatcher

func NewEventDispatcher() *EventDispatcher

func (*EventDispatcher) AddEventListener

func (ed *EventDispatcher) AddEventListener(eventType EventType, handler EventHandler) HandlerID

func (*EventDispatcher) DispatchEvent

func (ed *EventDispatcher) DispatchEvent(event *Event)

func (*EventDispatcher) RemoveEventListener

func (ed *EventDispatcher) RemoveEventListener(eventType EventType, handlerID HandlerID)

type EventHandler

type EventHandler func(event *Event)

EventHandler is a function that handles events

type EventPhase

type EventPhase int
const (
	PhaseNone    EventPhase = 0
	PhaseCapture EventPhase = 1
	PhaseTarget  EventPhase = 2
	PhaseBubble  EventPhase = 3
)

type EventType

type EventType string
const (
	MouseDown  EventType = "mousedown"
	MouseUp    EventType = "mouseup"
	MouseMove  EventType = "mousemove"
	MouseEnter EventType = "mouseenter"
	MouseLeave EventType = "mouseleave"
	Wheel      EventType = "wheel"
	DragStart  EventType = "dragstart"
	Drag       EventType = "drag"
	DragOver   EventType = "dragover"
	DragEnd    EventType = "dragend"
	Drop       EventType = "drop"
	Focus      EventType = "focus"
	Blur       EventType = "blur"
)

type FocusManager

type FocusManager struct {
	// contains filtered or unexported fields
}

func NewFocusManager

func NewFocusManager() *FocusManager

func (*FocusManager) Disable added in v0.0.27

func (fm *FocusManager) Disable()

Disable turns off focus management

func (*FocusManager) Enable added in v0.0.27

func (fm *FocusManager) Enable()

Enable turns on focus management

func (*FocusManager) GetCurrentFocus

func (fm *FocusManager) GetCurrentFocus() FocusableComponent

func (*FocusManager) HandleTab

func (fm *FocusManager) HandleTab(shiftPressed bool)

func (*FocusManager) IsEnabled added in v0.0.27

func (fm *FocusManager) IsEnabled() bool

IsEnabled returns whether focus management is enabled

func (*FocusManager) RefreshFocusableComponents

func (fm *FocusManager) RefreshFocusableComponents(root Component)

RefreshFocusableComponents finds all focusable components in the component tree

func (*FocusManager) SetFocus

func (fm *FocusManager) SetFocus(component FocusableComponent)

type FocusableComponent

type FocusableComponent interface {
	InteractiveComponent
	IsFocusable() bool
	SetFocusable(focusable bool)
	GetTabIndex() int
	SetTabIndex(index int)
}

type HandlerEntry added in v0.2.1

type HandlerEntry struct {
	ID      HandlerID
	Handler EventHandler
}

HandlerEntry represents an event handler with its ID

type HandlerID added in v0.2.1

type HandlerID string

HandlerID is a unique identifier for event handlers

type Identifiable

type Identifiable interface {
	GetID() uint64
}

type ImageCache added in v0.0.3

type ImageCache struct {
	// contains filtered or unexported fields
}

ImageCache provides a global cache for commonly used images

func GetCache added in v0.0.3

func GetCache() *ImageCache

GetCache returns the global image cache instance

func (*ImageCache) BorderImageWithColor added in v0.0.8

func (c *ImageCache) BorderImageWithColor(width, height int, col color.Color) *ebiten.Image

BorderImageWithColor returns a cached border image of the specified size and color

func (*ImageCache) Clear added in v0.0.3

func (c *ImageCache) Clear()

Clear empties the cache

func (*ImageCache) ImageWithColor added in v0.0.3

func (c *ImageCache) ImageWithColor(width, height int, col color.Color) *ebiten.Image

ImageWithColor returns a cached image of the specified size and color

type InputManager

type InputManager struct {
	// contains filtered or unexported fields
}

func NewInputManager

func NewInputManager(opts ...InputManagerOpt) *InputManager

func (*InputManager) DisableFocusManagement added in v0.0.27

func (im *InputManager) DisableFocusManagement()

DisableFocusManagement disables the focus manager

func (*InputManager) EnableFocusManagement added in v0.0.27

func (im *InputManager) EnableFocusManagement()

EnableFocusManagement enables the focus manager

func (*InputManager) IsFocusManagementEnabled added in v0.0.27

func (im *InputManager) IsFocusManagementEnabled() bool

IsFocusManagementEnabled returns whether focus management is enabled

func (*InputManager) Update

func (im *InputManager) Update(root Component)

Update processes input events and dispatches them to the appropriate components. It handles mouse button events, mouse movement, wheel events, and drag events. The root component is used as the starting point for event propagation.

type InputManagerOpt added in v0.0.24

type InputManagerOpt func(im *InputManager)

func WithFocusManager added in v0.0.24

func WithFocusManager(fm *FocusManager) InputManagerOpt

WithFocusManager sets the focus manager for the input manager

type Interactive

type Interactive interface {
	HandleEvent(event *Event)
	AddEventListener(eventType EventType, handler EventHandler) HandlerID
	RemoveEventListener(eventType EventType, handlerID HandlerID)
}

Interactive is an interface that can receive input events

type InteractiveComponent

type InteractiveComponent interface {
	Component
	Interactive
}

InteractiveComponent is an interface that combines the Component and Interactive interfaces

type Justify

type Justify int
const (
	JustifyLeft Justify = iota
	JustifyCenter
	JustifyRight
)

type Label

type Label struct {
	*BaseComponent
	// contains filtered or unexported fields
}

func NewLabel

func NewLabel(text string, opts ...ComponentOpt) *Label

func (*Label) Draw

func (b *Label) Draw(screen *ebiten.Image)

func (*Label) GetColor

func (b *Label) GetColor() color.Color

func (*Label) GetLineHeight added in v0.0.28

func (b *Label) GetLineHeight() int

func (*Label) GetNumberOfLines added in v0.0.28

func (b *Label) GetNumberOfLines() int

func (*Label) GetText

func (b *Label) GetText() string

func (*Label) GetTextHeight added in v0.0.28

func (b *Label) GetTextHeight() int

func (*Label) SetColor

func (b *Label) SetColor(color color.Color)

func (*Label) SetText

func (b *Label) SetText(text string)

type Layout

type Layout interface {
	ArrangeChildren(container Container)
	GetMinSize(container Container) Size
}

Layout defines how a container should arrange its children

type LayoutContainer

type LayoutContainer struct {
	*BaseContainer
	// contains filtered or unexported fields
}

func NewLayoutContainer

func NewLayoutContainer(opts ...ComponentOpt) *LayoutContainer

func (*LayoutContainer) AddChild added in v0.0.2

func (c *LayoutContainer) AddChild(child Component)

func (*LayoutContainer) ArrangeChildren added in v0.0.25

func (c *LayoutContainer) ArrangeChildren()

func (*LayoutContainer) RemoveChild added in v0.0.2

func (c *LayoutContainer) RemoveChild(child Component)

func (*LayoutContainer) Update

func (c *LayoutContainer) Update() error

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(root Container, opts ...ManagerOpt) *Manager

NewManager creates a new UI Manager with the given root container.

func (*Manager) DisableFocus added in v0.0.27

func (u *Manager) DisableFocus()

DisableFocus disables focus management for the UI.

func (*Manager) Draw

func (u *Manager) Draw(screen *ebiten.Image)

func (*Manager) EnableFocus added in v0.0.27

func (u *Manager) EnableFocus()

EnableFocus enables focus management for the UI.

func (*Manager) IsFocusEnabled added in v0.0.27

func (u *Manager) IsFocusEnabled() bool

IsFocusEnabled returns whether focus management is enabled.

func (*Manager) Update

func (u *Manager) Update() error

Update updates the UI Manager.

type ManagerOpt added in v0.0.24

type ManagerOpt func(m *Manager)

func WithInputManager added in v0.0.24

func WithInputManager(im *InputManager) ManagerOpt

type Padding

type Padding struct {
	Top, Right, Bottom, Left float64
}

Padding represents padding around a component

type Position

type Position struct {
	X, Y     float64
	Relative bool
	ZIndex   int
}

Position represents the position of a component

type Scrollable

type Scrollable interface {
	Container
	Interactive
	EventBoundary
	GetScrollOffset() Position
	SetScrollOffset(offset Position)
	HideScrollBar()
	ShowScrollBar()
	IsScrollBarHidden() bool
	ScrollToTop()
	ScrollToBottom()
}

type ScrollableColors added in v0.0.11

type ScrollableColors struct {
	Track     color.Color
	Thumb     color.Color
	ThumbDrag color.Color
}

func DefaultScrollableColors added in v0.0.11

func DefaultScrollableColors() ScrollableColors

type ScrollableContainer

type ScrollableContainer struct {
	*BaseFocusable
	*LayoutContainer
	// contains filtered or unexported fields
}

func NewScrollableContainer

func NewScrollableContainer(opts ...ComponentOpt) *ScrollableContainer

func (*ScrollableContainer) AddChild

func (sc *ScrollableContainer) AddChild(child Component)

func (*ScrollableContainer) Contains

func (sc *ScrollableContainer) Contains(x, y float64) bool

func (*ScrollableContainer) Draw

func (sc *ScrollableContainer) Draw(screen *ebiten.Image)

func (*ScrollableContainer) GetScrollOffset

func (sc *ScrollableContainer) GetScrollOffset() Position

func (*ScrollableContainer) HideScrollBar added in v0.0.25

func (sc *ScrollableContainer) HideScrollBar()

func (*ScrollableContainer) IsScrollBarHidden added in v0.0.25

func (sc *ScrollableContainer) IsScrollBarHidden() bool

func (*ScrollableContainer) IsScrolledToBottom added in v0.0.27

func (sc *ScrollableContainer) IsScrolledToBottom() bool

func (*ScrollableContainer) IsScrolledToTop added in v0.0.27

func (sc *ScrollableContainer) IsScrolledToTop() bool

func (*ScrollableContainer) IsWithinBounds

func (sc *ScrollableContainer) IsWithinBounds(x, y float64) bool

func (*ScrollableContainer) RemoveChild

func (sc *ScrollableContainer) RemoveChild(child Component)

func (*ScrollableContainer) ScrollToBottom added in v0.0.24

func (sc *ScrollableContainer) ScrollToBottom()

func (*ScrollableContainer) ScrollToTop added in v0.0.24

func (sc *ScrollableContainer) ScrollToTop()

func (*ScrollableContainer) SetScrollOffset

func (sc *ScrollableContainer) SetScrollOffset(offset Position)

func (*ScrollableContainer) ShowScrollBar added in v0.0.25

func (sc *ScrollableContainer) ShowScrollBar()

func (*ScrollableContainer) Update

func (sc *ScrollableContainer) Update() error

type Size

type Size struct {
	Width, Height float64
}

Size represents the dimensions of a component

func (Size) IsDrawable

func (s Size) IsDrawable() bool

type Slider added in v0.0.18

type Slider struct {
	*BaseFocusable
	*LayoutContainer
	// contains filtered or unexported fields
}

Slider is a component that allows selecting a value within a range

func NewSlider added in v0.0.18

func NewSlider(opts ...ComponentOpt) *Slider

NewSlider creates a new slider component

func (*Slider) Draw added in v0.0.18

func (s *Slider) Draw(screen *ebiten.Image)

func (*Slider) GetValue added in v0.0.18

func (s *Slider) GetValue() float64

GetValue returns the current slider value

func (*Slider) SetColors added in v0.0.18

func (s *Slider) SetColors(colors SliderColors)

SetColors sets the color scheme for the slider

func (*Slider) SetOnChange added in v0.0.18

func (s *Slider) SetOnChange(handler func(value float64))

SetOnChange sets the handler for value changes

func (*Slider) SetValue added in v0.0.18

func (s *Slider) SetValue(value float64)

SetValue sets the slider's value, respecting min/max bounds

func (*Slider) Update added in v0.0.18

func (s *Slider) Update() error

type SliderColors added in v0.0.18

type SliderColors struct {
	Track        color.Color
	TrackFilled  color.Color
	Thumb        color.Color
	ThumbHovered color.Color
	ThumbDragged color.Color
	FocusBorder  color.Color
}

SliderColors represents the color scheme for a slider

func DefaultSliderColors added in v0.0.18

func DefaultSliderColors() SliderColors

DefaultSliderColors returns a default color scheme for sliders

type SliderOpt added in v0.0.18

type SliderOpt func(s *Slider)

SliderOpt is a function that configures a Slider

type StackConfig

type StackConfig struct {
	Spacing   float64
	Alignment Alignment
}

StackConfig holds configuration for stack layouts

type StackContainer added in v0.0.17

type StackContainer struct {
	*BaseContainer
	// contains filtered or unexported fields
}

StackContainer manages a stack of views/screens with transitions

func NewStackContainer added in v0.0.17

func NewStackContainer(opts ...ComponentOpt) *StackContainer

func (*StackContainer) Clear added in v0.0.17

func (sc *StackContainer) Clear()

Clear removes all views from the stack except the root view

func (*StackContainer) Draw added in v0.0.20

func (sc *StackContainer) Draw(screen *ebiten.Image)

Draw overrides the BaseContainer.Draw method to implement clipping

func (*StackContainer) GetActiveView added in v0.0.17

func (sc *StackContainer) GetActiveView() Component

GetActiveView returns the currently active view

func (*StackContainer) Pop added in v0.0.17

func (sc *StackContainer) Pop()

Pop removes the top view from the stack with a transition

func (*StackContainer) Push added in v0.0.17

func (sc *StackContainer) Push(view Container)

Push adds a new view to the stack with a transition

func (*StackContainer) Update added in v0.0.17

func (sc *StackContainer) Update() error

Update handles the transition animation

type StackLayout

type StackLayout struct {
	Horizontal bool
	Config     StackConfig
}

StackLayout implements vertical or horizontal stacking of components

func NewHorizontalStackLayout

func NewHorizontalStackLayout(spacing float64, align Alignment) *StackLayout

NewHorizontalStackLayout is a helper function to create a horizontal stack layout

func NewStackLayout

func NewStackLayout(opts ...StackLayoutOpt) *StackLayout

func NewVerticalStackLayout

func NewVerticalStackLayout(spacing float64, align Alignment) *StackLayout

NewVerticalStackLayout is a helper function to create a vertical stack layout

func (*StackLayout) ArrangeChildren

func (l *StackLayout) ArrangeChildren(container Container)

ArrangeChildren positions all children in a vertical or horizontal stack

func (*StackLayout) GetMinSize

func (l *StackLayout) GetMinSize(container Container) Size

GetMinSize returns the minimum size required to fit all children

type StackLayoutOpt

type StackLayoutOpt func(l *StackLayout)

func WithAlignment

func WithAlignment(align Alignment) StackLayoutOpt

func WithHorizontal

func WithHorizontal() StackLayoutOpt

func WithSpacing

func WithSpacing(spacing float64) StackLayoutOpt

type TextInput

type TextInput struct {
	*BaseFocusable
	*BaseContainer
	// contains filtered or unexported fields
}

func NewTextInput

func NewTextInput(opts ...ComponentOpt) *TextInput

func (*TextInput) Blur

func (t *TextInput) Blur()

func (*TextInput) ClearSelection

func (t *TextInput) ClearSelection()

func (*TextInput) Draw

func (t *TextInput) Draw(screen *ebiten.Image)

func (*TextInput) Focus

func (t *TextInput) Focus()

func (*TextInput) GetText

func (t *TextInput) GetText() string

func (*TextInput) IsFocused

func (t *TextInput) IsFocused() bool

func (*TextInput) Select

func (t *TextInput) Select(start, end int)

func (*TextInput) SetFont

func (t *TextInput) SetFont(font font.Face)

func (*TextInput) SetText

func (t *TextInput) SetText(text string)

func (*TextInput) Update

func (t *TextInput) Update() error

type TextInputColors

type TextInputColors struct {
	Text        color.Color
	Background  color.Color
	Cursor      color.Color
	Selection   color.Color
	FocusBorder color.Color
}

func DefaultTextInputColors

func DefaultTextInputColors() TextInputColors

type Tooltip added in v0.2.0

type Tooltip struct {
	*LayoutContainer
	// contains filtered or unexported fields
}

Tooltip represents a tooltip component that can be attached to other components

func NewTooltip added in v0.2.0

func NewTooltip(opts ...ComponentOpt) *Tooltip

NewTooltip creates a new tooltip component

func (*Tooltip) Draw added in v0.2.0

func (t *Tooltip) Draw(screen *ebiten.Image)

Draw renders the tooltip

func (*Tooltip) GetMousePosition added in v0.2.0

func (t *Tooltip) GetMousePosition() (float64, float64)

GetMousePosition returns the current mouse position

func (*Tooltip) GetOffset added in v0.2.0

func (t *Tooltip) GetOffset() (float64, float64)

GetOffset returns the tooltip's offset

func (*Tooltip) GetTarget added in v0.2.0

func (t *Tooltip) GetTarget() Component

GetTarget returns the target component this tooltip belongs to

func (*Tooltip) GetTooltipPosition added in v0.2.0

func (t *Tooltip) GetTooltipPosition() TooltipPosition

GetTooltipPosition returns the tooltip's preferred position

func (*Tooltip) SetContent added in v0.2.0

func (t *Tooltip) SetContent(content Component)

SetContent sets the content of the tooltip

func (*Tooltip) SetTarget added in v0.2.0

func (t *Tooltip) SetTarget(target Component)

SetTarget sets the target component this tooltip belongs to

func (*Tooltip) UpdateMousePosition added in v0.2.0

func (t *Tooltip) UpdateMousePosition(x, y float64)

UpdateMousePosition updates the current mouse position for the tooltip

type TooltipColors added in v0.2.0

type TooltipColors struct {
	Background color.Color
	Border     color.Color
}

TooltipColors contains all the colors used by a tooltip

func DefaultTooltipColors added in v0.2.0

func DefaultTooltipColors() TooltipColors

DefaultTooltipColors returns the default color scheme for tooltips

type TooltipHandlers added in v0.2.1

type TooltipHandlers struct {
	// contains filtered or unexported fields
}

TooltipHandlers stores the event handler IDs for a registered tooltip

type TooltipManager added in v0.2.0

type TooltipManager struct {
	*ZIndexedContainer
	// contains filtered or unexported fields
}

TooltipManager handles the display and positioning of tooltips

func NewTooltipManager added in v0.2.0

func NewTooltipManager(opts ...ComponentOpt) *TooltipManager

NewTooltipManager creates a new TooltipManager

func (*TooltipManager) Disable added in v0.2.0

func (tm *TooltipManager) Disable()

Disable disables the tooltip manager and hides any active tooltips

func (*TooltipManager) Enable added in v0.2.0

func (tm *TooltipManager) Enable()

Enable enables the tooltip manager

func (*TooltipManager) HandleMouseMove added in v0.2.0

func (tm *TooltipManager) HandleMouseMove(mouseX, mouseY float64)

HandleMouseMove handles mouse movement to update tooltip position

func (*TooltipManager) HandleTargetHover added in v0.2.0

func (tm *TooltipManager) HandleTargetHover(component Component, mouseX, mouseY float64)

HandleTargetHover handles when a component with a tooltip is hovered

func (*TooltipManager) HandleTargetLeave added in v0.2.0

func (tm *TooltipManager) HandleTargetLeave(component Component)

HandleTargetLeave handles when the mouse leaves a component with a tooltip

func (*TooltipManager) HideTooltip added in v0.2.0

func (tm *TooltipManager) HideTooltip()

HideTooltip hides the currently visible tooltip

func (*TooltipManager) IsDisabled added in v0.2.0

func (tm *TooltipManager) IsDisabled() bool

IsDisabled returns whether the tooltip manager is disabled

func (*TooltipManager) RegisterTooltip added in v0.2.0

func (tm *TooltipManager) RegisterTooltip(component TooltipableComponent, tooltip *Tooltip)

RegisterTooltip registers a component to show tooltips It adds event listeners for mouse enter, leave, and move events to manage tooltip visibility and positioning

func (*TooltipManager) ShowTooltip added in v0.2.0

func (tm *TooltipManager) ShowTooltip(tooltip *Tooltip)

ShowTooltip displays a tooltip at the appropriate position

func (*TooltipManager) UnregisterTooltip added in v0.2.1

func (tm *TooltipManager) UnregisterTooltip(component TooltipableComponent)

UnregisterTooltip removes a tooltip from a component and cleans up its event listeners Other unrelated event listeners on the component will remain intact

func (*TooltipManager) Update added in v0.2.0

func (tm *TooltipManager) Update() error

Update updates the tooltip manager state

type TooltipPosition added in v0.2.0

type TooltipPosition int

TooltipPosition defines the preferred position of a tooltip relative to the mouse cursor

const (
	// Tooltip positions
	TooltipPositionAuto        TooltipPosition = iota // Automatically determine best position
	TooltipPositionTop                                // Above the cursor
	TooltipPositionRight                              // To the right of the cursor
	TooltipPositionBottom                             // Below the cursor
	TooltipPositionLeft                               // To the left of the cursor
	TooltipPositionTopLeft                            // Above and to the left of the cursor
	TooltipPositionTopRight                           // Above and to the right of the cursor
	TooltipPositionBottomLeft                         // Below and to the left of the cursor
	TooltipPositionBottomRight                        // Below and to the right of the cursor
)

type Tooltipable added in v0.2.0

type Tooltipable interface {
	SetTooltip(tooltip *Tooltip)
	GetTooltip() *Tooltip
	ClearTooltip()
}

Tooltipable is an interface for components that can have tooltips attached

type TooltipableComponent added in v0.2.0

type TooltipableComponent interface {
	InteractiveComponent
	Tooltipable
}

type Window

type Window struct {
	*BaseFocusable
	*LayoutContainer
	// contains filtered or unexported fields
}

func (*Window) AddChild

func (w *Window) AddChild(child Component)

func (*Window) Draw

func (w *Window) Draw(screen *ebiten.Image)

func (*Window) Hide

func (w *Window) Hide()

Hide makes the window invisible

func (*Window) IsVisible

func (w *Window) IsVisible() bool

IsVisible returns whether the window is currently visible

func (*Window) RemoveChild

func (w *Window) RemoveChild(child Component)

func (*Window) SetSize added in v0.0.23

func (w *Window) SetSize(size Size)

func (*Window) SetTitle added in v0.0.16

func (w *Window) SetTitle(title string)

func (*Window) Show

func (w *Window) Show()

Show makes the window visible

func (*Window) Toggle added in v0.0.10

func (w *Window) Toggle()

Toggle shows the window if hidden, hides it if visible

type WindowColors

type WindowColors struct {
	Background color.Color
	Header     color.Color
	HeaderText color.Color
	Border     color.Color
	// Close button colors (optional, will be derived from header color if nil)
	CloseButton  color.Color
	CloseHovered color.Color
	ClosePressed color.Color
	CloseCross   color.Color
}

WindowColors represents the color scheme for a window

func DefaultWindowColors

func DefaultWindowColors() WindowColors

DefaultWindowColors returns a default color scheme for windows

type WindowManager

type WindowManager struct {
	*ZIndexedContainer
	// contains filtered or unexported fields
}

func NewWindowManager

func NewWindowManager(opts ...ComponentOpt) *WindowManager

func (*WindowManager) CreateWindow

func (wm *WindowManager) CreateWindow(width, height float64, opts ...WindowOpt) *Window

func (*WindowManager) SetActiveWindow

func (wm *WindowManager) SetActiveWindow(window *Window)

type WindowOpt

type WindowOpt func(w *Window)

func WithBorderWidth

func WithBorderWidth(width float64) WindowOpt

WithBorderWidth sets the width of the window border

func WithCloseButtonSize added in v0.1.0

func WithCloseButtonSize(size Size) WindowOpt

WithCloseButtonSize sets the size of the close button

func WithCloseCallback

func WithCloseCallback(callback func()) WindowOpt

WithCloseCallback sets the callback for when the window is closed

func WithHeaderHeight

func WithHeaderHeight(height float64) WindowOpt

WithHeaderHeight sets the height of the window header

func WithStatic added in v0.0.6

func WithStatic() WindowOpt

WithStatic makes the window non-draggable

func WithWindowColors

func WithWindowColors(colors WindowColors) WindowOpt

WithWindowColors sets custom colors for the window

func WithWindowPosition

func WithWindowPosition(x, y float64) WindowOpt

WithPosition sets the window position

func WithWindowTitle

func WithWindowTitle(title string) WindowOpt

WithWindowTitle sets the window title

type WindowState

type WindowState int
const (
	WindowStateHidden WindowState = iota
	WindowStateNormal
)

type ZIndexedContainer

type ZIndexedContainer struct {
	*BaseContainer
}

func NewZIndexedContainer

func NewZIndexedContainer(opts ...ComponentOpt) *ZIndexedContainer

func (*ZIndexedContainer) Draw

func (z *ZIndexedContainer) Draw(screen *ebiten.Image)

func (*ZIndexedContainer) GetChildren

func (z *ZIndexedContainer) GetChildren() []Component

GetChildren returns the children of the container sorted by ZIndex.

func (*ZIndexedContainer) Update

func (z *ZIndexedContainer) Update() error

Directories

Path Synopsis
examples
inventory command
login command
settings command
tasks command
tooltip command

Jump to

Keyboard shortcuts

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