Skip to content
Randall C. O'Reilly edited this page Jan 25, 2024 · 1 revision

GoGi makes use of struct field tags to influence the GUI behavior. This is a very powerful paradigm for customizing the display and behavior of your structs.

Per https://github.com/asaskevich/govalidator, we adopt the convention of separating elements within a single tag with commas, and no spaces.

The ValueView framework in the giv sub-package (see Views) is the primary place where these tags are used. All ValueView types can access the tag of the element they are representing via the ViewTag method (FieldTag is a method on ki.Ki for accessing the field tag of the Ki elements directly -- the View version accesses the type information for the viewed struct). View tags can also be set directly (overriding field tags if redundant) for non-struct fields, using the SetTag(s) methods.

General

  • desc -- used by StructView to display a tooltip for that element -- all GoKi code uses desc to document struct fields. Content is just raw text -- can include HTML-style formatting tags for special effect.
  • view -- general tag for controlling the display -- can be used for more specific cases as shown below, for options that specifically control how an item is displayed
    • "-" -- don't display this field
    • "no-inline" -- prevent this field from being inlined -- can also set this as a type property using kit type registry: "no-inline": true
    • "inline" -- force the field to be inlined, regardless of number of elements (if > 6 fields / elements then not inlined by default) -- can also set this as a type property using kit type registry: "inline": true
    • "add-fields" -- when field is a struct, the fields of that sub-struct will be added directly into parent struct edit.
  • viewif:"expr" -- conditional display of field -- if expr evaluates to true, then it is shown, otherwise not. expr is a basic expression involving other fields on the struct, e.g.:
    • BoolField or !BoolField -- BoolField is a bool valued field
    • ValField=val (or ==) or ValField=[val1,val2] for multiple alternative options, or ValField!=val etc -- evaluates ValField as a string and compares literal string value with list of values -- if any match then shown (or not in case of !=)
    • Any above expr can be combined with && or || logical AND, OR, and prefixed with ! to negate.
  • inactive:"+" -- the widget for this field is set to Inactive (i.e., read-only, display-only, non-interactive)
  • def:"val1[,val2,...]" or def:"val1:val2" -- First case compares string value of field to given value(s) (literal string compare) and if it doesn't match, then field label is highlighted as having a non-default value. The second only applies to numerical inputs, where the value must be within the range defined by the two values (inclusive).
  • width:"chars" height:"ems" -- sets the minimum and preferred width / height for text field editor of item, in "ex" character width units or "em" height units
  • max-width:"-1 or chars", max-height:"-1 or chars" -- sets max-width / max-height in "ex" (width) or "em" (height) units -- if -1, then field will stretch to all avail space

Validation, limits in TextField and SpinBox

IconName

  • view:"show-name" -- shows the name of the Icon in addition to the actual icon itself.

TableView

  • tableview
    • "-" -- don't show this field in TableView
    • "-select" -- don't show field when viewed in select-only (Inactive) mode
    • "-edit" -- don't show field when in edit (non-Inactive, normal) mode
  • fixed-len:"true" -- don't show + / add buttons

SliceView

  • fixed-len:"true" -- don't show + / add buttons

StructView

  • "changeflag:"+" -- marks field, which must be a bool type, as being set whenever any of the other fields in the struct are edited (i.e., that field serves as a change flag).

  • StructViewFields can be set as a type property, to change the tags for fields "inherited" from embedded types, e.g., this will hide all of the ki.Node fields:

"StructViewFields": ki.Props{ // hide in view
	"UniqueNm": `view:"-"`,
	"Flag":     `view:"-"`,
	"Kids":     `view:"-"`,
	"Props":    `view:"-"`,
},

reflect.Type

  • type-embeds:"TypeName" -- specifies the minimum type, and shows a chooser with all types that embed that type.
Clone this wiki locally