panes

package
v0.11.7 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2025 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SplitAxisNone = iota
	SplitAxisX
	SplitAxisY
)

Variables

View Source
var UICautionColor renderer.RGB = renderer.RGBFromHex(0xB7B513)
View Source
var UIControlColor renderer.RGB = renderer.RGB{R: 0.2754237, G: 0.2754237, B: 0.2754237}
View Source
var UIErrorColor renderer.RGB = renderer.RGBFromHex(0xE94242)
View Source
var UITextColor renderer.RGB = renderer.RGB{R: 0.85, G: 0.85, B: 0.85}
View Source
var UITextHighlightColor renderer.RGB = renderer.RGBFromHex(0xB2B338)

Functions

func Activate

func Activate(root *DisplayNode, r renderer.Renderer, p platform.Platform, eventStream *sim.EventStream, lg *log.Logger)

func DrawPanes

func DrawPanes(root *DisplayNode, p platform.Platform, r renderer.Renderer, controlClient *sim.ControlClient,
	menuBarHeight float32, audioEnabled *bool, lg *log.Logger) renderer.RendererStats

DrawPanes is called each time through the main rendering loop; it handles all of the details of drawing the Panes in the display hierarchy, making sure they don't inadvertently draw over other panes, and providing mouse and keyboard events only to the Pane that should respectively be receiving them.

func LoadedSim added in v0.11.5

func LoadedSim(root *DisplayNode, client *sim.ControlClient, state sim.State, pl platform.Platform, lg *log.Logger)

func RegisterUnmarshalPane

func RegisterUnmarshalPane(name string, fn func([]byte) (Pane, error))

func ResetSim added in v0.11.5

func ResetSim(root *DisplayNode, client *sim.ControlClient, state sim.State, pl platform.Platform, lg *log.Logger)

Types

type Context

type Context struct {
	PaneExtent       math.Extent2D
	ParentPaneExtent math.Extent2D

	Platform platform.Platform
	// If we want something to be n pixels big, scale factor to apply to n.
	// (This is necessary for Windows high-DPI displays, which just expose
	// their native resolution to us, vs. Mac which pretends retina
	// displays are 72dpi as far as graphics commands.)
	DrawPixelScale float32
	PixelsPerInch  float32
	// DPIScale is similar to DrawPixelScale but always includes the
	// "retina" factor; this is mostly useful for drawing "chunky" 1
	// pixel-wide lines and the like.
	DPIScale float32

	Renderer  renderer.Renderer
	Mouse     *platform.MouseState
	Keyboard  *platform.KeyboardState
	HaveFocus bool
	Now       time.Time
	Lg        *log.Logger

	MenuBarHeight float32
	AudioEnabled  *bool

	KeyboardFocus KeyboardFocus

	ControlClient *sim.ControlClient
}

func (*Context) InitializeMouse

func (ctx *Context) InitializeMouse(fullDisplayExtent math.Extent2D, p platform.Platform)

func (*Context) SetWindowCoordinateMatrices

func (ctx *Context) SetWindowCoordinateMatrices(cb *renderer.CommandBuffer)

type DisplayNode

type DisplayNode struct {
	// non-nil only for leaf nodes: iff splitAxis == SplitAxisNone
	Pane      Pane
	SplitLine SplitLine
	// non-nil only for interior notes: iff splitAxis != SplitAxisNone
	Children [2]*DisplayNode
}

DisplayNode represents a node in the Pane display hierarchy, which is a kd-tree.

func NewDisplayPanes

func NewDisplayPanes(stars, messages, fsp Pane) *DisplayNode

func (*DisplayNode) FindPaneForMouse

func (d *DisplayNode) FindPaneForMouse(displayExtent math.Extent2D, p [2]float32,
	plat platform.Platform) Pane

FindPaneForMouse returns the Pane that the provided mouse position p is inside.

func (*DisplayNode) MarshalJSON

