debugui

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2025 License: Apache-2.0 Imports: 24 Imported by: 18

README

DebugUI for Ebitengine

DebugUI is a UI toolkit for Ebitengine applications, primarily intended for debugging purposes.

The project is currently under development. The API is subject to frequent changes.

DebugUI is based on Microui. The original Microui was developed by @rxi. The original Go port was developed by @zeozeozeo and @Zyko0.

License

DebugUI for Ebitengine is licensed under Apache license version 2.0. See LICENSE file.

Microui

https://github.com/rxi/microui

Copyright (c) 2024 rxi

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrawText

func DrawText(dst *ebiten.Image, str string, options *text.DrawOptions)

DrawText draws the text on the destination image with the given options, in the same way as debugui's widget text drawing.

Note that you have to specify the scale at the options when the context scale is not 1.

Types

type ContainerLayout

type ContainerLayout struct {
	// Bounds is the bounds of the widget.
	Bounds image.Rectangle

	// BodyBounds is the bounds of the body area of the container.
	BodyBounds image.Rectangle

	// ContentSize is the size of the content.
	// ContentSize can be larger than Bounds or BodyBounds. In this case, the widget should be scrollable.
	ContentSize image.Point

	// ScrollOffset is the offset of the scroll.
	ScrollOffset image.Point
}

ContainerLayout represents the layout of a container widget.

type Context

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

Context is the main context for the debug UI.

func (*Context) Button

func (c *Context) Button(label string) EventHandler

Button creates a button widget with the given label.

Button returns an EventHandler to handle click events. A returned EventHandler is never nil.

A Button widget is uniquely determined by its call location. Function calls made in different locations will create different widgets. If you want to generate different widgets with the same function call in a loop (such as a for loop), use [IDScope].

func (*Context) Checkbox

func (c *Context) Checkbox(state *bool, label string) EventHandler

Checkbox creates a checkbox with the given boolean state and text label.

A Checkbox widget is uniquely determined by its call location. Function calls made in different locations will create different widgets. If you want to generate different widgets with the same function call in a loop (such as a for loop), use [IDScope].

func (*Context) ClosePopup

func (c *Context) ClosePopup(popupID PopupID)

ClosePopup closes a popup window.

func (*Context) DrawOnlyWidget

func (c *Context) DrawOnlyWidget(f func(screen *ebiten.Image))

DrawOnlyWidget adds a widget that only draws the given function without user interaction.

func (*Context) GridCell

func (c *Context) GridCell(f func(bounds image.Rectangle))

GridCell creates a grid cell with the content defined by the function f.

func (*Context) Header

func (c *Context) Header(label string, initialExpansion bool, f func())

Header creates a header widget with the given label.

initialExpansion specifies whether the header is initially expanded. f is called to render the content of the header. The content is only rendered when the header is expanded.

A Header widget is uniquely determined by its call location. Function calls made in different locations will create different widgets. If you want to generate different widgets with the same function call in a loop (such as a for loop), use [IDScope].

func (*Context) IDScope

func (c *Context) IDScope(name string, f func())

IDScope creates a new scope for widget IDs. IDScope creates a unique scope based on the caller's position and the given name string.

IDScope is useful when you want to create multiple widgets at the same position e.g. in a for loop.

func (*Context) NumberField

func (c *Context) NumberField(value *int, step int) EventHandler

NumberField creates a number field to modify the value of a int value.

step is the amount to increment or decrement the value when the user drags the thumb.

NumberField returns an EventHandler to handle value change events. A returned EventHandler is never nil.

A NumberField widget is uniquely determined by its call location. Function calls made in different locations will create different widgets. If you want to generate different widgets with the same function call in a loop (such as a for loop), use [IDScope].

func (*Context) NumberFieldF

func (c *Context) NumberFieldF(value *float64, step float64, digits int) EventHandler

NumberFieldF creates a number field to modify the value of a float64 value.

step is the amount to increment or decrement the value when the user drags the thumb. digits is the number of decimal places to display.

NumberFieldF returns an EventHandler to handle value change events. A returned EventHandler is never nil.

A NumberFieldF widget is uniquely determined by its call location. Function calls made in different locations will create different widgets. If you want to generate different widgets with the same function call in a loop (such as a for loop), use [IDScope].

func (*Context) OpenPopup

func (c *Context) OpenPopup(popupID PopupID)

OpenPopup opens a popup window at the current pointing position.

func (*Context) Panel

func (c *Context) Panel(f func(layout ContainerLayout))

Panel creates a new panel with the contents defined by the function f. Panel can have scroll bars, and the contents of the panel can be scrolled.

func (*Context) Popup

func (c *Context) Popup(f func(layout ContainerLayout, popupID PopupID)) PopupID

Popup creates a popup window with the content defined by the provided function, and returns the PopupID of the popup window.

