d2ui

package
v0.0.0-...-7f92c57 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package d2ui provides ui elements like buttons, scrollbars, checkboxes, text labels, etc.

Index

Constants

View Source
const (
	ButtonTypeWide     ButtonType = 1
	ButtonTypeMedium   ButtonType = 2
	ButtonTypeNarrow   ButtonType = 3
	ButtonTypeCancel   ButtonType = 4
	ButtonTypeTall     ButtonType = 5
	ButtonTypeShort    ButtonType = 6
	ButtonTypeOkCancel ButtonType = 7

	ButtonTypeSkill              ButtonType = 7
	ButtonTypeRun                ButtonType = 8
	ButtonTypeMenu               ButtonType = 9
	ButtonTypeGoldCoin           ButtonType = 10
	ButtonTypeClose              ButtonType = 11
	ButtonTypeSecondaryInvHand   ButtonType = 12
	ButtonTypeMinipanelCharacter ButtonType = 13
	ButtonTypeMinipanelInventory ButtonType = 14
	ButtonTypeMinipanelSkill     ButtonType = 15
	ButtonTypeMinipanelAutomap   ButtonType = 16
	ButtonTypeMinipanelMessage   ButtonType = 17
	ButtonTypeMinipanelQuest     ButtonType = 18
	ButtonTypeMinipanelMen       ButtonType = 19
	ButtonTypeSquareClose        ButtonType = 20
	ButtonTypeSquareOk           ButtonType = 21
	ButtonTypeSkillTreeTab       ButtonType = 22
	ButtonTypeQuestDescr         ButtonType = 23
	ButtonTypeMinipanelOpenClose ButtonType = 24
	ButtonTypeMinipanelParty     ButtonType = 25
	ButtonTypeBuy                ButtonType = 26
	ButtonTypeSell               ButtonType = 27
	ButtonTypeRepair             ButtonType = 28
	ButtonTypeRepairAll          ButtonType = 29
	ButtonTypeUpArrow            ButtonType = 30
	ButtonTypeDownArrow          ButtonType = 31
	ButtonTypeLeftArrow          ButtonType = 32
	ButtonTypeRightArrow         ButtonType = 33
	ButtonTypeQuery              ButtonType = 34
	ButtonTypeSquelchChat        ButtonType = 35
	ButtonTypeTabBlank           ButtonType = 36
	ButtonTypeBlankQuestBtn      ButtonType = 37
	ButtonTypeAddSkill           ButtonType = 38
	ButtonTypePartyButton        ButtonType = 39

	ButtonNoFixedWidth  int = -1
	ButtonNoFixedHeight int = -1
)

ButtonType constants

View Source
const (
	ColorTokenSocketedItem  = ColorTokenGrey
	ColorTokenNormalItem    = ColorTokenWhite
	ColorTokenMagicItem     = ColorTokenBlue
	ColorTokenRareItem      = ColorTokenYellow
	ColorTokenSetItem       = ColorTokenGreen
	ColorTokenUniqueItem    = ColorTokenGold
	ColorTokenCraftedItem   = ColorTokenOrange
	ColorTokenServer        = ColorTokenRed
	ColorTokenButton        = ColorTokenBlack
	ColorTokenCharacterName = ColorTokenGold
	ColorTokenCharacterDesc = ColorTokenWhite
	ColorTokenCharacterType = ColorTokenGreen
)

Color tokens for specific use-cases

View Source
const (
	FrameLeft frameOrientation = iota
	FrameRight
)

Frame orientations

View Source
const (
	// TooltipYTop sets the Y origin of the tooltip to the top
	TooltipYTop tooltipYOrigin = iota
	// TooltipYCenter sets the Y origin of the tooltip to the center
	TooltipYCenter
	// TooltipYBottom sets the Y origin of the tooltip to the bottom
	TooltipYBottom
)
View Source
const (
	// TooltipXLeft sets the X origin of the tooltip to the left
	TooltipXLeft tooltipXOrigin = iota
	// TooltipXCenter sets the X origin of the tooltip to the center
	TooltipXCenter
	// TooltipXRight sets the X origin of the tooltip to the right
	TooltipXRight
)

Variables

This section is empty.

Functions

func ColorTokenize

func ColorTokenize(s string, t ColorToken) string

ColorTokenize formats the string with the given color token

