ui

package
v0.1.85 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ui draws each player's interface from a tree of elements, as struct literals:

ui.Show(p, ui.Panel{
	Style: ui.Style{Flow: ui.Down},
	Children: ui.Nodes{
		ui.Label{Text: "Round 2"},
		ui.Button{OnPress: ready, Children: ui.Text("Ready")},
	},
})

Each Show lays the tree out as flat nodes whose ids stay with their place in the tree, and sends the player only the nodes that changed since the screen they hold. Importing the package registers its handlers for presses, input changes, the frame clock and the player list with package mod.

Index

Constants

View Source
const (
	// Down runs children or colors down.
	Down = "down"
	// Right runs children or colors right, or aligns right.
	Right = "right"
	// DownWrap places children in columns that wrap.
	DownWrap = "downWrap"
	// RightWrap places children in rows that wrap.
	RightWrap = "rightWrap"
	// Up runs a gradient's colors up.
	Up = "up"
	// Left runs a gradient's colors left, or aligns left.
	Left = "left"
	// Radial runs a gradient's colors out from the center.
	Radial = "radial"
	// Top aligns to the top.
	Top = "top"
	// Center aligns to the middle.
	Center = "center"
	// Bottom aligns to the bottom.
	Bottom = "bottom"
	// Squish shrinks children that do not fit.
	Squish = "squish"
	// Clip cuts off children or text that do not fit.
	Clip = "clip"
	// Scroll lets the player scroll to children that do not fit.
	Scroll = "scroll"
	// Visible draws children that do not fit outside the element.
	Visible = "show"
	// Body is the game's text face.
	Body = "body"
	// Block is the face of the game's clock and titles.
	Block = "block"
	// Serif is the face of the game's menus.
	Serif = "serif"
	// Thin is the thinnest weight.
	Thin = "thin"
	// Light is a light weight.
	Light = "light"
	// Normal is the regular weight.
	Normal = "normal"
	// Medium is a medium weight.
	Medium = "medium"
	// SemiBold is a semibold weight.
	SemiBold = "semiBold"
	// Bold is a bold weight.
	Bold = "bold"
	// Black is the heaviest weight.
	Black = "black"
	// Ellipsis ends text that does not fit with an ellipsis.
	Ellipsis = "ellipsis"
	// Shrink shrinks text until it fits.
	Shrink = "shrink"
	// Underline draws a line under the text.
	Underline = "underline"
	// Strike draws a line through the text.
	Strike = "strike"
	// EaseOut starts fast and slows to the end.
	EaseOut = "out"
	// EaseIn starts slow and speeds to the end.
	EaseIn = "in"
	// EaseInOut starts and ends slow.
	EaseInOut = "inOut"
	// Linear keeps one pace.
	Linear = "linear"
	// Fit shows a picture whole.
	Fit = "fit"
	// Cover fills the box and crops.
	Cover = "cover"
	// Stretch fills the box and stretches.
	Stretch = "stretch"
	// FitWidth fits a picture's width.
	FitWidth = "fitWidth"
	// FitHeight fits a picture's height.
	FitHeight = "fitHeight"
	// None draws a picture at its own size.
	None = "none"
	// Small is the kill feed's square portrait.
	Small = "small"
	// Card is the hero picker's tall card.
	Card = "card"
	// Icon is the round icon.
	Icon = "icon"
	// Vertical is the hero grid's narrow portrait.
	Vertical = "vertical"
	// TopBar is the top bar, or its portrait.
	TopBar = "topBar"
	// Minimap is the minimap, or its icon.
	Minimap = "minimap"
	// LevelUp is the notice for each boon and ability point.
	LevelUp = "levelUp"
	// OwnHealth is the player's health bar.
	OwnHealth = "ownHealth"
	// Ammo is the clip ring and count at the crosshair.
	Ammo = "ammo"
	// Souls is the souls and level readout.
	Souls = "souls"
	// Abilities is the ability and active item bar.
	Abilities = "abilities"
	// Status is the game's mark in the top-left corner.
	Status = "status"
	// Stats is the weapon, spirit and vitality stats.
	Stats = "stats"
	// HeroPicker is the screen a player without a hero picks one on.
	HeroPicker = "heroPicker"
	// BrokerCountdown is the countdown in the Broker's window.
	BrokerCountdown = "brokerCountdown"
	// All is the whole HUD but the mods' own interfaces and tooltips.
	All = "all"
)

