ui

package module
v0.0.0-...-226917b Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 2 Imported by: 4

README

work in progress

Documentation

Index

Constants

View Source
const MenuDrag menuDrag = 0

Variables

This section is empty.

Functions

func HandleKeyboardShortcuts

func HandleKeyboardShortcuts(state *State)

Types

type BackendState

type BackendState struct {
	State
	// contains filtered or unexported fields
}

func (*BackendState) AddKeyPress

func (s *BackendState) AddKeyPress(k Key)

func (*BackendState) AddScroll

func (s *BackendState) AddScroll(x, y float64)

func (*BackendState) AddTextInput

func (s *BackendState) AddTextInput(text string)

func (*BackendState) AnimationRequested

func (s *BackendState) AnimationRequested() bool

func (*BackendState) Cursor

func (s *BackendState) Cursor() Cursor

func (*BackendState) GrabMouse

func (s *BackendState) GrabMouse()

func (*BackendState) QuitRequested

func (s *BackendState) QuitRequested() bool

func (*BackendState) RefocusRequested

func (s *BackendState) RefocusRequested() bool

func (*BackendState) ReleaseMouse

func (s *BackendState) ReleaseMouse(b MouseButton)

func (*BackendState) ResetEvents

func (s *BackendState) ResetEvents()

func (*BackendState) ResetRequests

func (s *BackendState) ResetRequests()
func (s *BackendState) SetBlink(b bool)

func (*BackendState) SetHovered

func (s *BackendState) SetHovered(h bool)

func (*BackendState) SetModifiers

func (s *BackendState) SetModifiers(m Modifier)

func (*BackendState) SetMouseButtons

func (s *BackendState) SetMouseButtons(b MouseButton)

func (*BackendState) SetMouseClicks

func (s *BackendState) SetMouseClicks(clicks int)

func (*BackendState) SetMousePosition

func (s *BackendState) SetMousePosition(x, y float64)

func (*BackendState) SetTheme

func (s *BackendState) SetTheme(t Theme)

func (*BackendState) SetWindowSize

func (s *BackendState) SetWindowSize(w, h float64)

func (*BackendState) UpdateRequested

func (s *BackendState) UpdateRequested() bool

func (*BackendState) WindowTitle

func (s *BackendState) WindowTitle() string

type Component

type Component interface {
	PreferredSize(*State) (float64, float64)
	Update(*State)
}

type Cursor

type Cursor byte
const (
	CursorNormal Cursor = iota
	CursorText
	CursorHand
	CursorCrosshair
	CursorDisabled
	CursorWait
	CursorWaitBackground
	CursorMove
	CursorResizeHorizontal
	CursorResizeVertical
	CursorResizeDiagonal
	CursorResizeDiagonal2
)

type Key

type Key string
const (
	KeyUnknown Key = "Unknown"

	KeyEscape Key = "Escape"
	KeyF1     Key = "F1"
	KeyF2     Key = "F2"
	KeyF3     Key = "F3"
	KeyF4     Key = "F4"
	KeyF5     Key = "F5"
	KeyF6     Key = "F6"
	KeyF7     Key = "F7"
	KeyF8     Key = "F8"
	KeyF9     Key = "F9"
	KeyF10    Key = "F10"
	KeyF11    Key = "F11"
	KeyF12    Key = "F12"

	KeyPrintScreen Key = "Print"
	KeyScrollLock  Key = "Scroll Lock"
	KeyPause       Key = "Pause"

	KeyInsert   Key = "Insert"
	KeyHome     Key = "Home"
	KeyPageUp   Key = "Page Up"
	KeyDelete   Key = "Delete"
	KeyEnd      Key = "End"
	KeyPageDown Key = "Page Down"

	KeyEnter     Key = "Enter"
	KeyBackspace Key = "Backspace"
	KeyTab       Key = "Tab"
	KeySpace     Key = "Space"
	KeyCapsLock  Key = "Caps Lock"

	KeyUp    Key = "Up"
	KeyLeft  Key = "Left"
	KeyDown  Key = "Down"
	KeyRight Key = "Right"

	KeyNumLock       Key = "Num Lock"
	KeyNumpadDiv     Key = "Numpad /"
	KeyNumpadMul     Key = "Numpad *"
	KeyNumpadMinus   Key = "Numpad -"
	KeyNumpadPlus    Key = "Numpad +"
	KeyNumpadEnter   Key = "Numpad Enter"
	KeyNumpad1       Key = "Numpad 1"
	KeyNumpad2       Key = "Numpad 2"
	KeyNumpad3       Key = "Numpad 3"
	KeyNumpad4       Key = "Numpad 4"
	KeyNumpad5       Key = "Numpad 5"
	KeyNumpad6       Key = "Numpad 6"
	KeyNumpad7       Key = "Numpad 7"
	KeyNumpad8       Key = "Numpad 8"
	KeyNumpad9       Key = "Numpad 9"
	KeyNumpad0       Key = "Numpad 0"
	KeyNumpadDecimal Key = "Numpad ."

	KeyMenu Key = "Menu"

	KeyLeftControl  Key = "Left Control"
	KeyLeftShift    Key = "Left Shift"
	KeyLeftAlt      Key = "Left Alt"
	KeyLeftSuper    Key = "Left Super"
	KeyRightControl Key = "Right Control"
	KeyRightShift   Key = "Right Shift"
	KeyRightAlt     Key = "Right Alt"
	KeyRightSuper   Key = "Right Super"
)