Types

type BaseWidget

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

BaseWidget contains default functionality that all widgets share

func NewBaseWidget

func NewBaseWidget(manager *UIManager) *BaseWidget

NewBaseWidget creates a new BaseWidget with defaults

func (*BaseWidget) Contains

func (b *BaseWidget) Contains(x, y int) bool

Contains determines whether a given x,y coordinate lands within a Widget

func (*BaseWidget) GetManager

func (b *BaseWidget) GetManager() (ui *UIManager)

GetManager returns the uiManager

func (*BaseWidget) GetPosition

func (b *BaseWidget) GetPosition() (x, y int)

GetPosition returns the position of the widget

func (*BaseWidget) GetRenderPriority

func (b *BaseWidget) GetRenderPriority() (prio RenderPriority)

GetRenderPriority returns the order in which this widget is rendered

func (*BaseWidget) GetSize

func (b *BaseWidget) GetSize() (width, height int)

GetSize returns the size of the widget

func (*BaseWidget) GetVisible

func (b *BaseWidget) GetVisible() (visible bool)

GetVisible returns whether the widget is visible

func (*BaseWidget) OffsetPosition

func (b *BaseWidget) OffsetPosition(x, y int)

OffsetPosition moves the widget by x and y

func (*BaseWidget) OnHoverEnd

func (b *BaseWidget) OnHoverEnd(callback func())

OnHoverEnd sets a function that is called if the hovering of the widget ends

func (*BaseWidget) OnHoverStart

func (b *BaseWidget) OnHoverStart(callback func())

OnHoverStart sets a function that is called if the hovering of the widget starts

func (*BaseWidget) OnMouseMove

func (b *BaseWidget) OnMouseMove(x, y int)

OnMouseMove is called when the mouse is moved

func (*BaseWidget) SetPosition

func (b *BaseWidget) SetPosition(x, y int)

SetPosition sets the position of the widget

func (*BaseWidget) SetRenderPriority

func (b *BaseWidget) SetRenderPriority(prio RenderPriority)

SetRenderPriority sets the order in which this widget is rendered

func (*BaseWidget) SetVisible

func (b *BaseWidget) SetVisible(visible bool)

SetVisible make the widget visible, not visible

type Button

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

Button defines a standard wide UI button

func (*Button) Activate

func (v *Button) Activate()

Activate calls the on activated callback handler, if any

func (*Button) Advance

func (v *Button) Advance(_ float64) error

Advance advances the button state

func (*Button) GetEnabled

func (v *Button) GetEnabled() bool

GetEnabled returns the enabled state

func (*Button) GetPressed

func (v *Button) GetPressed() bool

GetPressed returns the pressed state of the button

func (*Button) GetToggled

func (v *Button) GetToggled() bool

GetToggled returns the toggled state of the button

func (*Button) OnActivated

func (v *Button) OnActivated(callback func())

OnActivated defines the callback handler for the activate event

func (*Button) Render

func (v *Button) Render(target d2interface.Surface)

Render renders the button

func (*Button) SetEnabled

func (v *Button) SetEnabled(enabled bool)

SetEnabled sets the enabled state

func (*Button) SetPosition

func (v *Button) SetPosition(x, y int)

SetPosition sets the position of the widget

func (*Button) SetPressed

func (v *Button) SetPressed(pressed bool)

SetPressed sets the pressed state of the button

func (*Button) SetTooltip

func (v *Button) SetTooltip(t *Tooltip)

SetTooltip adds a tooltip to the button

func (*Button) SetVisible

func (v *Button) SetVisible(visible bool)

SetVisible sets the pressed state of the button

func (*Button) Toggle

func (v *Button) Toggle()

Toggle negates the toggled state of the button

type ButtonLayout

type ButtonLayout struct {
	ResourceName     string
	PaletteName      string
	FontPath         string
	ClickableRect    *image.Rectangle
	XSegments        int
	YSegments        int
	BaseFrame        int
	DisabledFrame    int
	DisabledColor    uint32
	TextOffset       int
	FixedWidth       int
	FixedHeight      int
	LabelColor       uint32
	Toggleable       bool
	AllowFrameChange bool
	HasImage         bool
	Tooltip          int
	TooltipXOffset   int
	TooltipYOffset   int
}

ButtonLayout defines the type of buttons