The names of each option. They are untyped so one name serves every option that takes it, as Right does a flow, an alignment and a gradient.

Variables

View Source
var Fill = Length{/* contains filtered or unexported fields */}

Fill shares the space left in the parent's flow.

View Source
var FitChildren = Length{/* contains filtered or unexported fields */}

FitChildren sizes an element to its children.

Functions

func AbilityBarPresses

func AbilityBarPresses(p mod.Player, onPress func(p mod.Player, slot int)) bool

AbilityBarPresses calls onPress with the slot, 0 to 3, each time player clicks the icon or upgrade pips of an ability on the game's own ability bar, as the game does when it trains one with Tab held; a nil onPress stops the clicks reaching the mod. The game answers a click from the hero's own abilities, and sends nothing for an ability the mod replaced, so a mod that replaces abilities answers here. Clicks reach the mod only while its screen holds the player's HUD.

func AbilityDisplay

func AbilityDisplay(viewer mod.Player, rows ...AbilityRow) bool

AbilityDisplay shows viewer each row's abilities in place of the ones the game shows for that player's hero: on the player's row of the game's Tab screen, and for viewer's own row on viewer's ability bar too, in the game's frame, ring and pips, with the game's ability window over each. Without rows the game's own come back, as they do when viewer leaves or the session ends. Rows match the Tab screen's by the player's name and else by the hero's, so each row's player should have a hero.

func CursorFree

func CursorFree(p mod.Player) (free, ok bool)

CursorFree reports whether player's mouse cursor is up now, whether the mod freed it with FreeCursor or the player did with the game's own keys. ok is false while the player has no hero to read.

func FreeCursor

func FreeCursor(p mod.Player, free bool) bool

FreeCursor shows player's mouse cursor without Tab held while free is true, so they can click the mod's panels, such as a pick screen; false gives the mouse back to aiming. Each call with true shows the cursor again, even when the player put it away with the game's own keys; a screen that changes without a call leaves their choice be. The game does not stop the player's shots, camera or movement while the cursor is up: a screen that must not fire a weapon blocks the buttons it takes.

func Hide

func Hide(p mod.Player) bool

Hide removes the interface, the routes and the notices the mod shows player.

func HideHud

func HideHud(p mod.Player, parts ...HudPart) bool

HideHud hides parts of the game's own HUD from player until the next call; no parts shows them all again.

func Route

func Route(p mod.Player, name, value string) bool

Route sends player the JSON text value under name, for every layout of the mod to read with Modlock.route, until the next call; "" removes it. A name is letters, digits, '_', '-' and '.'. A route with another name, or a value that is not JSON, sends nothing and returns false.

func Sheet

func Sheet(path string) bool

Sheet adds the style sheet at path in the mod's content styles directory, such as "hud.css", to every interface the mod shows, after the sheets added before it. Adding a sheet again changes nothing. A path is letters, digits, '_', '-' and '.' in segments separated by '/', ending in ".css"; another adds nothing and returns false.

func Show

func Show(p mod.Player, root Node) bool

Show replaces the interface the mod shows player with root. A player who left and a mod that restarted show nothing until the next call.

func Sound

func Sound(p mod.Player, sound string, seconds float32) bool

Sound plays the game's sound event sound, such as "UI.ItemDraft.Start", in player's game alone, once; seconds above 0 cuts it after that long, keeping only its start. It plays with the next screen the player reads, and not at all if the player reads it only after the mod's next few sounds.

func Toast

func Toast(p mod.Player, text string) bool

Toast shows player text in a notice at the lower left for four seconds. Notices stack, newest last, slide in, and fade as they expire.

func ToastFor

func ToastFor(p mod.Player, text string, seconds float64) bool

ToastFor shows player text in a notice for seconds, as Toast does.

Types

type AbilityRow

type AbilityRow struct {
	// Player is whose abilities the row replaces.
	Player mod.Player
	// Abilities holds slots 0 to 3; a nil slot shows the game's own.
	Abilities []*ShownAbility
}

AbilityRow is the four abilities, in slot order, AbilityDisplay shows for one player.

type AbilityTip