type Modifier

type Modifier byte
const (
	Shift Modifier = 1 << iota
	Control
	Alt
	Super
	CapsLock
	NumLock
)

type MouseButton

type MouseButton byte
const (
	MouseLeft MouseButton = 1 << iota
	MouseMiddle
	MouseRight
	MouseForward
	MouseBack
)
type Popup interface {
	Close()
	Closed() bool
}

type Root

type Root interface {
	OpenDialog(Component)
	CloseDialog()
	OpenPopup(draw.Rect, Component) Popup
	ClosePopups()
	HasPopups() bool
}

type State

type State struct {
	Draw *draw.Buffer
	// contains filtered or unexported fields
}

The State is a components connection to the application. It can be used to query input events and to request actions.

func (*State) AnimationSpeed

func (s *State) AnimationSpeed() float32

AnimationSpeed returns the time since the last call to RequestAnimation in seconds.

func (s *State) Blink() bool

Blink returns the current state of blinking elements. This is mostly indended for the cursor in text fields.

func (*State) ClickCount

func (s *State) ClickCount() int

ClickCount returns the number of consecutive mouse clicks.

func (*State) ClipboardString

func (s *State) ClipboardString() string

ClipboardString returns the contents of the clipboard.

func (*State) CloseDialog

func (s *State) CloseDialog()

CloseDialog closes the currently open dialog, if any.

func (*State) ClosePopups

func (s *State) ClosePopups()

ClosePopups closes all popups.

func (*State) ConsumeScroll

func (s *State) ConsumeScroll()

ConsumeScroll notifies the State that the scroll amount has been used and should not be used by any other components.

func (*State) DisableTabFocus

func (s *State) DisableTabFocus()

DisableTabFocus disables focus cycling with the tab key for the current component.

func (*State) DraggedContent

func (s *State) DraggedContent() (content interface{}, drop bool)

DraggedContent returns information abount a drag and drop gesture currently in progress. If there is no drag and drop gesture, or the mouse cursor is not above the current component, content will be nil. Otherwise, content will be the value passed to InitiateDrag. drop will be true if the mouse was released just before the current update.

func (*State) DrawChild

func (s *State) DrawChild(bounds draw.Rect, c Component)

DrawChild draws another component without passing on any input.

func (*State) FocusNext

func (s *State) FocusNext()

SetKeyboardFocus requests that the next component will receive keyboard events.

func (*State) FocusPrevious

func (s *State) FocusPrevious()

SetKeyboardFocus requests that the previous component will receive keyboard events.

func (*State) GetVisibilityRequest

func (s *State) GetVisibilityRequest() (draw.Rect, bool)

GetVisibilityRequest returns the rectangle passed to RequestVisible by a child of the current component. This method should be called after UpdateChild. The returned rectangle will be translated relative to the current component. If the second return value is false, RequestVisible was not called.

func (*State) HasKeyboardFocus

func (s *State) HasKeyboardFocus() bool

HasKeyboardFocus returns true if the current component receives keyboard events.

func (*State) HasModifiers

func (s *State) HasModifiers(m Modifier) bool

HasModifiers returns true if the given modifiers are currently active.

func (*State) HasMouseFocus