type ButtonType

type ButtonType int

ButtonType defines the type of button

type Checkbox

type Checkbox struct {
	*BaseWidget
	Image d2interface.Surface
	// contains filtered or unexported fields
}

Checkbox represents a checkbox UI element

func (*Checkbox) Activate

func (v *Checkbox) Activate()

Activate activates the checkbox

func (*Checkbox) Advance

func (v *Checkbox) Advance(_ float64) error

Advance does nothing for checkboxes

func (*Checkbox) GetCheckState

func (v *Checkbox) GetCheckState() bool

GetCheckState returns the check state of the checkbox

func (*Checkbox) GetEnabled

func (v *Checkbox) GetEnabled() bool

GetEnabled returns the enabled state of the checkbox

func (*Checkbox) GetPressed

func (v *Checkbox) GetPressed() bool

GetPressed returns the pressed state of the checkbox

func (*Checkbox) OnActivated

func (v *Checkbox) OnActivated(callback func())

OnActivated sets the callback function of the click event for the checkbox

func (*Checkbox) Render

func (v *Checkbox) Render(target d2interface.Surface)

Render renders the checkbox

func (*Checkbox) SetCheckState

func (v *Checkbox) SetCheckState(checkState bool)

SetCheckState sets the check state of the checkbox

func (*Checkbox) SetEnabled

func (v *Checkbox) SetEnabled(enabled bool)

SetEnabled sets the enabled state of the checkbox

func (*Checkbox) SetPressed

func (v *Checkbox) SetPressed(_ bool)

SetPressed does nothing for checkboxes

type ClickableWidget

type ClickableWidget interface {
	Widget
	SetEnabled(enabled bool)
	SetPressed(pressed bool)
	GetEnabled() bool
	GetPressed() bool
	OnActivated(callback func())
	Activate()
}

ClickableWidget defines an object that can be clicked

type ColorToken

type ColorToken string

ColorToken is a string which is used inside of label strings to set font color.

const (
	ColorTokenGrey   ColorToken = "[grey]"
	ColorTokenRed    ColorToken = "[red]"
	ColorTokenWhite  ColorToken = "[white]"
	ColorTokenBlue   ColorToken = "[blue]"
	ColorTokenYellow ColorToken = "[yellow]"
	ColorTokenGreen  ColorToken = "[green]"
	ColorTokenGold   ColorToken = "[gold]"
	ColorTokenOrange ColorToken = "[orange]"
	ColorTokenBlack  ColorToken = "[black]"
)

Color tokens for colored labels

type CursorButton

type CursorButton uint8

CursorButton represents a mouse button

const (
	// CursorButtonLeft represents the left mouse button
	CursorButtonLeft CursorButton = 1
	// CursorButtonRight represents the right mouse button
	CursorButtonRight CursorButton = 2
)

type CustomWidget

type CustomWidget struct {
	*BaseWidget
	// contains filtered or unexported fields
}

CustomWidget is a widget with a fully custom render function

func (*CustomWidget) Advance

func (c *CustomWidget) Advance(elapsed float64) error

Advance is a no-op

func (*CustomWidget) Render

func (c *CustomWidget) Render(target d2interface.Surface)

Render draws the custom widget

func (*CustomWidget) SetTooltip

func (c *CustomWidget) SetTooltip(t *Tooltip)

SetTooltip gives this widget a Tooltip that is displayed if the widget is hovered

type Drawable

type Drawable interface {
	Render(target d2interface.Surface)
	Advance(elapsed float64) error
	GetSize() (width, height int)
	SetPosition(x, y int)
	GetPosition() (x, y int)
	OffsetPosition(xo, yo int)
	GetVisible() bool
	SetVisible(visible bool)
	SetRenderPriority(priority RenderPriority)
	GetRenderPriority() (priority RenderPriority)
}

Drawable represents an instance that can be drawn

type HorizontalAlign

type HorizontalAlign int

HorizontalAlign type, determines alignment along x-axis within a layout

const (
	HorizontalAlignLeft HorizontalAlign = iota
	HorizontalAlignCenter
	HorizontalAlignRight
)

Horizontal alignment types

type Label

type Label struct {
	*BaseWidget

	Alignment HorizontalAlign

	Color map[int]color.Color

	*d2util.Logger
	// contains filtered or unexported fields
}

