mtk

package module
v0.0.0-...-756fa0c Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: GPL-2.0 Imports: 17 Imported by: 5

README

Introduction

MTK(Mural Toolkit) is a simple widget toolkit for creating graphical user interfaces written in Go with Pixel and Beep libraries.

The toolkit provides basic UI elements(buttons, text boxes, switches, lists, animations, etc.), simple audio handling and automatic scaling of UI elements.

Originally created as a part of Mural GUI.

MTK highly relies on Pixel library, make sure to check Pixel wiki first.

Dependencies

Basic dependencies are OpenGL development libraries, and some audio development libraries.

Linux

On Fedora-like distribution install: go libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel mesa-libGL-devel libXi-devel libXxf86vm-devel alsa-lib-devel.

On other distributions, you need to install the equivalence of these packages.

macOS

Install Go and Xcode or Command Line Tools for Xcode.

Windows

Install Go

Examples

All UI elements are automatically scaled to size specified in Pixel WindowConfig.

Create window:

// Create Pixel window configuration.
cfg := pixelgl.WindowConfig{
       Title:  "MTK window",
       Bounds: pixel.R(0, 0, 1600, 900),
}
// Create MTK warpper for Pixel window.
win, err := mtk.NewWindow(cfg)
if err != nil {
       panic(fmt.Errorf("Unable to create MTK window: %v", err))
}

Create button:

// Specify button parameters.
params := mtk.Params{
	Size:      mtk.SizeBig,
	FontSize:  mtk.SizeMedium,
	Shape:     mtk.ShapeRectangle,
	MainColor: colornames.Red,
}
// Create button.
button := mtk.NewButton(params)
// Set label and on-hover info.
button.SetLabel("Button")
button.SetInfo("Button info")
// Set some function on button click event.
button.SetOnClickFunc(onButtonClickedFunc)

Draw button in window:

for !win.Closed() {
	// Clear window.
	win.Clear(colornames.Black)
	// Draw button.
	buttonPos := win.Bounds().Center()
	button.Draw(win, mtk.Matrix().Moved(buttonPos))
	// Update.
	win.Update()
	button.Update(win)
}

Check example package for more detailed examples.

Documentation

Source code documentation can be easily browsed with go doc command.

Contributing

You are welcome to contribute to project development.

If you looking for things to do, then check TODO file or contact maintainer(ds@isangeles.dev).

When you find something to do, create new branch for your feature. After you finish, open pull request to merge your changes with master branch.

Contact

License

Copyright 2018-2024 Dariusz Sikora <ds@isangeles.dev>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Documentation

Overview

Toolkit package for Mural GUI.

Index

Constants

View Source
const (
	// Sizes.
	SizeMini Size = iota
	SizeSmall
	SizeMedium
	SizeBig
	SizeHuge
	// Shapes.
	ShapeRectangle Shape = iota
	ShapeSquare
	// Aligns
	AlignCenter Align = iota
	AlignRight
	AlignLeft
)

Variables

This section is empty.

Functions

func Atlas

func Atlas(f *font.Face) *text.Atlas

Atlas returns atlas for UI text with specified font.

func BottomOf

func BottomOf(drawArea pixel.Rect, size pixel.Vec, offset float64) pixel.Vec

BottomOf returns position of rect with specified size at the bottom of speicified draw area, width specified offset value.

func ConvSize

func ConvSize(size1080p float64) float64

Size converts specified default size value(for 1080p) to value for current resolution.

func ConvVec

func ConvVec(vec1080p pixel.Vec) pixel.Vec

ConvVec converts specified default Pixel XY vector values(for 1080p) to vector with values for current resolution.

func DisBL

func DisBL(rect pixel.Rect, scale float64) pixel.Vec

DisBL returns bottom left position of specified rectangle multiplied by specified value.

func DisBR

func DisBR(rect pixel.Rect, scale float64) pixel.Vec

DisBR returns bottom right position of specified rectangle multiplied by specified value.

func DisTL

func DisTL(rect pixel.Rect, scale float64) pixel.Vec

DisTL returns top left position of specified rectangle multiplied by specified value.

func DisTR

func DisTR(rect pixel.Rect, scale float64) pixel.Vec

DisTR returns top right position of specified rectangle multiplied by specified value.

func DrawPosBC

func DrawPosBC(bg pixel.Rect, size pixel.Vec) pixel.Vec

DrawPosBC returns bottom center draw position(center) on specified background for object with specified size.

func DrawPosBL

func DrawPosBL(bg pixel.Rect, size pixel.Vec) pixel.Vec

DrawPosBL returns bottom left draw position(center) on specified background for object with specified size.

func DrawPosBR

func DrawPosBR(bg pixel.Rect, size pixel.Vec) pixel.Vec

DrawPosBR returns bottom right draw position(center) on specified background for object with specified size.

func DrawPosCL

func DrawPosCL(bg pixel.Rect, size pixel.Vec) pixel.Vec

DrawPosCL returns center left draw position(center) on specified background for object with specified size.

func DrawPosCR

func DrawPosCR(bg pixel.Rect, size pixel.Vec) pixel.Vec

DrawPosCR returns center right draw position(center) on specified background for object with specified size.

func DrawPosTC

func DrawPosTC(bg pixel.Rect, size pixel.Vec) pixel.Vec

DrawPosTC returns top center draw position(center) on specified background for object with specified size.