type AbilityTip struct {
	// Name is the ability's class name.
	Name string
	// Player is whose hero the window reads its numbers from.
	Player mod.Player
}

AbilityTip is the game's own window for an ability, in the player's language: Name is the ability's class name, such as "ability_bebop_hook", and Player is whose hero the window reads its numbers from, a hero that stands on the map, such as a bot that plays it.

type Align

type Align string

Align places an element in its parent, or text in its element: Left, Center or Right across, and Top, Center or Bottom down.

type Avatar

type Avatar struct {
	// Key keeps the avatar's node in a list while the list changes.
	Key string
	// Class names the avatar's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the avatar.
	Style Style
	// Hover is drawn over Style while the pointer is over the avatar.
	Hover *Style
	// Enter is the style the avatar starts from when it first shows.
	Enter *Style
	// Exit is the style the avatar eases to as it leaves.
	Exit *Style
	// Cycle swings the avatar to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the avatar.
	Tooltip string
	// Item names an item by class name whose shop card shows over the avatar.
	Item string
	// Ability names an ability whose window shows over the avatar.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// SteamID is whose picture the avatar shows.
	SteamID uint64
}

Avatar shows the Steam picture of the player with SteamID.

func (Avatar) Render

func (e Avatar) Render() Node

Render returns the avatar itself.

type Button

type Button struct {
	// Key keeps the button's node in a list while the list changes.
	Key string
	// Class names the button's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the button.
	Style Style
	// Hover is drawn over Style while the pointer is over the button.
	Hover *Style
	// Enter is the style the button starts from when it first shows.
	Enter *Style
	// Exit is the style the button eases to as it leaves.
	Exit *Style
	// Cycle swings the button to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the button.
	Tooltip string
	// Item names an item by class name whose shop card shows over the button.
	Item string
	// Ability names an ability whose window shows over the button.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Sound is the game's sound event the press plays.
	Sound string
	// Disabled makes the button take no presses.
	Disabled bool
	// OnPress runs with the player who pressed the button.
	OnPress func(p mod.Player)
	// Children are the nodes the button holds.
	Children Node
}

Button holds its children and calls OnPress with the player who pressed it. Players press buttons while they have a cursor. Sound is the game's sound event the press plays, such as "UI.MainMenu.Activate", and a disabled button takes no presses.

func (Button) Render

func (e Button) Render() Node

Render returns the button itself.

type Cycle

type Cycle struct {
	// Style is the style the element swings to.
	Style Style
	// Seconds is how long each swing takes.
	Seconds float32
	// Count is how many times it swings, or 0 for as long as it shows.
	Count uint32
}

Cycle swings an element from its style to Style and back, each way taking Seconds, Count times or, with a zero Count, while it shows.

type Decoration

type Decoration string

Decoration draws a line Underline or through (Strike) the text.

type Dropdown struct {
	// Key keeps the dropdown's node in a list while the list changes.
	Key string
	// Class names the dropdown's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the dropdown.
	Style Style
	// Hover is drawn over Style while the pointer is over the dropdown.
	Hover *Style
	// Enter is the style the dropdown starts from when it first shows.
	Enter *Style
	// Exit is the style the dropdown eases to as it leaves.
	Exit *Style
	// Cycle swings the dropdown to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the dropdown.
	Tooltip string
	// Item names an item by class name whose shop card shows over the dropdown.
	Item string
	// Ability names an ability whose window shows over the dropdown.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Disabled makes the dropdown take no changes.
	Disabled bool
	// Options are the choices, in order.
	Options []string
	// Selected is the index of the chosen option.
	Selected int
	// OnChange runs with the index of the option the player picked.
	OnChange func(p mod.Player, index int)
}

Dropdown lets the player pick one of Options; Selected is its index. A disabled dropdown takes no changes.

func (e Dropdown) Render() Node

Render returns the dropdown itself.

type Easing

type Easing string

Easing is a transition's pace: EaseOut, EaseIn, EaseInOut or Linear.

type Edges

type Edges []float32

Edges are distances in pixels: one for every side, [vertical, horizontal], or [top, right, bottom, left]. Nil is unset.

type Entry