Label represents a user interface label

func (*Label) Advance

func (v *Label) Advance(elapsed float64) error

Advance is a no-op

func (*Label) GetText

func (v *Label) GetText() string

GetText returns label text

func (*Label) GetTextMetrics

func (v *Label) GetTextMetrics(text string) (width, height int)

GetTextMetrics returns the width and height of the enclosing rectangle in Pixels.

func (*Label) Render

func (v *Label) Render(target d2interface.Surface)

Render draws the label on the screen, respliting the lines to allow for other alignments.

func (*Label) SetBackgroundColor

func (v *Label) SetBackgroundColor(c color.Color)

SetBackgroundColor sets the background highlight color

func (*Label) SetText

func (v *Label) SetText(newText string)

SetText sets the label's text

type LabelButton

type LabelButton struct {
	*BaseWidget

	*d2util.Logger
	// contains filtered or unexported fields
}

LabelButton represents LabelButton

func (*LabelButton) Activate

func (b *LabelButton) Activate()

Activate calls the on activated callback handler, if any

func (*LabelButton) Advance

func (b *LabelButton) Advance(_ float64) error

Advance advances the label-button

func (*LabelButton) GetEnabled

func (b *LabelButton) GetEnabled() bool

GetEnabled returns the enabled state

func (*LabelButton) GetPosition

func (b *LabelButton) GetPosition() (x, y int)

GetPosition returns real position (including offset for the alignment)

func (*LabelButton) GetPressed

func (b *LabelButton) GetPressed() bool

GetPressed returns the pressed state of the button

func (*LabelButton) GetSize

func (b *LabelButton) GetSize() (x, y int)

GetSize returns label's size

func (*LabelButton) OnActivated

func (b *LabelButton) OnActivated(cb func())

OnActivated defines the callback handler for the activate event

func (*LabelButton) Render

func (b *LabelButton) Render(target d2interface.Surface)

Render renders label-button

func (*LabelButton) SetColors

func (b *LabelButton) SetColors(normColor, hoverColor color.Color)

SetColors sets label-button colors (on normal and hovered state)

func (*LabelButton) SetEnabled

func (b *LabelButton) SetEnabled(_ bool)

SetEnabled sets the enabled state

func (*LabelButton) SetPressed

func (b *LabelButton) SetPressed(_ bool)

SetPressed sets the pressed state of the button

func (*LabelButton) SetText

func (b *LabelButton) SetText(text string)

SetText sets button's text

type RenderPriority

type RenderPriority int

RenderPriority determines in which order ui elements are drawn. The higher the number the later an element is drawn.

const (
	RenderPriorityBackground RenderPriority = iota
	RenderPrioritySkilltree
	RenderPrioritySkilltreeIcon
	RenderPriorityHeroStatsPanel
	RenderPriorityQuestLog
	RenderPriorityInventory
	RenderPriorityHUDPanel
	RenderPriorityMinipanel
	RenderPriorityHelpPanel
	RenderPriorityForeground
)

Render priorities that determine the order in which widgets/widgetgroups are rendered. The higher the later it is rendered

type Scrollbar

type Scrollbar struct {
	*BaseWidget
	// contains filtered or unexported fields
}

Scrollbar is a vertical slider ui element

func (*Scrollbar) Activate

func (v *Scrollbar) Activate()

Activate will call the onActivate callback (if set)

func (*Scrollbar) Advance

func (v *Scrollbar) Advance(elapsed float64) error

Advance advances the scrollbar sprite

func (*Scrollbar) GetCurrentOffset

func (v *Scrollbar) GetCurrentOffset() int

GetCurrentOffset gets the current max offset of the scrollbar

func (*Scrollbar) GetEnabled

func (v *Scrollbar) GetEnabled() bool

GetEnabled returns whether or not the scrollbar is enabled

func (*Scrollbar) GetLastDirChange

func (v *Scrollbar) GetLastDirChange() int

GetLastDirChange get the last direction change

func (*Scrollbar) GetMaxOffset

func (v *Scrollbar) GetMaxOffset() int

GetMaxOffset returns the max offset

func (*Scrollbar) GetPressed

func (v *Scrollbar) GetPressed() bool

GetPressed is not used by the scrollbar, but is present to satisfy the ui widget interface

func (*Scrollbar) GetSize