func DrawPosTL

func DrawPosTL(bg pixel.Rect, size pixel.Vec) pixel.Vec

DrawPosTR returns top left position for draw specifed object with specified size.

func DrawPosTR

func DrawPosTR(bg pixel.Rect, size pixel.Vec) pixel.Vec

DrawPosTR returns top right draw position(center) on specified background for object with specified size.

func DrawRectangle

func DrawRectangle(t pixel.Target, drawArea pixel.Rect, color color.Color)

DrawRectangle draw rectangle on specified target with specified draw area(position and size) and color.

func InitAudio

func InitAudio(format beep.Format) error

InitAudio initializes the system audio with specified format. It need to be called before using the audio player struct.

func LeftOf

func LeftOf(drawArea pixel.Rect, size pixel.Vec, offset float64) pixel.Vec

LeftOf returns position for rect with specified size at the left side of specified draw area, with specified offset value.

func MainFont

func MainFont(s Size) font.Face

MainFont returns main font in specified size from data package.

func Matrix

func Matrix() pixel.Matrix

Matrix return scaled identity matrix.

func MatrixToDrawArea

func MatrixToDrawArea(matrix pixel.Matrix, rectSize pixel.Vec) (drawArea pixel.Rect)

MatrixToDrawArea calculates draw area based on specified matrix and rectangle.

func MoveBC

func MoveBC(bgSize, obSize pixel.Vec) pixel.Vec

MoveBC returns move vector from center of background with specified size to bottom center point draw position(center) for specified size.

func MoveBL

func MoveBL(bgSize, obSize pixel.Vec) pixel.Vec

MoveBL returns move vector from center of background with specified size to bottom left point draw position(center) for specified size.

func MoveBR

func MoveBR(bgSize, obSize pixel.Vec) pixel.Vec

MoveBR returns move vector from center of background with specified size to bottom right point draw position(center) for specified size.

func MoveTC

func MoveTC(bgSize, obSize pixel.Vec) pixel.Vec

MoveTC returns move vector from center of background with specified size to top center point draw position(center) for specified size.

func MoveTL

func MoveTL(bgSize, obSize pixel.Vec) pixel.Vec

MoveTL returns move vector from center of background with specified size to top left point draw position(center) for specified size.

func MoveTR

func MoveTR(bgSize, obSize pixel.Vec) pixel.Vec

MoveTR returns move vector from center of background with specified size to top right point draw position(center) for specified size.

func PosBL

func PosBL(size pixel.Rect, pos pixel.Vec) pixel.Vec

PosBL returns bottom left point for specified position of specified rectangle.

func PosBR

func PosBR(size pixel.Rect, pos pixel.Vec) pixel.Vec

PosBR returns bottom right point for specified position of specified rectangle.

func PosTL

func PosTL(size pixel.Rect, pos pixel.Vec) pixel.Vec

PosTL returns top left point for specified position of specified rectangle.

func PosTR

func PosTR(size, pos pixel.Vec) pixel.Vec

PosTR returns top right point for specified position of specified rectangle.

func Range

func Range(from, to pixel.Vec) float64

Range returns range between two specified positions.

func RightOf

func RightOf(drawArea pixel.Rect, size pixel.Vec, offset float64) pixel.Vec

ReightOf returns position for rect with specified size at the right side of specified draw area, with specified offset value.

func Scale

func Scale() float64

Scale return scale value for current resolution.

func SetButtonClickSound

func SetButtonClickSound(s *beep.Buffer)

SetButtonClickSound sets specified audio buffer as on-click audio effect for all buttons.

func SetMainFont

func SetMainFont(font *truetype.Font)

Sets specified truetype font as current main font of the interface.

func SlotCopy

func SlotCopy(slotA, slotB *Slot)

SlotCopy copies content from slot A to slot B(overwrites current content).

func SlotSwitch

func SlotSwitch(slotA, slotB *Slot)

SlotSwitch transfers all contant of slot A (value, icon, label, info) to slot B and vice versa.

func SplitSubN

func SplitSubN(s string, n int) []string

Splits string to chunks with n as max chunk width. Author: mozey(@stackoverflow).

func TopOf

func TopOf(drawArea pixel.Rect, size pixel.Vec, offset float64) pixel.Vec

TopOf returns position for rect with specified size at the top of specified draw area, with specified offset value.

Types

type Align

type Align int

Type for aligns. Directions: center(0), right(1), left(2)

type Animation

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

Struct for animations.

func NewAnimation

func NewAnimation(frames []*pixel.Sprite, fps int) *Animation

NewAnimation creates new animation with specified frames and FPS value. Animation is looping by default.

func (*Animation) Draw

func (anim *Animation) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws current animation frame.

func (*Animation) DrawArea

func (anim *Animation) DrawArea() pixel.Rect

DrawArea returns current frame draw area.

func (*Animation) Finished

func (anim *Animation) Finished() bool

Finished checks whether animation is finished, i.e. current frame is last frame of animation.

func (*Animation) Loop

func (anim *Animation) Loop(loop bool)

Loop toggles animation looping.

func (*Animation) Restart

func (anim *Animation) Restart()

Restarts restarts animation.

func (*Animation) SetCurrentFrameID

func (anim *Animation) SetCurrentFrameID(id int)