type Entry struct {
	// Key keeps the entry's node in a list while the list changes.
	Key string
	// Class names the entry's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the entry.
	Style Style
	// Hover is drawn over Style while the pointer is over the entry.
	Hover *Style
	// Enter is the style the entry starts from when it first shows.
	Enter *Style
	// Exit is the style the entry eases to as it leaves.
	Exit *Style
	// Cycle swings the entry to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the entry.
	Tooltip string
	// Item names an item by class name whose shop card shows over the entry.
	Item string
	// Ability names an ability whose window shows over the entry.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Disabled makes the entry take no changes.
	Disabled bool
	// Value is the entry's text.
	Value string
	// Placeholder is the faint text the entry shows empty.
	Placeholder string
	// MaxLength is the entry's limit in characters.
	MaxLength uint32
	// OnChange runs with the text the player typed.
	OnChange func(p mod.Player, text string)
}

Entry is a box the player types a line into: Value is its text, Placeholder the faint text it shows empty, and MaxLength its limit in characters, 100 unless set, and at most 240 bytes of text. A disabled entry takes no changes.

func (Entry) Render

func (e Entry) Render() Node

Render returns the entry itself.

type Face

type Face string

Face is one of the game's typefaces: Body its text, Block the capitals of its clock and titles, Serif its menus.

type Flow

type Flow string

Flow places an element's children: Down in a column, Right in a row, and DownWrap or RightWrap in columns or rows that wrap where one is full; unset stacks them.

type Fragment

type Fragment struct {
	// Key keeps the fragment's nodes in a list while the list changes.
	Key string
	// Children are the nodes the fragment holds.
	Children Node
}

Fragment groups children without a panel of its own, and keys a component in a list: ui.Fragment{Key: id, Children: Row{...}}.

func (Fragment) Render

func (f Fragment) Render() Node

Render returns the fragment's children.

type Gradient

type Gradient struct {
	// Shape is the direction the colors run: Down, Right, Up, Left or Radial.
	Shape Shape
	// Colors are the colors in order, as "#rrggbb" or "#rrggbbaa".
	Colors []string
	// At places each color from 0 to 1; a color past its end is spaced evenly.
	At []float32
}

Gradient blends colors across an element in place of its background. The colors run down unless Shape is set; At places each color from 0 to 1, spaced evenly where unset.

type Hero

type Hero struct {
	// Key keeps the hero's node in a list while the list changes.
	Key string
	// Class names the hero's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the hero.
	Style Style
	// Hover is drawn over Style while the pointer is over the hero.
	Hover *Style
	// Enter is the style the hero starts from when it first shows.
	Enter *Style
	// Exit is the style the hero eases to as it leaves.
	Exit *Style
	// Cycle swings the hero to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the hero.
	Tooltip string
	// Item names an item by class name whose shop card shows over the hero.
	Item string
	// Ability names an ability whose window shows over the hero.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Hero is the hero's id, as Pawn.Hero and mod.Heroes give it.
	Hero uint32
	// Look is which of the game's pictures of the hero to show.
	Look HeroLook
	// Scaling fits the picture into the element's box.
	Scaling Scaling
}

Hero shows a picture of a hero, by the game's hero id.

func (Hero) Render

func (e Hero) Render() Node

Render returns the hero itself.

type HeroLook

type HeroLook string

HeroLook is one of the game's pictures of a hero: Small the square portrait of the kill feed, Card the hero picker's tall card, Icon the round icon, Vertical the hero grid's narrow portrait, TopBar the top bar's portrait and Minimap the minimap icon.

type HudPart

type HudPart string

HudPart is a part of the game's own HUD: LevelUp the notice for each boon, ability point and power increase, OwnHealth the player's health bar, TopBar the bar of team scores, portraits and clock, Ammo the clip ring and count, Souls the souls and level readout, Minimap the minimap, Abilities the ability and active item bar, Status the game's mark in the top-left corner, Stats the weapon, spirit and vitality stats, HeroPicker the screen a player without a hero picks one on, BrokerCountdown the Broker's countdown, and All the whole HUD but the mods' own interfaces and the game's tooltips.

type Image

