forms

package
v0.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package forms reads and writes descriptions of Golphi forms. A document describes initial values, while application code supplies event handlers.

Index

Constants

View Source
const CurrentVersion = 1

CurrentVersion is the document version supported by this package.

Variables

This section is empty.

Functions

func IsFileDialog

func IsFileDialog(kind string) bool

IsFileDialog reports whether kind names a nonvisual file dialog component.

func Kinds

func Kinds() []string

Kinds returns the supported control names in palette order.

Types

type Control

type Control struct {
	ID            string   `json:"id"`
	GoName        string   `json:"goName,omitempty"`
	Kind          string   `json:"kind"`
	Parent        string   `json:"parent,omitempty"`
	Text          string   `json:"text,omitempty"`
	X             int      `json:"x"`
	Y             int      `json:"y"`
	Width         int      `json:"width"`
	Height        int      `json:"height"`
	Checked       *bool    `json:"checked,omitempty"`
	Items         []string `json:"items,omitempty"`
	SelectedIndex *int     `json:"selectedIndex,omitempty"`
	Patterns      []string `json:"patterns,omitempty"`
}

Control describes one component. For visual controls, Parent names a Panel by ID or is empty for the form. Bounds are relative to that parent in logical units. Items and SelectedIndex apply to ComboBox and ListBox. A nil SelectedIndex leaves the list unselected. A nil Checked means unchecked. For file dialogs, Parent is empty, bounds are zero, Text is the title, and Patterns optionally filters filenames.

type Document

type Document struct {
	Version  int       `json:"version"`
	Title    string    `json:"title"`
	Width    int       `json:"width"`
	Height   int       `json:"height"`
	Controls []Control `json:"controls"`
}

Document describes one form. The order of Controls is preserved when a document is saved and determines the order of siblings in the loaded form.

func Read

func Read(r io.Reader) (*Document, error)

Read decodes and validates a single JSON form document.

func (*Document) AssignGoNames

func (d *Document) AssignGoNames() bool

AssignGoNames fills missing names with the first free names of the form KindN in document order. It retains existing names, including ones assigned to controls later in the document, and reports whether it changed the form.

func (*Document) Build

func (d *Document) Build() (*ui.Form, map[string]ui.Component, error)

Build validates and builds the form without opening a native window. It returns the form and an index of its controls by their document IDs. Callers use the concrete control types to set handlers, then call Form.Run.

func (*Document) Validate

func (d *Document) Validate() error

Validate checks the document without creating Golphi components.

func (*Document) ValidateGoNames

func (d *Document) ValidateGoNames() error

ValidateGoNames checks that all controls can be exposed as distinct fields on a generated form. Legacy documents without names can still be read and built; use AssignGoNames before saving them for generation.

func (*Document) Write

func (d *Document) Write(w io.Writer) error

Write validates the document before writing JSON to w.

Jump to

Keyboard shortcuts

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