SetCurrentFrameID sets frame with specified ID as current draw frame of animation. If specified index is bigger than maximal frame index then first index is set, if smaller than minimal then last index is set.

func (*Animation) SetFPS

func (anim *Animation) SetFPS(fps int)

SetFPS sets number of frames per second.

func (*Animation) Update

func (anim *Animation) Update(win *Window)

Update updates animation.

type AudioPlayer

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

Struct for audio player.

func Audio

func Audio() *AudioPlayer

Audio returns toolkit audio player. Returned audio player will not be operational if the audio was not initialized before with InitAudio function.

func NewAudioPlayer

func NewAudioPlayer() *AudioPlayer

NewAudioPlayer creates new audio player.

func (*AudioPlayer) AddAudio

func (ap *AudioPlayer) AddAudio(ab *beep.Buffer) error

AddAudio adds specified audio stream to the current playlist.

func (*AudioPlayer) Clear

func (ap *AudioPlayer) Clear()

Clear clears music playlist.

func (*AudioPlayer) Muted

func (ap *AudioPlayer) Muted() bool

Muted checks if audio player is muted.

func (*AudioPlayer) Play

func (ap *AudioPlayer) Play(buffer *beep.Buffer)

Play starts playing specified audio stream.

func (*AudioPlayer) PlayIndex

func (ap *AudioPlayer) PlayIndex() int

PlayIndex returns index of currently playing audio buffer from the playlist.

func (*AudioPlayer) Playing

func (ap *AudioPlayer) Playing() bool

Playing checks if audio player is playing any audio buffer.

func (*AudioPlayer) Playlist

func (ap *AudioPlayer) Playlist() []*beep.Buffer

Playlist returns the audio player playlist.

func (*AudioPlayer) Reset

func (ap *AudioPlayer) Reset()

Reset stops player and moves play index to first music playlist index.

func (*AudioPlayer) ResumePlaylist

func (ap *AudioPlayer) ResumePlaylist()

ResumePlaylist starts playing audio from the playlist for current playlist ID.

func (*AudioPlayer) SetMute

func (ap *AudioPlayer) SetMute(m bool)

SetMute mutes/unmutes audio player.

func (*AudioPlayer) SetPlayIndex

func (ap *AudioPlayer) SetPlayIndex(id int)

SetPlayIndex sets specified index as current index on music playlist. If specified value is bigger than playlist lenght then first index is set, if is lower than 0 then last index is set.

func (*AudioPlayer) SetPlaylist

func (ap *AudioPlayer) SetPlaylist(playlist []*beep.Buffer)

SetPlaylist sets specified slice with audio streams as player playlist.

func (*AudioPlayer) SetVolume

func (ap *AudioPlayer) SetVolume(v float64)

SetVolume sets specified value as current audio volume value. 0 - unmodified(system volume), > 0 - lauder, < 0 quieter.

func (*AudioPlayer) Stop

func (ap *AudioPlayer) Stop()

Stop stops player.

func (*AudioPlayer) Volume

func (ap *AudioPlayer) Volume() float64

Volume returns current volume value. 0 - unmodified(system volume), > 0 - lauder, < 0 quieter.

type Button

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

Button struct for UI button.

func NewButton

func NewButton(params Params) *Button

NewButton creates new button with specified parameters.

func (*Button) Active

func (b *Button) Active(active bool)

Active toggles button active state.

func (*Button) Disabled

func (b *Button) Disabled() bool

Disabled checks whether button is disabled.

func (*Button) Draw

func (b *Button) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws button.

func (*Button) DrawArea

func (b *Button) DrawArea() pixel.Rect

DrawArea returns current button background position and size.

func (*Button) Focus

func (b *Button) Focus(focus bool)

Focus sets/removes focus from button

func (*Button) Focused

func (b *Button) Focused() bool

Focused checks whether buttons is focused.

func (*Button) SetBackground

func (b *Button) SetBackground(s *pixel.Sprite)

SetBackground sets specified sprite as button background, also removes background color.

func (*Button) SetClickSound

func (b *Button) SetClickSound(s *beep.Buffer)

SetClickSound sets specified audio buffer as on-click audio effect.

func (*Button) SetColor

func (b *Button) SetColor(c color.Color)

SetColor sets specified color as current button backgroun color.

func (*Button) SetInfo

func (b *Button) SetInfo(t string)

SetInfo sets specified text as content of button info window.

func (*Button) SetLabel

func (b *Button) SetLabel(t string)

SetLabel sets specified text as button label.

func (*Button) SetOnClickFunc

func (b *Button) SetOnClickFunc(callback func(b *Button))

SetOnClickFunc sets specified function as on-click callback function.

func (*Button) Size

func (b *Button) Size() pixel.Vec

Size returns button background size.

func (*Button) Update

func (b *Button) Update(win *Window)

Update updates button.

type CheckSlot

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

Struct for 'chackable' slots.

func NewCheckSlot

func NewCheckSlot(label string, value interface{}, bgSize pixel.Vec,
	color, checkColor color.Color) *CheckSlot

NewCheckSlot creates new item for list.

func (*CheckSlot) Check

func (cs *CheckSlot) Check(check bool)

Check toggles slot selection.

func (*CheckSlot) Checked

func (cs *CheckSlot) Checked() bool

Checked checks whether slot is checked.

func (*CheckSlot) Draw

func (cs *CheckSlot) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws slot.