func (v *Scrollbar) GetSize() (width, height int)

GetSize returns the scrollbar width and height

func (*Scrollbar) OnActivated

func (v *Scrollbar) OnActivated(callback func())

OnActivated sets the onActivate callback function for the scrollbar

func (*Scrollbar) Render

func (v *Scrollbar) Render(target d2interface.Surface)

Render renders the scrollbar to the given surface

func (*Scrollbar) SetCurrentOffset

func (v *Scrollbar) SetCurrentOffset(currentOffset int)

SetCurrentOffset sets the scrollbar's current offset

func (*Scrollbar) SetEnabled

func (v *Scrollbar) SetEnabled(enabled bool)

SetEnabled sets the enabled state

func (*Scrollbar) SetMaxOffset

func (v *Scrollbar) SetMaxOffset(maxOffset int)

SetMaxOffset sets the maximum offset of the scrollbar

func (*Scrollbar) SetPressed

func (v *Scrollbar) SetPressed(_ bool)

SetPressed is not used by the scrollbar, but is present to satisfy the ui widget interface

type Sprite

type Sprite struct {
	*BaseWidget

	*d2util.Logger
	// contains filtered or unexported fields
}

Sprite is a positioned visual object.

func (*Sprite) Advance

func (s *Sprite) Advance(elapsed float64) error

Advance advances the animation

func (*Sprite) GetCurrentFrame

func (s *Sprite) GetCurrentFrame() int

GetCurrentFrame gets index of current frame in animation

func (*Sprite) GetCurrentFrameSize

func (s *Sprite) GetCurrentFrameSize() (width, height int)

GetCurrentFrameSize gets the Size(width, height) of the current frame.

func (*Sprite) GetDirection

func (s *Sprite) GetDirection() int

GetDirection get the current animation direction

func (*Sprite) GetDirectionCount

func (s *Sprite) GetDirectionCount() int

GetDirectionCount gets the number of animation direction

func (*Sprite) GetFrameBounds

func (s *Sprite) GetFrameBounds() (width, height int)

GetFrameBounds gets maximum Size(width, height) of all frame.

func (*Sprite) GetFrameCount

func (s *Sprite) GetFrameCount() int

GetFrameCount gets number of frames in animation

func (*Sprite) GetFrameSize

func (s *Sprite) GetFrameSize(frameIndex int) (x, y int, err error)

GetFrameSize gets the Size(width, height) of a indexed frame.

func (*Sprite) GetSize

func (s *Sprite) GetSize() (width, height int)

GetSize returns the size of the current frame

func (*Sprite) GetSurface

func (s *Sprite) GetSurface() d2interface.Surface

GetSurface returns the surface of the sprite at the given frame

func (*Sprite) IsOnFirstFrame

func (s *Sprite) IsOnFirstFrame() bool

IsOnFirstFrame gets if the animation on its first frame

func (*Sprite) IsOnLastFrame

func (s *Sprite) IsOnLastFrame() bool

IsOnLastFrame gets if the animation on its last frame

func (*Sprite) Pause

func (s *Sprite) Pause()

Pause animation

func (*Sprite) PlayBackward

func (s *Sprite) PlayBackward()

PlayBackward play sprites backward

func (*Sprite) PlayForward

func (s *Sprite) PlayForward()

PlayForward plays sprite forward

func (*Sprite) Render

func (s *Sprite) Render(target d2interface.Surface)

Render renders the sprite on the given surface

func (*Sprite) RenderSection

func (s *Sprite) RenderSection(sfc d2interface.Surface, bound image.Rectangle)

RenderSection renders the section of the sprite enclosed by bounds

func (*Sprite) RenderSegmented

func (s *Sprite) RenderSegmented(target d2interface.Surface, segmentsX, segmentsY, frameOffset int)

RenderSegmented renders a sprite that is internally segmented as frames

func (*Sprite) Rewind

func (s *Sprite) Rewind()

Rewind sprite to beginning

func (*Sprite) SetColorMod

func (s *Sprite) SetColorMod(c color.Color)

SetColorMod sets the color modifier

func (*Sprite) SetCurrentFrame

func (s *Sprite) SetCurrentFrame(frameIndex int) error

SetCurrentFrame sets animation at a specific frame

func (*Sprite) SetDirection

func (s *Sprite) SetDirection(directionIndex int) error

