widgets

package
v0.0.0-...-328a337 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2020 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseButton

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

func NewBaseButton

func NewBaseButton(ID string, width int, height int, handler func(event events.IEvent) error) *BaseButton

func (*BaseButton) Draw

func (b *BaseButton) Draw(screen *ebiten.Image) error

func (*BaseButton) HandleEvent

func (b *BaseButton) HandleEvent(event events.IEvent) error

type BaseWidget

type BaseWidget struct {
	ID string

	// Location of top left of widget.
	// This is always relative to the parent widget.
	X      float64
	Y      float64
	Width  int
	Height int

	// widget disabled (and shouldn't be rendered.... OR.... greyed out?
	Disabled bool

	// direct parent of window.... hack to sort out mouse positioning...
	TopLevel bool
	// contains filtered or unexported fields
}

BaseWidget is the common element of ALL disable items. Widgets, buttons, panels etc. Should only handle some basic items like location, width, height and possibly events.

func NewBaseWidget

func NewBaseWidget(ID string, width int, height int, handler func(event events.IEvent) error) *BaseWidget

func (*BaseWidget) AddParentPanel

func (b *BaseWidget) AddParentPanel(parentPanel IPanel) error

func (*BaseWidget) CheckMouseEventCoords

func (b *BaseWidget) CheckMouseEventCoords(event events.IEvent) (bool, error)

func (*BaseWidget) ContainsCoords

func (b *BaseWidget) ContainsCoords(x float64, y float64) bool

ContainsCoords determines if co-ordinates... co-ords passed are GLOBAL and need to be converted.

func (*BaseWidget) Draw

func (b *BaseWidget) Draw(screen *ebiten.Image) error

func (*BaseWidget) GenerateLocalCoordMouseEvent

func (b *BaseWidget) GenerateLocalCoordMouseEvent(incomingEvent events.MouseEvent) events.MouseEvent

GenerateLocalCoordMouseEvent takes an incoming MouseEvent and converts the X,Y co-ordinates to something relative to the current widget. The incoming MouseEvent co-ords are relative to the parent.

func (*BaseWidget) GetData

func (b *BaseWidget) GetData() (interface{}, error)

func (*BaseWidget) GetID

func (b *BaseWidget) GetID() string

func (*BaseWidget) GetSize

func (b *BaseWidget) GetSize() (float64, float64)

func (*BaseWidget) GetXY

func (b *BaseWidget) GetXY() (float64, float64)

func (*BaseWidget) GlobalToLocalCoords

func (b *BaseWidget) GlobalToLocalCoords(x float64, y float64) (float64, float64)

GlobalToLocalCoords takes global co-ords and modifies it to local co-ords. It figures this out by keeping a global offset to base off. It gets the global offset by asking its parents for offset. The parent asks its parent and so on. THINK this should work. Remember LOCAL co-ords are really based off the parents co-ords... as in a widgets x,y is based off the parents 0,0.... man I need to explain that more clearly.

func (*BaseWidget) SetXY

func (b *BaseWidget) SetXY(x float64, y float64) error

type Canvas

type Canvas struct {
	BaseWidget
}

Canvas is just an image that will be updated outside of the UI framework. eg client could play a video to it (frame by frame)... etc. Just to testing out/playing

func NewCanvas

func NewCanvas(ID string, width int, height int) *Canvas

func (*Canvas) Draw

func (b *Canvas) Draw(screen *ebiten.Image) error

do we event need this?

func (*Canvas) GetUnderlyingImage

func (b *Canvas) GetUnderlyingImage() *ebiten.Image

func (*Canvas) HandleEvent

func (b *Canvas) HandleEvent(event events.IEvent) error

type CheckBox

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

func NewCheckBox

func NewCheckBox(ID string, text string, checkedImage string, uncheckedImage string, handler func(event events.IEvent) error) *CheckBox

func (*CheckBox) Draw

func (b *CheckBox) Draw(screen *ebiten.Image) error

func (*CheckBox) GetData

func (b *CheckBox) GetData() (interface{}, error)

func (*CheckBox) HandleEvent

func (b *CheckBox) HandleEvent(event events.IEvent) error

type EmptySpace

type EmptySpace struct {
	BaseWidget
}