By default, the popup window is hidden. To show the popup window, call OpenPopup with the PopupID returned by this function.

func (*Context) Scale

func (c *Context) Scale() int

Scale returns the scale of the UI.

func (*Context) SetGridLayout

func (c *Context) SetGridLayout(widths []int, heights []int)

SetGridLayout sets the grid layout. widths and heights are the sizes of each column and row.

If a size is 0, the default size is used. If a size is negative, the size represents the ratio of the remaining space. For example, if widths is []int{100, -1}, the first column is 100 pixels and the second column takes the remaining space. If widths is []int{100, -1, -2}, the first column is 100 pixels, the second column takes 1/3 of the remaining space, and the third column takes 2/3 of the remaining space.

If widths is nil, one column width with -1 is used for windows, and 0 (the default size) is used for popups. If heights is nil, 0 (the default size) is used.

When the number of items exceeds the number of grid cells, a new row starts with the same grid layout.

func (*Context) SetScale

func (c *Context) SetScale(scale int)

SetScale sets the scale of the UI.

The scale affects the rendering result of the UI.

The default scale is 1.

func (*Context) SetScroll

func (c *Context) SetScroll(scroll image.Point)

SetScroll sets the scroll offset of the current container.

func (*Context) SetTextFieldValue

func (c *Context) SetTextFieldValue(value string)

SetTextFieldValue sets the value of the current text field.

If the last widget is not a text field, this function does nothing.

func (*Context) Slider

func (c *Context) Slider(value *int, lo, hi int, step int) EventHandler

Slider cretes a slider widget with the given int value, range, and step.

lo and hi specify the range of the slider.

Slider returns an EventHandler to handle value change events. A returned EventHandler is never nil.

A Slider widget is uniquely determined by its call location. Function calls made in different locations will create different widgets. If you want to generate different widgets with the same function call in a loop (such as a for loop), use [IDScope].

func (*Context) SliderF

func (c *Context) SliderF(value *float64, lo, hi float64, step float64, digits int) EventHandler

SliderF cretes a slider widget with the given float64 value, range, step, and number of digits.

lo and hi specify the range of the slider. digits specifies the number of digits to display after the decimal point.

SliderF returns an EventHandler to handle value change events. A returned EventHandler is never nil.

A SliderF widget is uniquely determined by its call location. Function calls made in different locations will create different widgets. If you want to generate different widgets with the same function call in a loop (such as a for loop), use [IDScope].

func (*Context) Text

func (c *Context) Text(text string)

Text creates a text label.

func (*Context) TextField

func (c *Context) TextField(buf *string) EventHandler

TextField creates a text field to modify the value of a string buf.

TextField returns an EventHandler to handle events when the value is confirmed, such as on blur or Enter key press. A returned EventHandler is never nil.

A TextField widget is uniquely determined by its call location. Function calls made in different locations will create different widgets. If you want to generate different widgets with the same function call in a loop (such as a for loop), use [IDScope].

func (*Context) TreeNode

func (c *Context) TreeNode(label string, f func())

TreeNode creates a tree node widget with the given label.

A TreeNode widget is uniquely determined by its call location. Function calls made in different locations will create different widgets. If you want to generate different widgets with the same function call in a loop (such as a for loop), use [IDScope].

func (*Context) Window

func (c *Context) Window(title string, rect image.Rectangle, f func(layout ContainerLayout))

Window creates a new window with the contents defined by the function f.

title is the title of the window. rect is the initial size and position of the window.

type DebugUI

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

DebugUI is a debug UI.

The zero value for DebugUI is ready to use.

func (*DebugUI) Draw

func (d *DebugUI) Draw(screen *ebiten.Image)

Draw draws the debug UI.

Draw should be called once in the game's Draw function.

func (*DebugUI) Update

func (d *DebugUI) Update(f func(ctx *Context) error) (InputCapturingState, error)

Update updates the debug UI.

Update returns true if the debug UI is capturing input, e.g. when a widget has focus. Otherwise, Update returns false.

Update should be called once in the game's Update function.

type EventHandler

type EventHandler interface {
	// On registers a callback function to be called when the event occurs.
	On(func())
}

EventHandler is an interface for handling events in a widget.

type InputCapturingState

type InputCapturingState int

InputCapturingState is a bit mask that indicates the input capturing state of the debug UI.

const (
	// InputCapturingStateHover indicates that a pointing device is hovering over a widget.
	InputCapturingStateHover InputCapturingState = 1 << iota

	// InputCapturingStateFocus indicates that a widget like a text field is focused.
	InputCapturingStateFocus
)

type PopupID

type PopupID widgetID

PopupID is the ID of a popup window.

Directories

Path Synopsis
internal
vettool command

Jump to

Keyboard shortcuts

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