SetDirection places the animation in the direction of an animation

func (*Sprite) SetEffect

func (s *Sprite) SetEffect(e d2enum.DrawEffect)

SetEffect sets the draw effect type

func (*Sprite) SetPlayLength

func (s *Sprite) SetPlayLength(playLength float64)

SetPlayLength sets the play length of the sprite animation

func (*Sprite) SetPlayLoop

func (s *Sprite) SetPlayLoop(loop bool)

SetPlayLoop sets whether to loop the animation

type SwitchableButton

type SwitchableButton struct {
	*BaseWidget
	// contains filtered or unexported fields
}

SwitchableButton represents switchable button widget

func (*SwitchableButton) Activate

func (sbtn *SwitchableButton) Activate()

Activate switches widget into active state

func (*SwitchableButton) Advance

func (sbtn *SwitchableButton) Advance(_ float64) error

Advance advances widget

func (*SwitchableButton) Deactivate

func (sbtn *SwitchableButton) Deactivate()

Deactivate switch widget to inactive state

func (*SwitchableButton) GetEnabled

func (sbtn *SwitchableButton) GetEnabled() bool

GetEnabled returns true if current switcher position is enabled

func (*SwitchableButton) GetSize

func (sbtn *SwitchableButton) GetSize() (x, y int)

GetSize returns current button's size

func (*SwitchableButton) OnActivated

func (sbtn *SwitchableButton) OnActivated(cb func())

OnActivated sets onActivate callback

func (*SwitchableButton) OnDeactivated

func (sbtn *SwitchableButton) OnDeactivated(cb func())

OnDeactivated sets onDeactivate callback

func (*SwitchableButton) Render

func (sbtn *SwitchableButton) Render(target d2interface.Surface)

Render renders widget

func (*SwitchableButton) SetActiveTooltip

func (sbtn *SwitchableButton) SetActiveTooltip(tooltip *Tooltip)

SetActiveTooltip sets tooltip of active button's

func (*SwitchableButton) SetDisabledColor

func (sbtn *SwitchableButton) SetDisabledColor(color uint32)

SetDisabledColor sets switcher's disabled color

func (*SwitchableButton) SetEnabled

func (sbtn *SwitchableButton) SetEnabled(enabled bool)

SetEnabled sets button's enabled

func (*SwitchableButton) SetInactiveTooltip

func (sbtn *SwitchableButton) SetInactiveTooltip(tooltip *Tooltip)

SetInactiveTooltip sets tooltip of inactive button's

func (*SwitchableButton) SetPosition

func (sbtn *SwitchableButton) SetPosition(x, y int)

SetPosition sets widget's position

func (*SwitchableButton) SetState

func (sbtn *SwitchableButton) SetState(state bool)

SetState sets button's state

func (*SwitchableButton) SetVisible

func (sbtn *SwitchableButton) SetVisible(visible bool)

SetVisible sets widget's visibility

type TextBox

type TextBox struct {
	*BaseWidget

	*d2util.Logger
	// contains filtered or unexported fields
}

TextBox represents a text input box

func (*TextBox) Activate

func (v *TextBox) Activate()

Activate activates the text box

func (*TextBox) Advance

func (v *TextBox) Advance(_ float64) error

Advance updates the text box

func (*TextBox) GetEnabled

func (v *TextBox) GetEnabled() bool

GetEnabled returns the enabled state of the text box

func (*TextBox) GetPressed

func (v *TextBox) GetPressed() bool

GetPressed does nothing for text boxes

func (*TextBox) GetSize

func (v *TextBox) GetSize() (width, height int)

GetSize returns the size of the text box

func (*TextBox) GetText

func (v *TextBox) GetText() string

GetText returns the text box's text

func (*TextBox) OnActivated

func (v *TextBox) OnActivated(_ func())

OnActivated handles activation events for the text box

func (*TextBox) OnKeyChars

func (v *TextBox) OnKeyChars(event d2interface.KeyCharsEvent) bool

OnKeyChars handles key character events

func (*TextBox) OnKeyRepeat

func (v *TextBox) OnKeyRepeat(event d2interface.KeyEvent) bool

OnKeyRepeat handles key repeat events

func (*TextBox) Render

func (v *TextBox) Render(target d2interface.Surface)

Render renders the text box