func (*CheckSlot) DrawArea

func (cs *CheckSlot) DrawArea() pixel.Rect

DrawArea returns current slot draw area.

func (*CheckSlot) Label

func (cs *CheckSlot) Label() string

Label returns slot label.

func (*CheckSlot) SetOnCheckFunc

func (cs *CheckSlot) SetOnCheckFunc(f func(s *CheckSlot))

SetOnCheckFunc sets specified function as function triggered after slot was selected.

func (*CheckSlot) SetSize

func (cs *CheckSlot) SetSize(s pixel.Vec)

SetSize sets specified vector as background size.

func (*CheckSlot) Size

func (cs *CheckSlot) Size() pixel.Vec

Size returns slot background size.

func (*CheckSlot) Update

func (cs *CheckSlot) Update(win *Window)

Update updates slot.

func (*CheckSlot) Value

func (cs *CheckSlot) Value() interface{}

Value returns slot value.

type Focus

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

Focus represents user focus on UI element.

func (*Focus) Focus

func (f *Focus) Focus(e Focuser)

Focus sets focus on specified focusable element. Previously focused element(if exists) is unfocused before focusing specified one.

type Focuser

type Focuser interface {
	Focus(focus bool)
	Focused() bool
}

Interface for all 'focusable' UI elements, like buttons, switches, etc.

type InfoWindow

type InfoWindow struct {
	*Text
	// contains filtered or unexported fields
}

InfoWindow struct for small text boxes that follows mouse cursor.

func NewInfoWindow

func NewInfoWindow(params Params) *InfoWindow

NewInfoWindow creates new information window.

func (*InfoWindow) Draw

func (iw *InfoWindow) Draw(t pixel.Target)

Draw draws info window.

func (*InfoWindow) Update

func (iw *InfoWindow) Update(win *Window)

Update updates info window.

type List

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

Struct for list with 'selectable' items.

func NewList

func NewList(params Params) *List

NewList creates new list with specified parameters.

func (*List) Active

func (l *List) Active(active bool)

Active toggles list activity.

func (*List) AddItem

func (l *List) AddItem(label string, value interface{})

AddItem adds specified value with label to current list content.

func (*List) Clear

func (l *List) Clear()

Clear clears list.

func (*List) Disabled

func (l *List) Disabled() bool

Disabled checks whether list is disabled.

func (*List) Draw

func (l *List) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws list.

func (*List) DrawArea

func (l *List) DrawArea() pixel.Rect

DrawArea returns current list background position and size.

func (*List) Focus

func (l *List) Focus(focus bool)

Focus toggles focus on element.

func (*List) Focused

func (l *List) Focused() bool

Focused checks whether list is focused.

func (*List) InsertItems

func (l *List) InsertItems(items map[string]interface{})

InsertItems sets specified values with labels as current list content.

func (*List) SelectedValue

func (l *List) SelectedValue() interface{}

SelectedValue returns value of currently selected list item.

func (*List) SetDownButtonBackground

func (l *List) SetDownButtonBackground(s *pixel.Sprite)

SetDownButtonBackground sets specified sprite as scroll down button background.

func (*List) SetOnItemSelectFunc

func (l *List) SetOnItemSelectFunc(f func(i *CheckSlot))

SetOnItemSelectFunc sets specified function as function triggered after one of list items was selected.

func (*List) SetStartIndex

func (l *List) SetStartIndex(index int)

SetStartIndex sets specified integer as index of first item to display. If specified value is bigger than last item index then first index(0) is set, if is smaller than 0 then last index is set.

func (*List) SetUpButtonBackground

func (l *List) SetUpButtonBackground(s *pixel.Sprite)

SetUpButtonBackground sets specified sprite as scroll up button background.

func (*List) Size

func (l *List) Size() pixel.Vec

Size returns list background size

func (*List) Update

func (l *List) Update(win *Window)

Update updates list.

type MessageQueue

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

MessageQueue struct for list with messages to display.

func NewMessageQueue

func NewMessageQueue(focus *Focus) *MessageQueue

NewMessageQueue creates new messages queue.

func (*MessageQueue) Append

func (mq *MessageQueue) Append(m *MessageWindow)

Append adds specified message to the front of queue.

func (*MessageQueue) ContainsPosition

func (mq *MessageQueue) ContainsPosition(pos pixel.Vec) bool

ContainsPosition checks whether specified position is contained by any message window in the queue.

func (*MessageQueue) Draw

func (mq *MessageQueue) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws all messages

func (*MessageQueue) Remove

func (mq *MessageQueue) Remove(i int)

Remove removes message with specified index from queue.

func (*MessageQueue) Update

func (mq *MessageQueue) Update(win *Window)

Update updates all messages in queue.

type MessageWindow

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

MessageWindow struct represents UI message window.

func NewDialogWindow

func NewDialogWindow(params Params) *MessageWindow

NewDialogWindow creates new dialog window with message.

func NewMessageWindow

func NewMessageWindow(params Params) *MessageWindow

NewMessageWindow creates new message window instance.

func (*MessageWindow) Accepted

func (mw *MessageWindow) Accepted() bool

Accepted checks whether message was accepted.

func (*MessageWindow) Active

func (mw *MessageWindow) Active(active bool)

Active toggles message active state.

func (*MessageWindow) Disabled

func (mw *MessageWindow) Disabled() bool

