autoconfig

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 11 Imported by: 0

Image README

autoconfig

Image Go Reference

Autoconfig allows you to edit any Go struct with a Qt interface based on MIQT.

type Foo struct {                []----------------------[]
    Name string                  |  Name:  [___________]  |
}                                |                [Save]  |
                                 []----------------------[]

Usage

Creating a dialog:

// Passed in struct should be a pointer value
var foo MyStruct
autoconfig.OpenDialog(&foo, nil, "Dialog title", func() {
	// The value of 'foo' has been updated
})

Embedding into an existing layout:

var foo MyStruct
saveCallback := autoconfig.MakeConfigArea(&foo, qt6.QFormLayout)

// To save changes from the GUI into the struct, call the saveCallback() function.
// However, warning that nested fields may be mutated automatically without calling.

Only public fields are supported. This is a limitation of the standard library reflect package.

Supported types

  • All Go primitive types
    • string
    • bool
    • int
      • including uintptr, uint, and fixed-width versions
      • A custom QSpinBox is implemented for large bit-width types
    • float
    • complex
    • pointer (optional)
      • struct tags on the pointer are passed in to the child renderer
      • supports Resetter interface to allow resetting to default values
    • slice
    • []byte
      • supports MIME content detection, multiline text editor, and importing and exporting file content
    • fixed-size array
    • map
    • struct
      • child structs by value, and embedded structs, are rendered inline
      • struct tags on the slice are passed in to each child renderer
    • empty struct
  • Standard library types
    • time.Time
  • Custom types
    • AddressPort
    • EnumList
    • ExistingDirectory
    • ExistingFile
    • Header
    • MultilineString
    • Password
    • Any custom type that implements the Renderer interface
  • Custom layouts
    • OneOf
    • TabGroup

Customization

Add struct tags to individual fields to customize the rendering:

Tag Behaviour
ylabel Override label. If not present, the default label is the struct field's name with underscores replaced by spaces.
yenum For "EnumList"; list of dropdown options, separated by double-semicolon (;;)
yfilter For "ExistingFile"; filter to apply in popup dialog
yicon For "OneOf" and "TabGroup"; icon (either from theme, or with :/ prefix for resource icon)
yprefix For int, uint, float types; text to display as a prefix (e.g. "at least")
ysuffix For int, uint, float types; text to display as a suffix (e.g. "%" or "bytes")

Implement these interfaces to customize the rendering:

Interface Behaviour
Resetter May be used with pointer receiver to reset your type to default values, if autoconfig constructed a new version of your type (used by OneOf, pointer, and slice)
Renderer Add a fully custom Qt widget. Use with either value or pointer receiver.
fmt.Stringer May be used to format some types for display

Changelog

2026-01-16 v0.6.0

  • Pointers: Allow resetting any pointer type that implements Resetter
  • Allow scrolling tall dialog boxes
  • Render "xxDir" string struct fields as if they were ExistingDirectory
  • Render "xxPass", "xxPassword" string struct fields as if they were Password
  • Fix overflow for int64 and uint32/64 by implementing custom QSpinBox

2026-01-04 v0.5.0

  • Support map
  • Support fixed-size arrays
  • Support []byte with special handling, including MIME content detection and file import/export
  • Support complex64 and complex128
  • Add TabGroup
  • Add yprefix and ysuffix support for int, uint, and float types
  • Labels: Hide standalone : if a blank label was used
  • Labels: Hide duplicate labels if text was already shown in dialog/tab/dropdown
  • Fix label formatting for strings
  • Show "" as the label formatting for the empty string

2025-12-03 v0.4.1

  • Reduce flicker on Windows by enforcing Qt parent relationship during creation

2025-12-03 v0.4.0

  • Reduce flicker on Windows by setting Qt UpdatesEnabled false during struct calculation
  • OneOf: support Reset()
  • Labels: Support String() on ExistingFile and ExistingDirectory
  • Labels: Support labels on pointer types, with parenthesis
  • Labels: Support labels on structs using OneOf
  • Labels: Automatically convert CamelCase struct names to separated words
  • Struct tags are now passed through to slice and pointer children (e.g. allowing yfilter on *ExistingFile)
  • Use accurate type comparison for time.Time and OneOf, in case of naming conflict in other packages

2025-11-26 v0.3.0

  • BREAKING: Rename InitDefaulter to Resetter, rename Autoconfiger to Renderer
  • Add OneOf
  • Renderer interface now supports being implemented on either value or pointer receiver
  • AddressPort now renders a string description when used in a slice

2025-11-17 v0.2.0

  • Support arbitrary pointers, slices, int, uintptr, float, time.Time
  • Add Header
  • Skip over unsupported types (func, interface, unsafe.Pointer)
  • Fix cosmetic inconsistency when editing types