func (s *State) HasMouseFocus() bool

HasMouseFocus returns true if the current component receives mouse events, i.e. if it is hovered or grabbed.

func (*State) HasPopups

func (s *State) HasPopups() bool

HasPopups returns wether any popups are currently open.

func (*State) InitiateDrag

func (s *State) InitiateDrag(content interface{})

InitiateDrag starts a drag and drop gesture.

func (*State) IsHovered

func (s *State) IsHovered() bool

IsHovered returns true if the cursor is inside the current component.

func (*State) KeyPresses

func (s *State) KeyPresses() []Key

KeyPresses returns a list of key events that the current component should process.

func (*State) KeyboardFocus

func (s *State) KeyboardFocus() Component

KeyboardFocus returns the component that currently receives keyboard events.

func (*State) MouseButtonDown

func (s *State) MouseButtonDown(b MouseButton) bool

MouseButtonDown returns true if a given mouse button is pressed.

func (*State) MouseClick

func (s *State) MouseClick(b MouseButton) bool

MouseClick returns true if a given mouse button was clicked between the current and last update.

func (*State) MousePos

func (s *State) MousePos() (float64, float64)

MousePos returns the position of the cursor relative to the current component.

func (*State) OpenDialog

func (s *State) OpenDialog(d Component)

OpenDialog displays the given component as a dialog. While a dialog is open, other components do not receive any events. Only one dialog may be open at a time.

func (*State) OpenPopup

func (s *State) OpenPopup(bounds draw.Rect, d Component) Popup

OpenPopup displays the given component as a popup.

func (*State) PeekKeyPresses

func (s *State) PeekKeyPresses() []Key

PeekKeyPresses returns a list of key events. Unlike KeyPresses, this method returns events even if they are not intended for the current component.

func (*State) Quit

func (s *State) Quit()

Quit requests the application to close.

func (*State) RequestAnimation

func (s *State) RequestAnimation()

RequestAnimation requests that the ui should be updated again after a short amount of time.

func (*State) RequestRefocus

func (s *State) RequestRefocus()

RequestRefocus requests that the component receiving mouse events should be determined again. This method should rarely be called by normal components.

func (*State) RequestUpdate

func (s *State) RequestUpdate()

RequestUpdate requests that the ui should be updated again after the current update. This method will typically be called if an input event causes a change to the layout or to components that may have already been updated.

func (*State) RequestVisible

func (s *State) RequestVisible(r draw.Rect)

RequestVisible should be called to request that the current component should be scrolled, so that the given rectangle is visible.

func (*State) Scroll

func (s *State) Scroll() (float64, float64)

Scroll returns the amount of scrolling since the last update.

func (s *State) SetBlink()

SetBlink requests that blinking elements should be visible.

func (*State) SetClipboardString

func (s *State) SetClipboardString(c string)

SetClipboardString sets the contents of the clipboard.

func (*State) SetCursor

func (s *State) SetCursor(c Cursor)

SetCursor sets the current compnents cursor style.

func (*State) SetKeyboardFocus

func (s *State) SetKeyboardFocus(c Component)

SetKeyboardFocus requests that the given component will receive keyboard events.

func (*State) SetRoot

func (s *State) SetRoot(r Root)

func (*State) SetTheme

func (s *State) SetTheme(t Theme)

func (*State) SetWindowTitle

func (s *State) SetWindowTitle(title string)

SetCursor sets the title of the window.

func (*State) Size

func (s *State) Size() (float64, float64)

Size returns the size of the current component

func (*State) TextInput

func (s *State) TextInput() string

TextInput returns the string that would be generated by key inputs. Key presses that contributed to the text input will still appear in KeyPresses().

func (*State) Theme

func (s *State) Theme() Theme

func (*State) UpdateChild

func (s *State) UpdateChild(bounds draw.Rect, c Component)

UpdateChild calls another component's Update method with a State that will deliver the correct events.

func (*State) WindowBounds

func (s *State) WindowBounds() draw.Rect

WindowBounds returns the bounds of the window relative to the current component's origin. This means the minimum point of the returned Rect will most likely be negative.

type Theme

type Theme interface {
	Color(string) draw.Color
	Font(string) draw.Font
	Enter(string)
	Leave()
}

Directories

Path Synopsis
impl
sdl
ttf

Jump to

Keyboard shortcuts

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