EmptySpace lame way to put spaces in panels..

func NewEmptySpace

func NewEmptySpace(ID string, width int, height int) *EmptySpace

func (*EmptySpace) Draw

func (b *EmptySpace) Draw(screen *ebiten.Image) error

do we event need this?

func (*EmptySpace) HandleEvent

func (b *EmptySpace) HandleEvent(event events.IEvent) error

type HPanel

type HPanel struct {
	Panel

	// X offset for next widget to be added.
	XLoc float64
}

HPanel stacks internal objects horizonally... left to right.

func NewHPanel

func NewHPanel(ID string, colour *color.RGBA) *HPanel

func NewHPanelWithSize

func NewHPanelWithSize(ID string, width int, height int, colour *color.RGBA) *HPanel

func (*HPanel) AddWidget

func (p *HPanel) AddWidget(w IWidget) error

AddWidget adds a widget to the panel, but each widget is to the right of the previous one.

func (*HPanel) ClearWidgets

func (p *HPanel) ClearWidgets() error

type IButton

type IButton interface {
	HandleEvent(event events.IEvent) error
	Draw(screen *ebiten.Image) error
}

type IPanel

type IPanel interface {
	AddWidget(w IWidget) error
	Draw(screen *ebiten.Image) error
	HandleEvent(event events.IEvent) error
	SetTopLevel(bool)
	SetSize(width int, height int) error
	GetSize() (float64, float64)
	ContainsCoords(x float64, y float64) bool // contains co-ords... co-ords are based on immediate parents location/size.
	ListWidgets() []IWidget
	ListPanels() []Panel
	GetCoords() (float64, float64)
	GetDeltaOffset() (bool, float64, float64)
	GlobalToLocalCoords(x float64, y float64) (float64, float64)
	AddParentPanel(parentPanel IPanel) error
	ClearWidgets() error
}

type IWidget

type IWidget interface {
	Draw(screen *ebiten.Image) error
	HandleEvent(event events.IEvent) error
	GetData() (interface{}, error)            // absolutely HATE the empty interface, but this will need to be extremely generic I suppose?
	ContainsCoords(x float64, y float64) bool // contains co-ords... co-ords are based on immediate parents location/size.
	GlobalToLocalCoords(x float64, y float64) (float64, float64)
	AddParentPanel(parentPanel IPanel) error
	SetXY(x float64, y float64) error
	GetXY() (float64, float64)
	GetSize() (float64, float64)
	GetID() string
}

IWidget defines what actions can be performed on a widget. Hate using the I* notation... but will do for now.

type ImageButton

type ImageButton struct {
	BaseButton
	// contains filtered or unexported fields
}

func NewImageButton

func NewImageButton(ID string, pressedImageName string, nonPressedImageName string, handler func(event events.IEvent) error) *ImageButton

func (*ImageButton) Draw

func (b *ImageButton) Draw(screen *ebiten.Image) error

type Label

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

func NewLabel

func NewLabel(ID string, text string, width int, height int, backgroundColour *color.RGBA, fontInfo *common.Font) *Label

func (*Label) Draw

func (t *Label) Draw(screen *ebiten.Image) error

func (*Label) GetData

func (t *Label) GetData() (interface{}, error)

func (*Label) HandleEvent

func (t *Label) HandleEvent(event events.IEvent) error

type Panel

type Panel struct {
	BaseWidget

	// DynamicSize is for when we based sizes off window/panels etc. ie everything is
	// proportional as opposed to absolute.
	DynamicSize bool
	// contains filtered or unexported fields
}

Panel has a position, width and height. Panels contain other widgets (and also other panels).

func NewPanel

func NewPanel(ID string, colour *color.RGBA, borderColour *color.RGBA) *Panel

func (*Panel) AddWidget

func (p *Panel) AddWidget(w IWidget) error

AddWidget adds a widget to a panel and subscribes the widget to a number of events (generated from the panel)

func (*Panel) ClearWidgets

func (p *Panel) ClearWidgets() error

func (*Panel) Draw

func (p *Panel) Draw(screen *ebiten.Image) error

Draw renders all the widgets inside the panel (and the panel itself.. .if there is anything to it?)

func (*Panel) GetCoords