func (*TextBox) SetEnabled

func (v *TextBox) SetEnabled(enabled bool)

SetEnabled sets the enabled state of the text box

func (*TextBox) SetFilter

func (v *TextBox) SetFilter(filter string)

SetFilter sets the text box filter

func (*TextBox) SetNumberOnly

func (v *TextBox) SetNumberOnly(max int)

SetNumberOnly sets text box to support only numeric values

func (*TextBox) SetPosition

func (v *TextBox) SetPosition(x, y int)

SetPosition sets the position of the text box

func (*TextBox) SetPressed

func (v *TextBox) SetPressed(_ bool)

SetPressed does nothing for text boxes

func (*TextBox) SetText

func (v *TextBox) SetText(newText string)

SetText sets the text box's text

func (*TextBox) Update

func (v *TextBox) Update()

Update updates the textbox (not currently implemented)

type Tooltip

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

Tooltip contains a label containing text with a transparent, black background

func (*Tooltip) Advance

func (t *Tooltip) Advance(elapsed float64) error

Advance is a no-op

func (*Tooltip) GetSize

func (t *Tooltip) GetSize() (sx, sy int)

GetSize returns the size of the tooltip

func (*Tooltip) Render

func (t *Tooltip) Render(target d2interface.Surface)

Render draws the tooltip

func (*Tooltip) SetBoxEnabled

func (t *Tooltip) SetBoxEnabled(enable bool)

SetBoxEnabled determines whether a black box is drawn around the text

func (*Tooltip) SetText

func (t *Tooltip) SetText(text string)

SetText sets the tooltip text and splits \n into lines

func (*Tooltip) SetTextLines

func (t *Tooltip) SetTextLines(lines []string)

SetTextLines sets the tooltip text in the form of an array of strings

type UIFrame

type UIFrame struct {
	*BaseWidget

	*d2util.Logger
	// contains filtered or unexported fields
}

UIFrame is a representation of a ui panel that occupies the left or right half of the screen when it is visible.

func (*UIFrame) Advance

func (u *UIFrame) Advance(elapsed float64) error

Advance is a no-op

func (*UIFrame) GetFrameBounds

func (u *UIFrame) GetFrameBounds() (width, height int)

GetFrameBounds returns the maximum width and height of all frames in sprite.

func (*UIFrame) GetFrameCount

func (u *UIFrame) GetFrameCount() int

GetFrameCount returns the number of frames in the sprite

func (*UIFrame) Render

func (u *UIFrame) Render(target d2interface.Surface)

Render the frame to the target surface

type UIManager

type UIManager struct {
	CursorX int
	CursorY int

	*d2util.Logger
	// contains filtered or unexported fields
}

UIManager manages a collection of UI elements (buttons, textboxes, labels)

func NewUIManager

NewUIManager creates a UIManager instance with the given input and audio provider

func (*UIManager) Advance

func (ui *UIManager) Advance(elapsed float64)

Advance updates all of the UI elements

func (*UIManager) CursorButtonPressed

func (ui *UIManager) CursorButtonPressed(button CursorButton) bool

CursorButtonPressed determines if the specified button has been pressed

func (*UIManager) CursorPosition

func (ui *UIManager) CursorPosition() (x, y int)

CursorPosition returns the current cursor position

func (*UIManager) Initialize

func (ui *UIManager) Initialize()

Initialize is meant to be called after the game loads all of the necessary files for sprites and audio

func (*UIManager) NewButton

func (ui *UIManager) NewButton(buttonType ButtonType, text string) *Button

NewButton creates an instance of Button

func (*UIManager) NewCheckbox

func (ui *UIManager) NewCheckbox(checkState bool) *Checkbox

NewCheckbox creates a new instance of a checkbox

func (*UIManager) NewCustomWidget

func (ui *UIManager) NewCustomWidget(renderFunc func(target d2interface.Surface), width, height int) *CustomWidget

NewCustomWidget creates a new widget with custom render function

func (*UIManager) NewCustomWidgetCached

func (ui *UIManager) NewCustomWidgetCached(renderFunc func(target d2interface.Surface), width, height int) *CustomWidget

NewCustomWidgetCached creates a new widget and caches anything rendered via the renderFunc into a static image to be displayed

func (*UIManager) NewDefaultButton

func (ui *UIManager) NewDefaultButton(path string, frame int) *Button