func (d *DisplayNode) MarshalJSON() ([]byte, error)

MarshalJSON is called when a DisplayNode is to be marshaled into JSON. Here we instead marshal out a TypedDisplayNodePane that also stores the Pane's type.

func (*DisplayNode) NodeForPane

func (d *DisplayNode) NodeForPane(pane Pane) *DisplayNode

NodeForPane searches a display node hierarchy for a given Pane, returning the associated DisplayNode.

func (*DisplayNode) ParentNodeForPane

func (d *DisplayNode) ParentNodeForPane(pane Pane) (*DisplayNode, int)

ParentNodeForPane returns both the DisplayNode one level up the hierarchy from the specified Pane and the index into the children nodes for that node that leads to the specified Pane.

func (*DisplayNode) SplitX

func (d *DisplayNode) SplitX(x float32, newChild *DisplayNode) *DisplayNode

SplitX returns a new DisplayNode that is the result of splitting the provided node horizontally direction at the specified offset (which should be between 0 and 1), storing the node as the new node's first child, and storing newChild as the's second child.

func (*DisplayNode) SplitY

func (d *DisplayNode) SplitY(y float32, newChild *DisplayNode) *DisplayNode

SplitY returns a new DisplayNode from splitting the provided node vertically, analogous to the SplitX method.

func (*DisplayNode) String

func (d *DisplayNode) String() string

func (*DisplayNode) UnmarshalJSON

func (d *DisplayNode) UnmarshalJSON(s []byte) error

UnmarshalJSON unmarshals text into a DisplayNode; its main task is to use the type sting that comes along in the TypedDisplayNodePane to determine which Pane type to unmarshal the Pane's member variables into.

func (*DisplayNode) VisitPanes

func (d *DisplayNode) VisitPanes(visit func(Pane))

VisitPanes visits all of the Panes in a DisplayNode hierarchy, calling the provided callback function for each one.

func (*DisplayNode) VisitPanesWithBounds

func (d *DisplayNode) VisitPanesWithBounds(displayExtent math.Extent2D, parentDisplayExtent math.Extent2D, p platform.Platform,
	visit func(math.Extent2D, math.Extent2D, Pane))

VisitPanesWithBounds visits all of the panes in a DisplayNode hierarchy, giving each one both its own bounding box in window coordinates as well the bounding box of its parent node in the DisplayNodeTree.

type EmptyPane

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

func NewEmptyPane

func NewEmptyPane() *EmptyPane

func (*EmptyPane) Activate

func (*EmptyPane) CanTakeKeyboardFocus

func (ep *EmptyPane) CanTakeKeyboardFocus() bool

func (*EmptyPane) Draw

func (ep *EmptyPane) Draw(ctx *Context, cb *renderer.CommandBuffer)

func (*EmptyPane) Hide

func (ep *EmptyPane) Hide() bool

func (*EmptyPane) LoadedSim added in v0.11.5

func (ep *EmptyPane) LoadedSim(client *sim.ControlClient, ss sim.State, pl platform.Platform, lg *log.Logger)

func (*EmptyPane) ResetSim added in v0.11.5

func (ep *EmptyPane) ResetSim(client *sim.ControlClient, ss sim.State, pl platform.Platform, lg *log.Logger)

type FlightStripPane

type FlightStripPane struct {
	FontSize int

	HideFlightStrips          bool
	AutoAddDepartures         bool
	AutoAddArrivals           bool
	AutoAddOverflights        bool
	AutoAddTracked            bool
	AutoAddAcceptedHandoffs   bool
	AutoRemoveDropped         bool
	AutoRemoveHandoffs        bool
	AddPushed                 bool
	CollectDeparturesArrivals bool

	// computer id number: 000-999
	CIDs          map[string]int
	AllocatedCIDs map[int]interface{}

	// estimated departure/arrival or coordination time, depending
	AircraftTimes map[string]time.Time
	// contains filtered or unexported fields
}

