Documentation ¶
Overview ¶
Package form is used to divide a 2D area into sections using plans. This reduces some of the code complexity involved in creating form based 2D UIs. Forms are split into sections using arrays of strings where each string character represents a section. For example a form with 4 sections can be created as follows:
// Create a form with plan "ab" // "cd" f := NewForm([]string{"ab", "cd"}, formWidth, formHeight) for cnt, sect := range f.Sections() { x, y, w, h := sect.Bounds() // now use section positions... }
Each section can be queried for its center location and size and is labelled with the corresponding string character from the plan.
Package form is provided as part of the vu (virtual universe) 3D engine.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Form ¶
type Form interface { Resize(w, h int) // Realign sections to the new dimensions. Section(l string) Section // Get Section for plan label l. Sections() []Section // All sections in this form. }
Form organizes a 2D area into sections. Once a form is created, its sections can be queried for their center pixel locations and sizes. Resizing a form updates the section centers and sizes. Form is intended for static layouts where the form parts are added once and never removed.
Form generates layouts based on the given plan.
func New ¶
New creates a form based on a character string plan. The plan visually describes how the form should be partitioned. Some example plans are:
"ab" or "xxaby" "cd" "xxcdy"
Identical adjacent characters create a single section spanning multiple rows and/or columns.
Form guidelines may be set at creation using separate strings as follows:
"gap x y" Gap in pixels x between columns and y between rows. "pad t b l r" Border padding in pixels: top, bottom, left, right. "grabx c" Have column number c use extra horizontal space. "graby r" Have row number r use extra vertical space.
Note that sizes are in pixels. Column and row numbering starts at 0.
type Section ¶
type Section interface { Label() string // Label from plan. At() (x, y float64) // Center location of the section. Size() (w, h float64) // Width and height of the section. Bounds() (x, y, w, h float64) // At() and Size() in one call. In(x, y int) bool // True if x and y are in the section. Offset() (x, y float64) // Bottom left corner. }
Section is part of a form. All section dimensions are in pixels. The section's top left corner is at x, y. The section label is set by the form based on the sections corresponding plan character.