NewDefaultButton creates a new button with default settings

func (*UIManager) NewLabel

func (ui *UIManager) NewLabel(fontPath, palettePath string) *Label

NewLabel creates a new instance of a UI label

func (*UIManager) NewLabelButton

func (ui *UIManager) NewLabelButton(font, palette string) *LabelButton

NewLabelButton creates a label-button

func (*UIManager) NewScrollbar

func (ui *UIManager) NewScrollbar(x, y, height int) *Scrollbar

NewScrollbar creates a scrollbar instance

func (*UIManager) NewSprite

func (ui *UIManager) NewSprite(animationPath, palettePath string) (*Sprite, error)

NewSprite creates a new Sprite

func (*UIManager) NewSwitchableButton

func (ui *UIManager) NewSwitchableButton(active, inactive *Button, state bool) *SwitchableButton

NewSwitchableButton creates new switchable button

func (*UIManager) NewTextbox

func (ui *UIManager) NewTextbox() *TextBox

NewTextbox creates a new instance of a text box

func (*UIManager) NewTooltip

func (ui *UIManager) NewTooltip(font,
	palette string,
	originX tooltipXOrigin,
	originY tooltipYOrigin) *Tooltip

NewTooltip creates a tooltip instance. Note here, that we need to define the orign point of the tooltip rect using tooltipXOrigin and tooltinYOrigin

func (*UIManager) NewUIFrame

func (ui *UIManager) NewUIFrame(frameOrientation frameOrientation) *UIFrame

NewUIFrame creates a new Frame instance

func (*UIManager) NewWidgetGroup

func (ui *UIManager) NewWidgetGroup(priority RenderPriority) *WidgetGroup

NewWidgetGroup creates a new widget group

func (*UIManager) OnMouseButtonDown

func (ui *UIManager) OnMouseButtonDown(event d2interface.MouseEvent) bool

OnMouseButtonDown is the mouse button down event handler

func (*UIManager) OnMouseButtonUp

func (ui *UIManager) OnMouseButtonUp(event d2interface.MouseEvent) bool

OnMouseButtonUp is an event handler for input

func (*UIManager) OnMouseMove

func (ui *UIManager) OnMouseMove(event d2interface.MouseMoveEvent) bool

OnMouseMove is the mouse move event handler

func (*UIManager) Render

func (ui *UIManager) Render(target d2interface.Surface)

Render renders all of the UI elements

func (*UIManager) Renderer

func (ui *UIManager) Renderer() d2interface.Renderer

Renderer returns the renderer for this ui manager

func (*UIManager) Reset

func (ui *UIManager) Reset()

Reset resets the state of the UI manager. Typically called for new screens

type Widget

type Widget interface {
	Drawable

	GetManager() (ui *UIManager)
	OnMouseMove(x int, y int)
	OnHoverStart(callback func())
	OnHoverEnd(callback func())

	Contains(x, y int) (contained bool)
	// contains filtered or unexported methods
}

Widget defines an object that is a UI widget

type WidgetGroup

type WidgetGroup struct {
	*BaseWidget
	// contains filtered or unexported fields
}

WidgetGroup allows the grouping of widgets to apply actions to all widgets at once.

func (*WidgetGroup) AddWidget

func (wg *WidgetGroup) AddWidget(w Widget)

AddWidget adds a widget to the group

func (*WidgetGroup) Advance

func (wg *WidgetGroup) Advance(elapsed float64) error

Advance is a no-op here

func (*WidgetGroup) OffsetPosition

func (wg *WidgetGroup) OffsetPosition(x, y int)

OffsetPosition moves all widgets by x and y

func (*WidgetGroup) OnMouseMove

func (wg *WidgetGroup) OnMouseMove(x, y int)

OnMouseMove handles mouse move events

func (*WidgetGroup) Render

func (wg *WidgetGroup) Render(target d2interface.Surface)

Render draw the widgets to the screen

func (*WidgetGroup) SetEnabled

func (wg *WidgetGroup) SetEnabled(enabled bool)

SetEnabled sets enable on all clickable widgets of this group

func (*WidgetGroup) SetVisible

func (wg *WidgetGroup) SetVisible(visible bool)

SetVisible sets the visibility of all widgets in the group

Jump to

Keyboard shortcuts

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