Disabled checks whether message is unactive.

func (*MessageWindow) Dismissed

func (mw *MessageWindow) Dismissed() bool

Dismissed checks whether window was dismised.

func (*MessageWindow) Draw

func (mw *MessageWindow) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws window.

func (*MessageWindow) DrawArea

func (mw *MessageWindow) DrawArea() pixel.Rect

DrawArea returns size of current draw area.

func (*MessageWindow) Focus

func (mw *MessageWindow) Focus(focus bool)

Focus sets or removes focus from window.

func (*MessageWindow) Focused

func (mw *MessageWindow) Focused() bool

Focused checks whether window is focused.

func (*MessageWindow) Opened

func (mw *MessageWindow) Opened() bool

Opened checks whether window should be open.

func (*MessageWindow) SetAcceptLabel

func (mw *MessageWindow) SetAcceptLabel(l string)

SetAcceptLabel sets label for accept button.

func (*MessageWindow) SetCancelLabel

func (mw *MessageWindow) SetCancelLabel(l string)

SetCancelLabel sets label for cancel button.

func (*MessageWindow) SetOnAcceptFunc

func (mw *MessageWindow) SetOnAcceptFunc(f func(msg *MessageWindow))

SetOnAcceptFunc sets specified function as function triggered after message was accepted.

func (*MessageWindow) SetOnCancelFunc

func (mw *MessageWindow) SetOnCancelFunc(f func(msg *MessageWindow))

SetOnCancelFunc sets specified function as function triggered after message was canceled.

func (*MessageWindow) Show

func (mw *MessageWindow) Show(show bool)

Show toggles window visibility.

func (*MessageWindow) Size

func (mw *MessageWindow) Size() pixel.Vec

Size resturns message window size.

func (*MessageWindow) Update

func (mw *MessageWindow) Update(win *Window)

Update handles key press events.

type MultiAnimation

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

Struct with sparate animation for each direction(up, right, down and left).

func NewMultiAnimation

func NewMultiAnimation(up, right, down, left *Animation) *MultiAnimation

NewMultiAnimation creates new multi direction animation from specified animations(up, right, down, left).

func (*MultiAnimation) Down

func (ma *MultiAnimation) Down()

Down sets animation direction to down.

func (*MultiAnimation) Draw

func (ma *MultiAnimation) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws animation for current dirtection.

func (*MultiAnimation) DrawArea

func (ma *MultiAnimation) DrawArea() pixel.Rect

DrawArea returns current draw area.

func (*MultiAnimation) Finished

func (ma *MultiAnimation) Finished() bool

Finished checks whether current animation is finished.

func (*MultiAnimation) Left

func (ma *MultiAnimation) Left()

Left sets animation direction to left.

func (*MultiAnimation) Loop

func (ma *MultiAnimation) Loop(loop bool)

Loop toggles animation looping for each direction.

func (*MultiAnimation) Restart

func (ma *MultiAnimation) Restart()

Restart restarts all animations.

func (*MultiAnimation) Right

func (ma *MultiAnimation) Right()

Right sets animation direction to right.

func (*MultiAnimation) Up

func (ma *MultiAnimation) Up()

Up sets animation direction to up.

func (*MultiAnimation) Update

func (ma *MultiAnimation) Update(win *Window)

Update updates animation for current direction.

type Params

type Params struct {
	MainColor   color.Color
	SecColor    color.Color
	AccentColor color.Color
	Size        Size
	SizeRaw     pixel.Vec
	FontSize    Size
	Shape       Shape
	Background  *pixel.Sprite
	Label       string
	Info        string
}

Struct for MTK graphical widget parameters.

type ProgressBar

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

Struct for progress bars.

func NewProgressBar

func NewProgressBar(size Size, color color.Color) *ProgressBar

NewProgressBar creates new progress bar with IMDraw background bar with specified size, color and label text.

func (*ProgressBar) Draw

func (pb *ProgressBar) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws progress bar.

func (*ProgressBar) DrawArea

func (pb *ProgressBar) DrawArea() pixel.Rect

DrawArea returns current last draw area of this element.

func (*ProgressBar) Max

func (pb *ProgressBar) Max() int

Max retruns maximal progress value.

func (*ProgressBar) SetBackground

func (pb *ProgressBar) SetBackground(p pixel.Picture)

SetBackground sets specified sprite as bar background, also removes current background color.

func (*ProgressBar) SetColor

func (pb *ProgressBar) SetColor(c color.Color)

SetColor sets specified color as background color.

func (*ProgressBar) SetLabel

func (pb *ProgressBar) SetLabel(t string)

SetLabel sets specified text as progress label.

func (*ProgressBar) SetMax

func (pb *ProgressBar) SetMax(max int)

SetMax sets specified value as progress maximal value.

func (*ProgressBar) SetValue

func (pb *ProgressBar) SetValue(val int)

SetValue sets specified value as current progress value.

func (*ProgressBar) Size

func (pb *ProgressBar) Size() pixel.Vec

Size returns bar size.

func (*ProgressBar) Update

func (pb *ProgressBar) Update(win *Window)

Update updates progress bar.

func (*ProgressBar) Value

func (pb *ProgressBar) Value() int

Value retruns current progress value.

type Shape

type Shape int

Type for shapes of UI elements. Shapes: rectangle(0), square(1).

type Size

type Size int