func NewFlightStripPane

func NewFlightStripPane() *FlightStripPane

func (*FlightStripPane) Activate

func (fsp *FlightStripPane) Activate(r renderer.Renderer, p platform.Platform, eventStream *sim.EventStream, lg *log.Logger)

func (*FlightStripPane) CanTakeKeyboardFocus

func (fsp *FlightStripPane) CanTakeKeyboardFocus() bool

func (*FlightStripPane) DisplayName

func (fsp *FlightStripPane) DisplayName() string

func (*FlightStripPane) Draw

func (fsp *FlightStripPane) Draw(ctx *Context, cb *renderer.CommandBuffer)

func (*FlightStripPane) DrawUI

func (fsp *FlightStripPane) DrawUI(p platform.Platform, config *platform.Config)

func (*FlightStripPane) Hide

func (fsp *FlightStripPane) Hide() bool

func (*FlightStripPane) LoadedSim added in v0.11.5

func (fsp *FlightStripPane) LoadedSim(client *sim.ControlClient, ss sim.State, pl platform.Platform, lg *log.Logger)

func (*FlightStripPane) ResetSim added in v0.11.5

func (fsp *FlightStripPane) ResetSim(client *sim.ControlClient, ss sim.State, pl platform.Platform, lg *log.Logger)

type KeyboardFocus

type KeyboardFocus interface {
	Take(p Pane)
	TakeTemporary(p Pane)
	Release()
	Current() Pane
}

type Message

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

func (*Message) Color

func (msg *Message) Color() renderer.RGB

type MessagesPane

type MessagesPane struct {
	FontIdentifier renderer.FontIdentifier
	// contains filtered or unexported fields
}

func NewMessagesPane

func NewMessagesPane() *MessagesPane

func (*MessagesPane) Activate

func (mp *MessagesPane) Activate(r renderer.Renderer, p platform.Platform, eventStream *sim.EventStream, lg *log.Logger)

func (*MessagesPane) CanTakeKeyboardFocus

func (mp *MessagesPane) CanTakeKeyboardFocus() bool

func (*MessagesPane) DisplayName

func (mp *MessagesPane) DisplayName() string

func (*MessagesPane) Draw

func (mp *MessagesPane) Draw(ctx *Context, cb *renderer.CommandBuffer)

func (*MessagesPane) DrawUI

func (mp *MessagesPane) DrawUI(p platform.Platform, config *platform.Config)

func (*MessagesPane) Hide

func (mp *MessagesPane) Hide() bool

func (*MessagesPane) LoadedSim added in v0.11.5

func (mp *MessagesPane) LoadedSim(client *sim.ControlClient, ss sim.State, pl platform.Platform, lg *log.Logger)

func (*MessagesPane) ResetSim added in v0.11.5

func (mp *MessagesPane) ResetSim(client *sim.ControlClient, ss sim.State, pl platform.Platform, lg *log.Logger)

type Pane

type Pane interface {
	// Activate is called once at startup time; it should do general,
	// Sim-independent initialization.
	Activate(r renderer.Renderer, p platform.Platform, eventStream *sim.EventStream, lg *log.Logger)

	// LoadedSim is called when vice is restarted and a Sim is loaded from disk.
	LoadedSim(client *sim.ControlClient, ss sim.State, pl platform.Platform, lg *log.Logger)

	// ResetSim is called when a brand new Sim is launched
	ResetSim(client *sim.ControlClient, ss sim.State, pl platform.Platform, lg *log.Logger)

	CanTakeKeyboardFocus() bool
	Hide() bool
	Draw(ctx *Context, cb *renderer.CommandBuffer)
}

Panes (should) mostly operate in window coordinates: (0,0) is lower left, just in their own pane, oblivious to the full window size. Higher level code will handle positioning the panes in the main window.

func UnmarshalPane

func UnmarshalPane(paneType string, data []byte) (Pane, error)