type Image struct {
	// Key keeps the image's node in a list while the list changes.
	Key string
	// Class names the image's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the image.
	Style Style
	// Hover is drawn over Style while the pointer is over the image.
	Hover *Style
	// Enter is the style the image starts from when it first shows.
	Enter *Style
	// Exit is the style the image eases to as it leaves.
	Exit *Style
	// Cycle swings the image to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the image.
	Tooltip string
	// Item names an item by class name whose shop card shows over the image.
	Item string
	// Ability names an ability whose window shows over the image.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Src is the image's path in the game's content.
	Src string
	// Scaling fits the picture into the image's box.
	Scaling Scaling
}

Image shows an image from the game's content, such as "file://{images}/hud/icon.png".

func (Image) Render

func (e Image) Render() Node

Render returns the image itself.

type Label

type Label struct {
	// Key keeps the label's node in a list while the list changes.
	Key string
	// Class names the label's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the label.
	Style Style
	// Hover is drawn over Style while the pointer is over the label.
	Hover *Style
	// Enter is the style the label starts from when it first shows.
	Enter *Style
	// Exit is the style the label eases to as it leaves.
	Exit *Style
	// Cycle swings the label to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the label.
	Tooltip string
	// Item names an item by class name whose shop card shows over the label.
	Item string
	// Ability names an ability whose window shows over the label.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Text is the label's text.
	Text string
	// Token names the game's localized text to show in place of Text.
	Token string
	// Variables fill each {s:name} place in Token's text.
	Variables map[string]string
}

Label shows text: Text, or the game's text for Token in the player's language, with each {s:name} place in it filled from Variables.

func (Label) Render

func (e Label) Render() Node

Render returns the label itself.

type Layout

type Layout struct {
	// Key keeps the layout's node in a list while the list changes.
	Key string
	// Class names the layout's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the layout.
	Style Style
	// Src is the layout's path in the mod's content addon.
	Src string
	// Data is the JSON text the layout's script reads, or "" for none.
	Data string
}

Layout loads a layout from the mod's content addon: Src is its path there, such as "shop.xml", and Data is the JSON text its script reads with Modlock.data.

func (Layout) Render

func (e Layout) Render() Node

Render returns the layout itself.

type Length

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

Length is a size: pixels, a percentage of the parent, FitChildren to size to the children, or Fill to share the space left in the parent's flow. The zero Length is unset.

func Percent

func Percent(v float32) Length

Percent returns a length of v percent of the parent.

func Px

func Px(v float32) Length

Px returns a length of v pixels.

type Node

type Node interface {
	// Render returns the nodes that stand for this one.
	Render() Node
}

Node is anything an element may hold: an element, Text, Nodes, a Fragment or a component. A component is any other type whose Render returns the nodes that stand for it; an element's Render returns the element itself. A nil Node holds nothing.

type Nodes

type Nodes []Node

Nodes is a list of children. A child with a Key keeps its node while the list around it changes; the rest keep theirs by index.

func (Nodes) Render

func (n Nodes) Render() Node

Render returns the list itself.

type Overflow

type Overflow string

Overflow decides what happens to children that do not fit: Squish shrinks them, Clip cuts them off, Scroll lets the player scroll to them, and Visible draws them outside the element.

type Panel

type Panel struct {
	// Key keeps the panel's node in a list while the list changes.
	Key string
	// Class names the panel's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the panel.
	Style Style
	// Hover is drawn over Style while the pointer is over the panel.
	Hover *Style
	// Enter is the style the panel starts from when it first shows.
	Enter *Style
	// Exit is the style the panel eases to as it leaves.
	Exit *Style
	// Cycle swings the panel to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the panel.
	Tooltip string
	// Item names an item by class name whose shop card shows over the panel.
	Item string
	// Ability names an ability whose window shows over the panel.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Children are the nodes the panel holds.
	Children Node
}

Panel groups its children.

func (Panel) Render

func (e Panel) Render() Node

Render returns the panel itself.

type Scaling

type Scaling string

Scaling fits a picture into its element's box: Fit shows it whole, Cover fills the box and crops, Stretch fills the box and stretches, FitWidth and FitHeight fit one side, and None draws it at its own size.

type Shadow

type Shadow struct {
	// X offsets the shadow across, in pixels.
	X float32
	// Y offsets the shadow down, in pixels.
	Y float32
	// Blur softens the shadow, in pixels.
	Blur float32
	// Spread grows a box's shadow or strengthens a text shadow.
	Spread float32
	// Color is the shadow's color, as "#rrggbb" or "#rrggbbaa".
	Color string
	// Inset draws a box's shadow inside its edge.
	Inset bool
}