Type for sizes of UI elements, like buttons, switches, etc. Sizes: mini(0), small(1), medium(2), big(3), huge(4).

func (Size) BarSize

func (s Size) BarSize() pixel.Vec

BarSize returns size parameters for progress bar.

func (Size) ButtonSize

func (s Size) ButtonSize(sh Shape) pixel.Vec

ButtonSize returns szie parameters for button with this size and with specifed shape.

func (Size) ListSize

func (s Size) ListSize() pixel.Vec

ListSize returns size parameters for list.

func (Size) MessageWindowSize

func (s Size) MessageWindowSize() pixel.Vec

MessageWindowSize returns size parameters for message window.

func (Size) SlotSize

func (s Size) SlotSize() pixel.Vec

SlotSize returns size parameters for slot.

func (Size) SwitchSize

func (s Size) SwitchSize() pixel.Vec

SwitchSize return rectangele parameters for switch with this size.

type Slot

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

Struct for slot.

func NewSlot

func NewSlot(params Params) *Slot

NewSlot creates new slot without background.

func (*Slot) AddValues

func (s *Slot) AddValues(vls ...interface{})

AddValue adds specified interface to slot values list.

func (*Slot) Clear

func (s *Slot) Clear()

Clear removes slot value, icon, label and text.

func (*Slot) Drag

func (s *Slot) Drag(drag bool)

Drag toggles slot drag mode(icon follows mouse cursor).

func (*Slot) Dragged

func (s *Slot) Dragged() bool

Dragged checks whether slot is in drag mode(icon follows mouse cursor).

func (*Slot) Draw

func (s *Slot) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws slot.

func (*Slot) DrawArea

func (s *Slot) DrawArea() pixel.Rect

DrawArea returns current slot background draw area.

func (*Slot) Icon

func (s *Slot) Icon() pixel.Picture

Icon returns current slot icon picture.

func (*Slot) Label

func (s *Slot) Label() string

Label returns slot label text.

func (*Slot) Pop

func (s *Slot) Pop() interface{}

Pop removes and returns first value from slot. Clears slot if removed value was last value in slot.

func (*Slot) SetColor

func (s *Slot) SetColor(c color.Color)

SetColor sets specified color as slot color.

func (*Slot) SetIcon

func (s *Slot) SetIcon(pic pixel.Picture)

SetIcon sets specified sprite as current slot icon.

func (*Slot) SetInfo

func (s *Slot) SetInfo(text string)

SetInfo sets specified text as content of slot info window.

func (*Slot) SetLabel

func (s *Slot) SetLabel(text string)

SetLabel sets specified text as slot label.

func (*Slot) SetOnLeftClickFunc

func (s *Slot) SetOnLeftClickFunc(f func(s *Slot))

SetOnLeftClickFunc set speicfied function as function triggered after left mouse click event.

func (*Slot) SetOnRightClickFunc

func (s *Slot) SetOnRightClickFunc(f func(s *Slot))

SetOnClickFunc set speicfied function as function triggered after right mouse click event.

func (*Slot) SetOnSpecialLeftClickFunc

func (s *Slot) SetOnSpecialLeftClickFunc(f func(s *Slot))

SetOnSpecialLeftClickFunc set speicfied function as function triggered after special key pressed + left mouse click event.

func (*Slot) SetOnSpecialRightClickFunc

func (s *Slot) SetOnSpecialRightClickFunc(f func(s *Slot))

SetOnSpecialRightClickFunc set speicfied function as function triggered after special key pressed + right mouse click event.

func (*Slot) SetSpecialKey

func (s *Slot) SetSpecialKey(k pixelgl.Button)

SetSpecialKey sets special key for slot click events.

func (*Slot) SetValues

func (s *Slot) SetValues(vls []interface{})

SetValues replaces current values with specified ones.

func (*Slot) Size

func (s *Slot) Size() pixel.Vec

Size returns slot size.

func (*Slot) Update

func (s *Slot) Update(win *Window)

Update updates slot.

func (*Slot) Values

func (s *Slot) Values() []interface{}

Values returns all slot values.

type SlotList

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

Struct for list with slots.

func NewSlotList

func NewSlotList(bgSize pixel.Vec, bgColor color.Color, slotSize Size) *SlotList

NewSlotList creates new list with slots.

func (*SlotList) Add

func (sl *SlotList) Add(s *Slot)

Add adds specified slot to list.

func (*SlotList) Clear

func (sl *SlotList) Clear()

Clear clears all slots on the list.

func (*SlotList) Draw

func (sl *SlotList) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws list.

func (*SlotList) EmptySlot

func (sl *SlotList) EmptySlot() *Slot

EmptySlot returns first empty slot.

func (*SlotList) SetDownButtonBackground

func (sl *SlotList) SetDownButtonBackground(s *pixel.Sprite)

SetDownButtonBackground sets specified sprite as scroll down button background.

func (*SlotList) SetUpButtonBackground

func (sl *SlotList) SetUpButtonBackground(s *pixel.Sprite)

SetUpButtonBackground sets specified sprite as scroll up button background.

func (*SlotList) Size

func (sl *SlotList) Size() pixel.Vec

Bounds retruns background size.

func (*SlotList) Slots

func (sl *SlotList) Slots() []*Slot

Slots returns all slots from list.

func (*SlotList) Update

func (sl *SlotList) Update(win *Window)