type PaneUpgrader

type PaneUpgrader interface {
	Upgrade(prev, current int)
}

type ScrollBar

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

ScrollBar provides functionality for a basic scrollbar for use in Pane implementations. (Since those are not handled by imgui, we can't use imgui's scrollbar there.)

func NewVerticalScrollBar

func NewVerticalScrollBar(width int, invert bool) *ScrollBar

NewVerticalScrollBar returns a new ScrollBar instance with the given width. invert indicates whether the scrolled items are drawn from the bottom of the Pane or the top; invert should be true if they are being drawn from the bottom.

func (*ScrollBar) Draw

func (sb *ScrollBar) Draw(ctx *Context, cb *renderer.CommandBuffer)

Draw emits the drawing commands for the scrollbar into the provided CommandBuffer.

func (*ScrollBar) Offset

func (sb *ScrollBar) Offset() int

Offset returns the offset into the items at which drawing should start (i.e., the items before the offset are offscreen.) Note that the scroll offset is reported in units of the number of items passed to Update; thus, if scrolling text, the number of items might be measured in lines of text, or it might be measured in scanlines. The choice determines whether scrolling happens at the granularity of entire lines at a time or is continuous.

func (*ScrollBar) PixelExtent

func (sb *ScrollBar) PixelExtent() int

func (*ScrollBar) Update

func (sb *ScrollBar) Update(nItems int, nVisible int, ctx *Context)

Update should be called once per frame, providing the total number of things being drawn, the number of them that are visible, and the Context passed to the Pane's Draw method (so that mouse events can be handled, if appropriate.

func (*ScrollBar) Visible

func (sb *ScrollBar) Visible() bool

Visible indicates whether the scrollbar will be drawn (it disappears if all of the items can fit onscreen.)

type SplitLine

type SplitLine struct {
	// Offset in [0,1] with respect to the parent Pane's bounds.
	Pos  float32
	Axis SplitType
}

SplitLine represents a line separating two Panes in the display hierarchy. It implements the Pane interface, which simplifies some of the details of drawing and interacting with the display hierarchy.

func (*SplitLine) Activate

func (*SplitLine) CanTakeKeyboardFocus

func (s *SplitLine) CanTakeKeyboardFocus() bool

func (*SplitLine) Deactivate

func (s *SplitLine) Deactivate()

func (*SplitLine) Draw

func (s *SplitLine) Draw(ctx *Context, cb *renderer.CommandBuffer)

func (*SplitLine) Hide

func (s *SplitLine) Hide() bool

func (*SplitLine) LoadedSim added in v0.11.5

func (*SplitLine) ResetSim added in v0.11.5

type SplitType

type SplitType int

type TypedDisplayNodePane

type TypedDisplayNodePane struct {
	DisplayNode
	Type string
}

TypedDisplayNodePane helps with marshaling to and unmarshaling from JSON, which is how the configuration and settings are saved between sessions. Most of this works out pretty much for free thanks to go's JSON support and ability to automatically inspect and serialize structs. The one messy bit is that when we save the DisplayNode hierarchy, although the public member variables of Panes are automatically serialized, the types of the Panes are not. Therefore, we instead marshal/unmarshal TypedDisplayNodePane instances, which carry along a string representation of the associated Pane type stored at a DisplayNode.

type UIDrawer

type UIDrawer interface {
	DisplayName() string
	DrawUI(p platform.Platform, config *platform.Config)
}

type WMKeyboardFocus

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

func (*WMKeyboardFocus) Current

func (f *WMKeyboardFocus) Current() Pane

func (*WMKeyboardFocus) Release

func (f *WMKeyboardFocus) Release()

func (*WMKeyboardFocus) Take

func (f *WMKeyboardFocus) Take(p Pane)

func (*WMKeyboardFocus) TakeTemporary

func (f *WMKeyboardFocus) TakeTemporary(p Pane)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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