Shadow is a soft shadow, offset by X and Y and softened by Blur, in pixels. Spread grows a box's shadow in pixels, or strengthens a text shadow, where 0 draws it at full strength; Inset draws a box's shadow inside its edge.

type Shape

type Shape string

Shape is the direction a gradient's colors run: Down, Right, Up, Left or Radial.

type ShownAbility

type ShownAbility struct {
	// Name is the ability's class name, whose window the game shows over it.
	Name string
	// Image is its picture, a path in the game's content as an image's src.
	Image string
	// Upgrades holds its bought tiers as Ability.Upgrades: bit 0 unlocks it.
	Upgrades uint32
}

ShownAbility is the ability AbilityDisplay shows in one slot.

type Slider

type Slider struct {
	// Key keeps the slider's node in a list while the list changes.
	Key string
	// Class names the slider's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the slider.
	Style Style
	// Hover is drawn over Style while the pointer is over the slider.
	Hover *Style
	// Enter is the style the slider starts from when it first shows.
	Enter *Style
	// Exit is the style the slider eases to as it leaves.
	Exit *Style
	// Cycle swings the slider to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the slider.
	Tooltip string
	// Item names an item by class name whose shop card shows over the slider.
	Item string
	// Ability names an ability whose window shows over the slider.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Disabled makes the slider take no changes.
	Disabled bool
	// Value is the slider's number.
	Value float32
	// Min is the least number; with Max also 0 the range is 0 to 1.
	Min float32
	// Max is the greatest number.
	Max float32
	// Step is the distance between the stops, or 0 for none.
	Step float32
	// OnChange runs with the number the player dragged to.
	OnChange func(p mod.Player, value float32)
	// OnWheel receives one wheel step and its pointer anchor while enabled.
	OnWheel func(p mod.Player, wheel *mod.Wheel)
}

Slider is a bar the player drags to a number from Min to Max, 0 to 1 unless set, stopping at each Step when Step is set. A disabled slider takes no changes.

func (Slider) Render

func (e Slider) Render() Node

Render returns the slider itself.

type Style

type Style struct {
	// Width sizes the element across.
	Width Length
	// Height sizes the element down.
	Height Length
	// MinWidth is the least the element's width may shrink to.
	MinWidth Length
	// MaxWidth is the most the element's width may grow to.
	MaxWidth Length
	// MinHeight is the least the element's height may shrink to.
	MinHeight Length
	// MaxHeight is the most the element's height may grow to.
	MaxHeight Length
	// Flow places the children in a column or a row, or in columns or rows
	// that wrap where one is full; unset stacks them.
	Flow Flow
	// X places the element across from its parent's left edge, in pixels or a
	// percent of the parent, outside the parent's flow.
	X Length
	// Y places the element down from its parent's top edge, as X does across.
	Y Length
	// ZIndex draws the element above its siblings with a lower index.
	ZIndex int32
	// Overflow decides what children that do not fit do, across and down.
	Overflow Overflow
	// OverflowX sets Overflow across.
	OverflowX Overflow
	// OverflowY sets Overflow down.
	OverflowY Overflow
	// HorizontalAlign places the element across: Left, Center or Right.
	HorizontalAlign Align
	// VerticalAlign places the element down: Top, Center or Bottom.
	VerticalAlign Align
	// Margin is the space outside the element's edge, as Edges takes it.
	Margin Edges
	// Padding is the space inside the element's edge, as Edges takes it.
	Padding Edges
	// Background fills the element.
	Background string
	// Color colors the text.
	Color string
	// FontSize is the text's size in pixels.
	FontSize float32
	// Bold sets the text bold.
	Bold bool
	// TextAlign aligns the text: Left, Center or Right.
	TextAlign Align
	// BorderRadius rounds the corners, in pixels.
	BorderRadius float32
	// Opacity fades the element and its children, from 0 to 1.
	Opacity *float32
	// Face is one of the game's typefaces: Body, Block or Serif.
	Face Face
	// Uppercase sets the text in capitals.
	Uppercase bool
	// LetterSpacing widens the space between letters, in pixels.
	LetterSpacing float32
	// Shadow draws a soft drop shadow under the text, to read over the world.
	Shadow bool
	// TextShadow draws this shadow under the text in place of Shadow's.
	TextShadow *Shadow
	// BorderWidth and BorderColor draw a line around the element's edge; it
	// shows only when both are set.
	BorderWidth float32
	// BorderColor is the color of the border.
	BorderColor string
	// Gradient fills the element in place of its background.
	Gradient *Gradient
	// BoxShadow draws a shadow around or inside the element's box.
	BoxShadow *Shadow
	// Tint washes the element and its children with a color.
	Tint string
	// Saturation scales the colors' saturation; 1 leaves them.
	Saturation *float32
	// Brightness scales the colors' brightness; 1 leaves them.
	Brightness *float32
	// Contrast scales the colors' contrast; 1 leaves them.
	Contrast *float32
	// Blur blurs the element and its children by a radius in pixels.
	Blur float32
	// Italic sets the text in italics.
	Italic bool
	// Weight sets the text's weight in place of Bold.
	Weight Weight
	// LineHeight is the height of each line of text, in pixels.
	LineHeight float32
	// NoWrap keeps the text on one line.
	NoWrap bool
	// TextOverflow ends text that does not fit.
	TextOverflow TextOverflow
	// Decoration draws a line under or through the text.
	Decoration Decoration
	// Translate moves the element as drawn by [x, y] pixels.
	Translate []float32
	// Scale scales the element as drawn: one factor, or [x, y].
	Scale []float32
	// Rotate turns the element clockwise, in degrees.
	Rotate float32
	// Origin is the point the element scales and turns about, as [x, y]
	// percents of its size; unset is its center.
	Origin []float32
	// Transition animates each change of the style.
	Transition *Transition
}