Update updates list.

type Switch

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

Switch struct represents graphical switch for values.

func NewSwitch

func NewSwitch(params Params) *Switch

NewSwitch creates new switch with specified size and color.

func (*Switch) Active

func (s *Switch) Active(active bool)

Active toggles switch activity.

func (*Switch) Disabled

func (s *Switch) Disabled() bool

Disabled checks whether switch is active.

func (*Switch) Draw

func (s *Switch) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws switch.

func (*Switch) DrawArea

func (s *Switch) DrawArea() pixel.Rect

DrawArea returns current switch background position and size.

func (*Switch) Find

func (s *Switch) Find(value interface{}) int

Find checks if switch constains specified value and returns index of this value or -1 if switch does not contains such value.

func (*Switch) FindValue

func (s *Switch) FindValue(index int) *SwitchValue

Find searches switch values for value with specified index and returns this value or nil if switch does not contains value with such index.

func (*Switch) Focus

func (s *Switch) Focus(focus bool)

Focus toggles focus on element.

func (*Switch) Focused

func (s *Switch) Focused() bool

Focused checks whether switch is focused.

func (*Switch) Reset

func (s *Switch) Reset()

Reset sets value with first index as current value.

func (*Switch) SetBackground

func (s *Switch) SetBackground(spr *pixel.Sprite)

SetBackground sets specified sprite as switch background, also removes background color.

func (*Switch) SetColor

func (s *Switch) SetColor(c color.Color)

SetColor sets specified color as switch background color.

func (*Switch) SetIndex

func (s *Switch) SetIndex(index int)

SetIndex sets value with specified index as current value of this switch. If specified value is bigger than maximal possible index, then index of first value is set, if specified index is smaller than minimal, then index of last value is set.

func (*Switch) SetInfo

func (s *Switch) SetInfo(t string)

SetInfo sets specified text as info.

func (*Switch) SetIntValues

func (s *Switch) SetIntValues(min, max int)

SwtIntValues adds to witch all integers from specified min/max range.

func (*Switch) SetLabel

func (s *Switch) SetLabel(t string)

SetLabel sets specified text as label.

func (*Switch) SetNextButtonBackground

func (s *Switch) SetNextButtonBackground(spr *pixel.Sprite)

SetNextButtonBackground sets specified sprite as next button background.

func (*Switch) SetOnChangeFunc

func (s *Switch) SetOnChangeFunc(f func(s *Switch, old, new *SwitchValue))

Sets specified function as function triggered on on switch value change.

func (*Switch) SetPrevButtonBackground

func (s *Switch) SetPrevButtonBackground(spr *pixel.Sprite)

SetPrevButtonBackground sets specified sprite as previous button background.

func (*Switch) SetValues

func (s *Switch) SetValues(values ...SwitchValue)

SetValues sets specified list with values as switch values.

func (*Switch) Size

func (s *Switch) Size() pixel.Vec

Size returns switch background size.

func (*Switch) Update

func (s *Switch) Update(win *Window)

Update updates switch and all elements.

func (*Switch) Value

func (s *Switch) Value() *SwitchValue

Value returns current switch value.

type SwitchValue

type SwitchValue struct {
	View  interface{}
	Value interface{}
}

Tuple for switch values, contains value to display(view) and real value.

type Text

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

Text struct for short text like labels, names, etc.

func NewText

func NewText(p Params) *Text

NewText creates new text with specified parameters.

func (*Text) Align

func (t *Text) Align(a Align)

Align aligns text to specified position.

func (*Text) BoundsOf

func (tx *Text) BoundsOf(text string) pixel.Rect

BoundsOf returns bounds of specified text while displayed.

func (*Text) Clear

func (t *Text) Clear()

Clear clears texts,

func (*Text) Content

func (t *Text) Content() string

Content returs text content.

func (*Text) Draw

func (tx *Text) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws text.

func (*Text) DrawArea

func (tx *Text) DrawArea() pixel.Rect

DrawArea returns current draw area of text.

func (*Text) SetColor

func (tx *Text) SetColor(c color.Color)

SetColor sets specified color as current text color.

func (*Text) SetMaxWidth

func (tx *Text) SetMaxWidth(width float64)

SetMaxWidth sets maximal width of single text line.

func (*Text) SetText

func (t *Text) SetText(text string)

SetText sets specified text as text to display.

func (*Text) Size

func (tx *Text) Size() pixel.Vec

Size returns size of current text.

func (*Text) String

func (tx *Text) String() string

String returns text content.

func (*Text) Write

func (tx *Text) Write(p []byte) (n int, err error)

Write writes specified data as text to text area.

type Textbox

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

Struct for textboxes.

func NewTextbox

func NewTextbox(params Params) *Textbox

NewTextbox creates new textbox with specified parameters.

func (*Textbox) AddText

func (tb *Textbox) AddText(text string)

AddText adds specified text to box.

func (*Textbox) AtBottom

func (tb *Textbox) AtBottom() bool

AtBottom checks if textbox is scrolled to the bottom.

func (*Textbox) Clear

func (tb *Textbox) Clear()

Clear clears textbox.

func (*Textbox) Draw

func (tb *Textbox) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws textbox.

func (*Textbox) DrawArea

func (t *Textbox) DrawArea() pixel.Rect

DrawArea returns current draw area of text box background.

func (*Textbox) Focus