2025-11-15 v0.1.0

  • Initial public release

Image Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenDialog

func OpenDialog(ct ConfigurableStruct, parent *qt.QWidget, title string, onFinished func())

OpenDialog opens the struct for editing in a new modal dialog in the current global event loop. The dialog only has an "OK" button, you can't cancel your modifications to the supplied struct, the struct saver is always called.

Types

type AddressPort

type AddressPort struct {
	Address string
	Port    int
}

AddressPort allows entering a text address and a numeric port. The port is limited to the 0-65535 range.

func (AddressPort) Render added in v0.3.0

func (AddressPort) Render(area *qt.QFormLayout, rv *reflect.Value, tag reflect.StructTag, label string) SaveFunc

func (AddressPort) String added in v0.3.0

func (a AddressPort) String() string

type ConfigurableStruct

type ConfigurableStruct interface{}

type EnumList

type EnumList int

EnumList allows choosing from a dropdown. The integer value is the 0-based index of available options. Available options should be set in the `yenum` struct tag, separated by ";;".

func (EnumList) Render added in v0.3.0

func (EnumList) Render(area *qt.QFormLayout, rv *reflect.Value, tag reflect.StructTag, label string) SaveFunc

type ExistingDirectory

type ExistingDirectory string

ExistingDirectory allows browsing for an existing directory. The string value is the absolute path to the directory on disk.

func (ExistingDirectory) Render added in v0.3.0

func (ExistingDirectory) Render(area *qt.QFormLayout, rv *reflect.Value, tag reflect.StructTag, label string) SaveFunc

func (ExistingDirectory) String added in v0.4.0

func (e ExistingDirectory) String() string

type ExistingFile

type ExistingFile string

ExistingFile allows browsing for an existing file. The string value is the absolute path to the file on disk. If the `yfilter` struct tag is present, this allows constraining the file types using Qt syntax.

func (*ExistingFile) Render added in v0.3.0

func (*ExistingFile) Render(area *qt.QFormLayout, rv *reflect.Value, tag reflect.StructTag, label string) SaveFunc

func (ExistingFile) String added in v0.4.0

func (f ExistingFile) String() string
type Header struct{}

Header shows a single-line header across the form. Use the `ylabel` tag to set the header's text.

func (Header) Render added in v0.3.0

func (Header) Render(area *qt.QFormLayout, rv *reflect.Value, tag reflect.StructTag, label string) SaveFunc

type MultiLineString

type MultiLineString string

MultiLineString shows a multi-line string area.

func (MultiLineString) Render added in v0.3.0

func (MultiLineString) Render(area *qt.QFormLayout, rv *reflect.Value, tag reflect.StructTag, label string) SaveFunc

type OneOf added in v0.3.0

type OneOf string

If a OneOf is the first member in a struct, the struct rendering will change to allow selecting one of the remaining struct members.

All the remaining struct members must be pointer types.

Each struct member's 'ylabel' tag is used as the dropdown selection's label. Each struct member's 'yicon' tag, if present, is used as the dropdown selection's icon. The icon can either be a theme icon, or (with `:/` prefix) a Qt embedded resource.

When saving, only the selected struct member will be populated; all other values will be set to nil.

type Password

type Password string

Password shows a single-line text area with character masking.

func (Password) Render added in v0.3.0

func (Password) Render(area *qt.QFormLayout, rv *reflect.Value, tag reflect.StructTag, label string) SaveFunc

type Renderer added in v0.3.0

type Renderer interface {
	Render(area *qt.QFormLayout, rv *reflect.Value, tag reflect.StructTag, label string) SaveFunc
}

Renderer is a custom-rendered type that can be interacted with automatically by the autoconfig package.

type Resetter added in v0.3.0

type Resetter interface {
	Reset()
}

Resetter is a type that can reset itself to default values. It's used if autoconfig needs to initialize a child struct.

type SaveFunc

type SaveFunc func()

func MakeConfigArea

func MakeConfigArea(ct ConfigurableStruct, area *qt.QFormLayout) SaveFunc

MakeConfigArea makes a config area by pushing elements into a QFormLayout. Use the returned function to force all changes from the UI to be saved to the struct.

type TabGroup added in v0.5.0

type TabGroup struct{}

If a TabGroup is the first member in a struct, the struct rendering will change to show all remaining fields as tabs.

All the remaining struct members must be non-pointer types.

Each struct member's 'ylabel' tag is used as the tab's label. Each struct member's 'yicon' tag, if present, is used as the tab's icon. The icon can either be a theme icon, or (with `:/` prefix) a Qt embedded resource.

Image Directories

Path Synopsis
This package implements some QSpinBox variants to support different integer bit widths.
This package implements some QSpinBox variants to support different integer bit widths.

Jump to

Keyboard shortcuts

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