Style lays out and paints an element. Colors are "#rrggbb" or "#rrggbbaa". A zero field is unset, except where zero means something on the wire: the pointer fields, and the slices and Lengths, which are unset only when nil or zero.

func (Style) Merge

func (s Style) Merge(over Style) Style

Merge returns s with each field over sets in its place, as a later style overrides an earlier one.

type Text

type Text string

Text is a label of plain text.

func (Text) Render

func (t Text) Render() Node

Render returns the text itself.

type TextOverflow

type TextOverflow string

TextOverflow ends text that does not fit with an Ellipsis, Shrinks it until it fits, or Clips it at the edge.

type Toggle

type Toggle struct {
	// Key keeps the toggle's node in a list while the list changes.
	Key string
	// Class names the toggle's classes in the mod's sheets, separated by spaces.
	Class string
	// Style lays out and paints the toggle.
	Style Style
	// Hover is drawn over Style while the pointer is over the toggle.
	Hover *Style
	// Enter is the style the toggle starts from when it first shows.
	Enter *Style
	// Exit is the style the toggle eases to as it leaves.
	Exit *Style
	// Cycle swings the toggle to another style and back while it shows.
	Cycle *Cycle
	// Tooltip is the text the game's tooltip shows over the toggle.
	Tooltip string
	// Item names an item by class name whose shop card shows over the toggle.
	Item string
	// Ability names an ability whose window shows over the toggle.
	Ability *AbilityTip
	// HoverSound is the game's sound event played as the pointer enters.
	HoverSound string
	// Disabled makes the toggle take no changes.
	Disabled bool
	// Text labels the toggle.
	Text string
	// On checks the box.
	On bool
	// OnChange runs with whether the player checked the box.
	OnChange func(p mod.Player, on bool)
}

Toggle is a box the player checks, labeled by Text. A disabled toggle takes no changes.

func (Toggle) Render

func (e Toggle) Render() Node

Render returns the toggle itself.

type Transition

type Transition struct {
	// Seconds is how long each change takes.
	Seconds float32
	// Delay is how long each change waits before it starts, in seconds.
	Delay float32
	// Easing is EaseOut, EaseIn, EaseInOut or Linear.
	Easing Easing
}

Transition animates each change of an element's style, and the move to its hover style and back, over Seconds after Delay. Easing is EaseOut unless set.

type Weight

type Weight string

Weight sets text's weight in place of Bold: Thin, Light, Normal, Medium, SemiBold, Bold or Black.

Jump to

Keyboard shortcuts

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