func (tb *Textbox) Focus(focus bool)

Focus sets/removes focus from textbox.

func (*Textbox) Focused

func (tb *Textbox) Focused() bool

Focused checks if textbox is focused.

func (*Textbox) ScrollBottom

func (tb *Textbox) ScrollBottom()

ScrollBottom scrolls textbox to last lines of text content.

func (*Textbox) SetDownButtonBackground

func (tb *Textbox) SetDownButtonBackground(s *pixel.Sprite)

SetDownButtonBackground sets specified sprite as scroll down button background.

func (*Textbox) SetMaxTextWidth

func (tb *Textbox) SetMaxTextWidth(width float64)

SetMaxTextWidth sets maximal width of single line in text area.

func (*Textbox) SetSize

func (tb *Textbox) SetSize(s pixel.Vec)

SetSize sets background size.

func (*Textbox) SetText

func (tb *Textbox) SetText(text ...string)

SetText clears textbox and inserts specified lines of text.

func (*Textbox) SetUpButtonBackground

func (tb *Textbox) SetUpButtonBackground(s *pixel.Sprite)

SetUpButtonBackground sets specified sprite as scroll up button background.

func (*Textbox) Size

func (tb *Textbox) Size() pixel.Vec

Size returns size of textbox background.

func (*Textbox) String

func (tb *Textbox) String() string

String returns textbox content.

func (*Textbox) TextSize

func (tb *Textbox) TextSize() pixel.Vec

TextSize returns size of text content.

func (*Textbox) Update

func (tb *Textbox) Update(win *Window)

Update handles key events.

type Textedit

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

Struct for text edit fields.

func NewTextedit

func NewTextedit(params Params) *Textedit

NewTextedit creates new textedit based on specified parameters.

func (*Textedit) Active

func (te *Textedit) Active(active bool)

Active toggles field activity.

func (*Textedit) Clear

func (te *Textedit) Clear()

Clear clears text edit input.

func (*Textedit) Disabled

func (te *Textedit) Disabled() bool

Disabled checks whether field is disabled.

func (*Textedit) Draw

func (te *Textedit) Draw(t pixel.Target, matrix pixel.Matrix)

Draw draws text edit.

func (*Textedit) DrawArea

func (te *Textedit) DrawArea() pixel.Rect

DrawArea returns current draw area rectangle.

func (*Textedit) Focus

func (te *Textedit) Focus(focus bool)

Focus sets or removes focus from text edit.

func (*Textedit) Focused

func (te *Textedit) Focused() bool

Focused checks whether text edit is focused.

func (*Textedit) SetSize

func (te *Textedit) SetSize(size pixel.Vec)

SetSize sets text edit size.

func (*Textedit) SetText

func (te *Textedit) SetText(text string)

SetText sets specified text as current value of text edit field.

func (*Textedit) Size

func (te *Textedit) Size() pixel.Vec

Size returns text edit size.

func (*Textedit) Text

func (te *Textedit) Text() string

Text return current value of text edit.

func (*Textedit) Update

func (te *Textedit) Update(win *Window)

Update updates text edit.

type Window

type Window struct {
	*pixelgl.Window
	// contains filtered or unexported fields
}

Wrapper struct for pixel window, to provide scalability.

func NewWindow

func NewWindow(conf pixelgl.WindowConfig) (*Window, error)

NewWindow creates new MTK window.

func (*Window) Delta

func (w *Window) Delta() int64

Delta returns time from last window update in milliseconds.

func (*Window) FPS

func (w *Window) FPS() int

FPS returns current frame per second value.

func (*Window) PointBL

func (w *Window) PointBL() pixel.Vec

PointBL returns position of bottom left corner of window.

func (*Window) PointBR

func (w *Window) PointBR() pixel.Vec

PointBR returns position of bottom right corner of window.

func (*Window) PointTL

func (w *Window) PointTL() pixel.Vec

PointTL returns position of top left corner of window.

func (*Window) SetMaxFPS

func (w *Window) SetMaxFPS(fps int)

SetMaxFPS sets maximal value for window FPS. Value <= 0 removes FPS limit.

func (*Window) Update

func (w *Window) Update()

Update updates window.

Directories

Path Synopsis
example
animation
Example for creating simple MTK animation.
Example for creating simple MTK animation.
audioplayer/control
Example of controlling audio player.
Example of controlling audio player.
audioplayer/play
Example of using audio player.
Example of using audio player.
button
Example for creating simple MTK button with draw background, custom on-click function, and click sound effect.
Example for creating simple MTK button with draw background, custom on-click function, and click sound effect.
list
Example of creating and using list.
Example of creating and using list.
messagequeue
Example for the MTK Message Queue.
Example for the MTK Message Queue.
messagewindow
Example for creating MTK message window.
Example for creating MTK message window.
slot
Example of creating and using slot.
Example of creating and using slot.
switch/number
Example for creating MTK switch with number values.
Example for creating MTK switch with number values.
switch/toggle
Example for creating MTK switch.
Example for creating MTK switch.
text
Example of creating text to draw.
Example of creating text to draw.
textbox
Example of creating and using MTK textbox.
Example of creating and using MTK textbox.
textedit
Example of creating and using MTK textedit.
Example of creating and using MTK textedit.
window
Example of creating MTK window.
Example of creating MTK window.

Jump to

Keyboard shortcuts

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