func (p *Panel) GetCoords() (float64, float64)

func (*Panel) GetDeltaOffset

func (p *Panel) GetDeltaOffset() (bool, float64, float64)

func (*Panel) HandleEvent

func (p *Panel) HandleEvent(event events.IEvent) error

HandlEvent returns true if related to this panel. eg, mouse was in its borders etc. Keyboard... well, will accept anyway (need to figure out focusing for that).

func (*Panel) HandleKeyboardEvent

func (p *Panel) HandleKeyboardEvent(event events.IEvent) (bool, error)

func (*Panel) HandleMouseEvent

func (p *Panel) HandleMouseEvent(event events.IEvent) (bool, error)

func (*Panel) ListPanels

func (p *Panel) ListPanels() []Panel

func (*Panel) ListWidgets

func (p *Panel) ListWidgets() []IWidget

func (*Panel) SetSize

func (p *Panel) SetSize(width int, height int) error

func (*Panel) SetTopLevel

func (p *Panel) SetTopLevel(topLevel bool)

type RadioButtonGroup

type RadioButtonGroup struct {
	Panel
	// contains filtered or unexported fields
}

func NewRadioButtonGroup

func NewRadioButtonGroup(ID string, vertical bool, border bool, handler func(event events.IEvent) error) *RadioButtonGroup

func (*RadioButtonGroup) AddRadioButton

func (rb *RadioButtonGroup) AddRadioButton(buttonText string) error

AddRadioButton adds a new radio button to the radio button group. temporarily just trying the checkbox here.

func (*RadioButtonGroup) HandleEvent

func (rb *RadioButtonGroup) HandleEvent(event events.IEvent) error

type TextButton

type TextButton struct {
	BaseButton

	Rect image.Rectangle
	// contains filtered or unexported fields
}

TextButton is a button that just has a background colour, text and text colour.

func NewTextButton

func NewTextButton(ID string, text string, useImageforSize bool, width int, height int,
	nonPressedBackgroundColour *color.RGBA,
	pressedBackgroundColour *color.RGBA, fontInfo *common.Font, handler func(event events.IEvent) error) *TextButton

NewTextButton. Button will have specified dimensions of width and height, useImageForSize is true. Then take the size from the contained text

func (*TextButton) Draw

func (b *TextButton) Draw(screen *ebiten.Image) error

type TextInput

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

func NewTextInput

func NewTextInput(ID string, width int, height int, backgroundColour *color.RGBA, fontInfo *common.Font, handler func(event events.IEvent) error) *TextInput

func (*TextInput) Draw

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

func (*TextInput) GetData

func (t *TextInput) GetData() (interface{}, error)

func (*TextInput) HandleEvent

func (t *TextInput) HandleEvent(event events.IEvent) error

type Toolbar

type Toolbar struct {
	HPanel

	// X offset for next widget to be added.
	XLoc float64
}

Toolbar stacks internal objects horizonally... left to right.

func NewToolBar

func NewToolBar(ID string, colour *color.RGBA) *Toolbar

func (*Toolbar) AddToolBarItem

func (p *Toolbar) AddToolBarItem(i IWidget) error

AddToolBarItem add toolbaritem. Basically just an alias to HPanel.AddWidget for now... but that could change.

type ToolbarItem

type ToolbarItem struct {
	ImageButton
}

Toolbar stacks internal objects horizonally... left to right.

func NewToolbarItem

func NewToolbarItem(ID string, handler func(event events.IEvent) error) *ToolbarItem

type VPanel

type VPanel struct {
	Panel

	// Y offset for next widget to be added.
	YLoc float64
	// contains filtered or unexported fields
}

VPanel stacks internal objects vertically.... starting at top and going down... so umm reverse panel :)

func NewVPanel

func NewVPanel(ID string, colour *color.RGBA) *VPanel

func NewVPanelWithSize

func NewVPanelWithSize(ID string, width int, height int, colour *color.RGBA) *VPanel

func (*VPanel) AddWidget

func (p *VPanel) AddWidget(w IWidget) error

AddWidget adds a widget to the panel, but each widget is below the next one.

func (*VPanel) ClearWidgets

func (p *VPanel) ClearWidgets() error

Jump to

Keyboard shortcuts

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