Documentation ¶
Overview ¶
Package d2ui provides ui elements like buttons, scrollbars, checkboxes, text labels, etc.
Index ¶
- Constants
- func ColorTokenize(s string, t ColorToken) string
- type BaseWidget
- func (b *BaseWidget) Contains(x, y int) bool
- func (b *BaseWidget) GetManager() (ui *UIManager)
- func (b *BaseWidget) GetPosition() (x, y int)
- func (b *BaseWidget) GetRenderPriority() (prio RenderPriority)
- func (b *BaseWidget) GetSize() (width, height int)
- func (b *BaseWidget) GetVisible() (visible bool)
- func (b *BaseWidget) OffsetPosition(x, y int)
- func (b *BaseWidget) OnHoverEnd(callback func())
- func (b *BaseWidget) OnHoverStart(callback func())
- func (b *BaseWidget) OnMouseMove(x, y int)
- func (b *BaseWidget) SetPosition(x, y int)
- func (b *BaseWidget) SetRenderPriority(prio RenderPriority)
- func (b *BaseWidget) SetVisible(visible bool)
- type Button
- func (v *Button) Activate()
- func (v *Button) Advance(_ float64) error
- func (v *Button) GetEnabled() bool
- func (v *Button) GetPressed() bool
- func (v *Button) GetToggled() bool
- func (v *Button) OnActivated(callback func())
- func (v *Button) Render(target d2interface.Surface)
- func (v *Button) SetEnabled(enabled bool)
- func (v *Button) SetPosition(x, y int)
- func (v *Button) SetPressed(pressed bool)
- func (v *Button) SetTooltip(t *Tooltip)
- func (v *Button) SetVisible(visible bool)
- func (v *Button) Toggle()
- type ButtonLayout
- type ButtonType
- type Checkbox
- func (v *Checkbox) Activate()
- func (v *Checkbox) Advance(_ float64) error
- func (v *Checkbox) GetCheckState() bool
- func (v *Checkbox) GetEnabled() bool
- func (v *Checkbox) GetPressed() bool
- func (v *Checkbox) OnActivated(callback func())
- func (v *Checkbox) Render(target d2interface.Surface)
- func (v *Checkbox) SetCheckState(checkState bool)
- func (v *Checkbox) SetEnabled(enabled bool)
- func (v *Checkbox) SetPressed(_ bool)
- type ClickableWidget
- type ColorToken
- type CursorButton
- type CustomWidget
- type Drawable
- type HorizontalAlign
- type Label
- type LabelButton
- func (b *LabelButton) Activate()
- func (b *LabelButton) Advance(_ float64) error
- func (b *LabelButton) GetEnabled() bool
- func (b *LabelButton) GetPosition() (x, y int)
- func (b *LabelButton) GetPressed() bool
- func (b *LabelButton) GetSize() (x, y int)
- func (b *LabelButton) OnActivated(cb func())
- func (b *LabelButton) Render(target d2interface.Surface)
- func (b *LabelButton) SetColors(normColor, hoverColor color.Color)
- func (b *LabelButton) SetEnabled(_ bool)
- func (b *LabelButton) SetPressed(_ bool)
- func (b *LabelButton) SetText(text string)
- type RenderPriority
- type Scrollbar
- func (v *Scrollbar) Activate()
- func (v *Scrollbar) Advance(elapsed float64) error
- func (v *Scrollbar) GetCurrentOffset() int
- func (v *Scrollbar) GetEnabled() bool
- func (v *Scrollbar) GetLastDirChange() int
- func (v *Scrollbar) GetMaxOffset() int
- func (v *Scrollbar) GetPressed() bool
- func (v *Scrollbar) GetSize() (width, height int)
- func (v *Scrollbar) OnActivated(callback func())
- func (v *Scrollbar) Render(target d2interface.Surface)
- func (v *Scrollbar) SetCurrentOffset(currentOffset int)
- func (v *Scrollbar) SetEnabled(enabled bool)
- func (v *Scrollbar) SetMaxOffset(maxOffset int)
- func (v *Scrollbar) SetPressed(_ bool)
- type Sprite
- func (s *Sprite) Advance(elapsed float64) error
- func (s *Sprite) GetCurrentFrame() int
- func (s *Sprite) GetCurrentFrameSize() (width, height int)
- func (s *Sprite) GetDirection() int
- func (s *Sprite) GetDirectionCount() int
- func (s *Sprite) GetFrameBounds() (width, height int)
- func (s *Sprite) GetFrameCount() int
- func (s *Sprite) GetFrameSize(frameIndex int) (x, y int, err error)
- func (s *Sprite) GetSize() (width, height int)
- func (s *Sprite) GetSurface() d2interface.Surface
- func (s *Sprite) IsOnFirstFrame() bool
- func (s *Sprite) IsOnLastFrame() bool
- func (s *Sprite) Pause()
- func (s *Sprite) PlayBackward()
- func (s *Sprite) PlayForward()
- func (s *Sprite) Render(target d2interface.Surface)
- func (s *Sprite) RenderSection(sfc d2interface.Surface, bound image.Rectangle)
- func (s *Sprite) RenderSegmented(target d2interface.Surface, segmentsX, segmentsY, frameOffset int)
- func (s *Sprite) Rewind()
- func (s *Sprite) SetColorMod(c color.Color)
- func (s *Sprite) SetCurrentFrame(frameIndex int) error
- func (s *Sprite) SetDirection(directionIndex int) error
- func (s *Sprite) SetEffect(e d2enum.DrawEffect)
- func (s *Sprite) SetPlayLength(playLength float64)
- func (s *Sprite) SetPlayLoop(loop bool)
- type SwitchableButton
- func (sbtn *SwitchableButton) Activate()
- func (sbtn *SwitchableButton) Advance(_ float64) error
- func (sbtn *SwitchableButton) Deactivate()
- func (sbtn *SwitchableButton) GetEnabled() bool
- func (sbtn *SwitchableButton) GetSize() (x, y int)
- func (sbtn *SwitchableButton) OnActivated(cb func())
- func (sbtn *SwitchableButton) OnDeactivated(cb func())
- func (sbtn *SwitchableButton) Render(target d2interface.Surface)
- func (sbtn *SwitchableButton) SetActiveTooltip(tooltip *Tooltip)
- func (sbtn *SwitchableButton) SetDisabledColor(color uint32)
- func (sbtn *SwitchableButton) SetEnabled(enabled bool)
- func (sbtn *SwitchableButton) SetInactiveTooltip(tooltip *Tooltip)
- func (sbtn *SwitchableButton) SetPosition(x, y int)
- func (sbtn *SwitchableButton) SetState(state bool)
- func (sbtn *SwitchableButton) SetVisible(visible bool)
- type TextBox
- func (v *TextBox) Activate()
- func (v *TextBox) Advance(_ float64) error
- func (v *TextBox) GetEnabled() bool
- func (v *TextBox) GetPressed() bool
- func (v *TextBox) GetSize() (width, height int)
- func (v *TextBox) GetText() string
- func (v *TextBox) OnActivated(_ func())
- func (v *TextBox) OnKeyChars(event d2interface.KeyCharsEvent) bool
- func (v *TextBox) OnKeyRepeat(event d2interface.KeyEvent) bool
- func (v *TextBox) Render(target d2interface.Surface)
- func (v *TextBox) SetEnabled(enabled bool)
- func (v *TextBox) SetFilter(filter string)
- func (v *TextBox) SetNumberOnly(max int)
- func (v *TextBox) SetPosition(x, y int)
- func (v *TextBox) SetPressed(_ bool)
- func (v *TextBox) SetText(newText string)
- func (v *TextBox) Update()
- type Tooltip
- type UIFrame
- type UIManager
- func (ui *UIManager) Advance(elapsed float64)
- func (ui *UIManager) CursorButtonPressed(button CursorButton) bool
- func (ui *UIManager) CursorPosition() (x, y int)
- func (ui *UIManager) Initialize()
- func (ui *UIManager) NewButton(buttonType ButtonType, text string) *Button
- func (ui *UIManager) NewCheckbox(checkState bool) *Checkbox
- func (ui *UIManager) NewCustomWidget(renderFunc func(target d2interface.Surface), width, height int) *CustomWidget
- func (ui *UIManager) NewCustomWidgetCached(renderFunc func(target d2interface.Surface), width, height int) *CustomWidget
- func (ui *UIManager) NewDefaultButton(path string, frame int) *Button
- func (ui *UIManager) NewLabel(fontPath, palettePath string) *Label
- func (ui *UIManager) NewLabelButton(font, palette string) *LabelButton
- func (ui *UIManager) NewScrollbar(x, y, height int) *Scrollbar
- func (ui *UIManager) NewSprite(animationPath, palettePath string) (*Sprite, error)
- func (ui *UIManager) NewSwitchableButton(active, inactive *Button, state bool) *SwitchableButton
- func (ui *UIManager) NewTextbox() *TextBox
- func (ui *UIManager) NewTooltip(font, palette string, originX tooltipXOrigin, originY tooltipYOrigin) *Tooltip
- func (ui *UIManager) NewUIFrame(frameOrientation frameOrientation) *UIFrame
- func (ui *UIManager) NewWidgetGroup(priority RenderPriority) *WidgetGroup
- func (ui *UIManager) OnMouseButtonDown(event d2interface.MouseEvent) bool
- func (ui *UIManager) OnMouseButtonUp(event d2interface.MouseEvent) bool
- func (ui *UIManager) OnMouseMove(event d2interface.MouseMoveEvent) bool
- func (ui *UIManager) Render(target d2interface.Surface)
- func (ui *UIManager) Renderer() d2interface.Renderer
- func (ui *UIManager) Reset()
- type Widget
- type WidgetGroup
- func (wg *WidgetGroup) AddWidget(w Widget)
- func (wg *WidgetGroup) Advance(elapsed float64) error
- func (wg *WidgetGroup) OffsetPosition(x, y int)
- func (wg *WidgetGroup) OnMouseMove(x, y int)
- func (wg *WidgetGroup) Render(target d2interface.Surface)
- func (wg *WidgetGroup) SetEnabled(enabled bool)
- func (wg *WidgetGroup) SetVisible(visible bool)
Constants ¶
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
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
const ( FrameLeft frameOrientation = iota FrameRight )
Frame orientations
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 )
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) GetPressed ¶
GetPressed returns the pressed state of the button
func (*Button) GetToggled ¶
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 ¶
SetEnabled sets the enabled state
func (*Button) SetPosition ¶
SetPosition sets the position of the widget
func (*Button) SetPressed ¶
SetPressed sets the pressed state of the button
func (*Button) SetTooltip ¶
SetTooltip adds a tooltip to the button
func (*Button) SetVisible ¶
SetVisible sets the pressed 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 Checkbox ¶
type Checkbox struct { *BaseWidget Image d2interface.Surface // contains filtered or unexported fields }
Checkbox represents a checkbox UI element
func (*Checkbox) GetCheckState ¶
GetCheckState returns the check state of the checkbox
func (*Checkbox) GetEnabled ¶
GetEnabled returns the enabled state of the checkbox
func (*Checkbox) GetPressed ¶
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 ¶
SetCheckState sets the check state of the checkbox
func (*Checkbox) SetEnabled ¶
SetEnabled sets the enabled state of the checkbox
func (*Checkbox) SetPressed ¶
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) GetTextMetrics ¶
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 ¶
SetBackgroundColor sets the background highlight color
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
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) GetCurrentOffset ¶
GetCurrentOffset gets the current max offset of the scrollbar
func (*Scrollbar) GetEnabled ¶
GetEnabled returns whether or not the scrollbar is enabled
func (*Scrollbar) GetLastDirChange ¶
GetLastDirChange get the last direction change
func (*Scrollbar) GetMaxOffset ¶
GetMaxOffset returns the max offset
func (*Scrollbar) GetPressed ¶
GetPressed is not used by the scrollbar, but is present to satisfy the ui widget interface
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 ¶
SetCurrentOffset sets the scrollbar's current offset
func (*Scrollbar) SetEnabled ¶
SetEnabled sets the enabled state
func (*Scrollbar) SetMaxOffset ¶
SetMaxOffset sets the maximum offset of the scrollbar
func (*Scrollbar) SetPressed ¶
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) GetCurrentFrame ¶
GetCurrentFrame gets index of current frame in animation
func (*Sprite) GetCurrentFrameSize ¶
GetCurrentFrameSize gets the Size(width, height) of the current frame.
func (*Sprite) GetDirection ¶
GetDirection get the current animation direction
func (*Sprite) GetDirectionCount ¶
GetDirectionCount gets the number of animation direction
func (*Sprite) GetFrameBounds ¶
GetFrameBounds gets maximum Size(width, height) of all frame.
func (*Sprite) GetFrameCount ¶
GetFrameCount gets number of frames in animation
func (*Sprite) GetFrameSize ¶
GetFrameSize gets the Size(width, height) of a indexed frame.
func (*Sprite) GetSurface ¶
func (s *Sprite) GetSurface() d2interface.Surface
GetSurface returns the surface of the sprite at the given frame
func (*Sprite) IsOnFirstFrame ¶
IsOnFirstFrame gets if the animation on its first frame
func (*Sprite) IsOnLastFrame ¶
IsOnLastFrame gets if the animation on its last frame
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) SetColorMod ¶
SetColorMod sets the color modifier
func (*Sprite) SetCurrentFrame ¶
SetCurrentFrame sets animation at a specific frame
func (*Sprite) SetDirection ¶
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 ¶
SetPlayLength sets the play length of the sprite animation
func (*Sprite) SetPlayLoop ¶
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) GetEnabled ¶
GetEnabled returns the enabled state of the text box
func (*TextBox) GetPressed ¶
GetPressed does nothing for text boxes
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 ¶
SetEnabled sets the enabled state of the text box
func (*TextBox) SetNumberOnly ¶
SetNumberOnly sets text box to support only numeric values
func (*TextBox) SetPosition ¶
SetPosition sets the position of the text box
func (*TextBox) SetPressed ¶
SetPressed does nothing for text boxes
type Tooltip ¶
type Tooltip struct { *BaseWidget // contains filtered or unexported fields }
Tooltip contains a label containing text with a transparent, black background
func (*Tooltip) Render ¶
func (t *Tooltip) Render(target d2interface.Surface)
Render draws the tooltip
func (*Tooltip) SetBoxEnabled ¶
SetBoxEnabled determines whether a black box is drawn around the text
func (*Tooltip) SetTextLines ¶
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) GetFrameBounds ¶
GetFrameBounds returns the maximum width and height of all frames in sprite.
func (*UIFrame) GetFrameCount ¶
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 ¶
func NewUIManager( asset *d2asset.AssetManager, renderer d2interface.Renderer, input d2interface.InputManager, l d2util.LogLevel, audio d2interface.AudioProvider, ) *UIManager
NewUIManager creates a UIManager instance with the given input and audio provider
func (*UIManager) CursorButtonPressed ¶
func (ui *UIManager) CursorButtonPressed(button CursorButton) bool
CursorButtonPressed determines if the specified button has been pressed
func (*UIManager) CursorPosition ¶
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 ¶
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 ¶
NewDefaultButton creates a new button with default settings
func (*UIManager) NewLabelButton ¶
func (ui *UIManager) NewLabelButton(font, palette string) *LabelButton
NewLabelButton creates a label-button
func (*UIManager) NewScrollbar ¶
NewScrollbar creates a scrollbar instance
func (*UIManager) NewSwitchableButton ¶
func (ui *UIManager) NewSwitchableButton(active, inactive *Button, state bool) *SwitchableButton
NewSwitchableButton creates new switchable button
func (*UIManager) NewTextbox ¶
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 ¶
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
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