Documentation
¶
Overview ¶
Package prop provides a reflection-based property editing system.
Widgets implement IEnumProperties to expose their configurable properties. The PropertySheet widget displays these properties with auto-generated editors (text fields, checkboxes, etc.) for live editing.
Key types:
- IEnumProperties: interface for exposing editable properties
- IPropertyList: interface for collecting property definitions
- PropertySheet: UI widget that displays and edits object properties
- IPropertyControl: interface for custom property editor widgets
Index ¶
- Constants
- func IsValidPropId(s string) bool
- type CheckBox
- type ColorEdit
- func (this *ColorEdit) Activate()
- func (this *ColorEdit) BindProperty(item *PropertyItem1)
- func (this *ColorEdit) Color() paint.Color
- func (this *ColorEdit) Deactivate()
- func (this *ColorEdit) Draw(g paint.Painter)
- func (this *ColorEdit) Init(self gui.IWidget)
- func (this *ColorEdit) UpdateConfig()
- func (this *ColorEdit) UpdateValue()
- type IEnumProperties
- type IPropertyControl
- type IPropertyList
- type IPropertyView
- type IntEdit
- type Property
- func (prop Property) GetValue() interface{}
- func (prop Property) GetValueStr() string
- func (prop Property) Id() string
- func (prop Property) IsReadOnly() bool
- func (prop Property) SetValue(a interface{})
- func (prop Property) SetValueStr(s string) error
- func (prop Property) String() string
- func (prop Property) Type() reflect.Type
- type PropertyCommand
- type PropertyConfigFile
- func (this *PropertyConfigFile) Inherit() *PropertyConfigFile
- func (this *PropertyConfigFile) InheritName() (s string)
- func (this *PropertyConfigFile) ItemConfig(id string) (*core.TDoc, *PropertyConfigFile)
- func (this *PropertyConfigFile) Save() error
- func (this *PropertyConfigFile) SetInheritName(s string)
- type PropertyItem
- func (this *PropertyItem) CfgHidden() (ret bool)
- func (this *PropertyItem) CfgItemHeight() (height float64)
- func (this *PropertyItem) CfgLabel() (label string)
- func (this *PropertyItem) CfgOrder() (ret int)
- func (this *PropertyItem) CfgReadOnly() (ret bool)
- func (this *PropertyItem) CfgWidgetType() (typ string)
- func (this *PropertyItem) Control() (ret IPropertyControl)
- func (this *PropertyItem) GetValue() interface{}
- func (this *PropertyItem) GetValueStr() string
- func (this *PropertyItem) HasExpander() bool
- func (this *PropertyItem) Id() string
- func (this *PropertyItem) IsExpand() bool
- func (this *PropertyItem) IsMultiValue() bool
- func (this *PropertyItem) IsReadOnly() bool
- func (this *PropertyItem) IsVisible() bool
- func (this *PropertyItem) ItemHeight() float64
- func (this *PropertyItem) Label() string
- func (this *PropertyItem) MultiValueHint() string
- func (this *PropertyItem) SetCfgHidden(b bool)
- func (this *PropertyItem) SetCfgItemHeight(height float64)
- func (this *PropertyItem) SetCfgLabel(label string)
- func (this *PropertyItem) SetCfgOrder(order int)
- func (this *PropertyItem) SetCfgReadOnly(b bool)
- func (this *PropertyItem) SetCfgWidgetType(typ string)
- func (this *PropertyItem) SetValue(a interface{})
- func (this *PropertyItem) SetValueStr(s string) error
- func (this *PropertyItem) String() string
- func (this *PropertyItem) Type() reflect.Type
- func (this *PropertyItem) UpdateControl()
- func (this *PropertyItem) UpdateControlConfig()
- func (this *PropertyItem) UpdateControlValue()
- type PropertyItem1
- type PropertySheet
- func (this *PropertySheet) AddProperty(id string, get, set interface{}) (item *PropertyItem, first bool)
- func (this *PropertySheet) Bind(objs []interface{}, configName string, owner interface{})
- func (this *PropertySheet) Class() string
- func (this *PropertySheet) Clear(owner interface{})
- func (this *PropertySheet) DefaultItemHeight() float64
- func (this *PropertySheet) Draw(g paint.Painter)
- func (this *PropertySheet) Filter() string
- func (this *PropertySheet) Icon() paint.Icon
- func (this *PropertySheet) Init(iw gui.IWidget)
- func (this *PropertySheet) Layout()
- func (this *PropertySheet) LoadSession(doc *core.TDoc) error
- func (this *PropertySheet) OnLeftDown(x, y float64)
- func (this *PropertySheet) RefreshValues()
- func (this *PropertySheet) SaveSession() (doc *core.TDoc, err error)
- func (this *PropertySheet) SetFilter(text string)
- func (this *PropertySheet) SetIcon(icon paint.Icon)
- func (this *PropertySheet) SetTitle(s string)
- func (this *PropertySheet) Title() string
- type TextEdit
- func (this *TextEdit) Activate()
- func (this *TextEdit) BindProperty(item *PropertyItem1)
- func (this *TextEdit) Deactivate()
- func (this *TextEdit) Draw(g paint.Painter)
- func (this *TextEdit) Init(self gui.IWidget)
- func (this *TextEdit) OnEdited(s string)
- func (this *TextEdit) OnSubmit(s string)
- func (this *TextEdit) UpdateConfig()
- func (this *TextEdit) UpdateValue()
Constants ¶
const TagBindingID = "tag"
TagBindingID is the property id an industrial widget registers for the design-time tag that drives it. It is the seam scada.BindScreen resolves a widget's tag through (its bindIndustrial reads TagName()), so the designer, the saved design and the generated code all have to agree on this one id.
Variables ¶
This section is empty.
Functions ¶
func IsValidPropId ¶
IsValidPropId reports whether s is usable as a property id. In this codebase property ids double as display labels, so the rule is intentionally permissive: any non-empty, non-blank string is accepted as long as it contains no control characters. This admits unicode/CJK letters (e.g. "液位"), digits, spaces and punctuation used in labels (e.g. "Show Label", "GPU加速").
Types ¶
type CheckBox ¶
func NewCheckBox ¶
func NewCheckBox() *CheckBox
func (*CheckBox) BindProperty ¶
func (this *CheckBox) BindProperty(item *PropertyItem1)
func (*CheckBox) Deactivate ¶
func (this *CheckBox) Deactivate()
func (*CheckBox) OnCheckChanged ¶
func (this *CheckBox) OnCheckChanged()
func (*CheckBox) UpdateConfig ¶
func (this *CheckBox) UpdateConfig()
func (*CheckBox) UpdateValue ¶
func (this *CheckBox) UpdateValue()
type ColorEdit ¶
ColorEdit is the property-sheet editor for a paint.Color row: it shows the value and drops down the shared gui.ColorPicker to change it.
Without it a color fell through to TextEdit, which could render the value (core.VisualString -> Color.String) but never commit one: parsePropertyValue goes through core.PersistSscan, and fmt has no scanner for a struct, so every edit died with "can't scan type: *paint.Color" and colors were read-only in the designer. The commit here bypasses the string round-trip entirely and hands the typed value to PropertyItem.SetValue.
The color swatch beside the label is drawn by the sheet itself (PropertySheet.drawColorSwatch), so this control draws only the value text and the drop-down arrow — two swatches a splitter apart read as one broken control.
func NewColorEdit ¶
func NewColorEdit() *ColorEdit
func (*ColorEdit) BindProperty ¶
func (this *ColorEdit) BindProperty(item *PropertyItem1)
func (*ColorEdit) Color ¶
Color is the color currently displayed, which is the property's value for an agreeing selection and the zero color for a 多值 row.
func (*ColorEdit) Deactivate ¶
func (this *ColorEdit) Deactivate()
func (*ColorEdit) UpdateConfig ¶
func (this *ColorEdit) UpdateConfig()
func (*ColorEdit) UpdateValue ¶
func (this *ColorEdit) UpdateValue()
type IEnumProperties ¶
type IEnumProperties interface {
EnumProperties(list IPropertyList)
}
用来枚举属性的接口 对象实现这个接口后即可在属性表里显示
type IPropertyControl ¶
type IPropertyControl interface {
gui.IWidget
// 绑定属性, 在创建之后调用
BindProperty(item *PropertyItem1)
// 更新属性值
// 控件从item获取新值并显示
UpdateValue()
// 更新其他配置
// 控件从item读取有用的配置并更新, 例如如下拉选项
UpdateConfig()
// 激活. 获取键盘焦点, 高亮显示
Activate()
// 取消激活, 如果属性值已被用户修改, 则控件应调用item的SetValueByControl
Deactivate()
}
属性表控件应实现的接口
type IPropertyList ¶
type IPropertyList interface {
AddProperty(id string, get, set interface{}) (item *PropertyItem, first bool)
}
属性条目列表
type IPropertyView ¶
type IPropertyView interface {
// 清除属性表, 如果指定了owner, 则只在owner和Bind时候匹配时才清除
// 此接口用来清理属性表中过时的条目
Clear(owner interface{})
// 绑定对象, 显示对象的属性
// 属性视图先清除旧的条目, 然后逐个调用对象的IEnumProperties接口生成新条目
// 同名的条目将合并成一条, 出现类型不匹配等异常时打出警告并跳过相应条目
// 未实现IEnumProperties的对象将被忽略
// owner只用在调用Clear()方法时判断是否需要清除, 没有特殊要求
// 建议把owner设为相应视图, 以免Clear时误清其他视图的属性
Bind(objs []interface{}, cfgName string, owner interface{})
}
属性视图
type IntEdit ¶
type IntEdit struct{ TextEdit }
IntEdit keeps integer values exact (including int64/uint64), rather than converting them through float64. Invalid intermediate text is not submitted; Return/deactivation restores the current property value. Up/Down step by one.
func (*IntEdit) Deactivate ¶
func (edit *IntEdit) Deactivate()
type Property ¶
type Property struct {
// contains filtered or unexported fields
}
属性基本信息的实现
func (Property) GetValue ¶
func (prop Property) GetValue() interface{}
获取属性的值 如果是合并后的属性, 此方法只取第一个对象的值
func (Property) GetValueStr ¶
获取字符串形式的属性值, 如果转换失败, 此函数返回空字符串 如果是合并后的属性, 此方法只取第一个对象的值
func (Property) SetValue ¶
func (prop Property) SetValue(a interface{})
设置属性的值 如果是合并后的属性, 此方法会为所有对象设置新值
func (Property) SetValueStr ¶
设置字符串形式的属性的值, 如果设置失败, 此函数返回错误信息 如果是合并后的属性, 此方法会为所有对象设置新值
type PropertyCommand ¶
type PropertyCommand struct {
// contains filtered or unexported fields
}
修改属性的命令
func (*PropertyCommand) Redo ¶
func (cmd *PropertyCommand) Redo()
func (*PropertyCommand) Text ¶
func (cmd *PropertyCommand) Text() string
func (*PropertyCommand) Undo ¶
func (cmd *PropertyCommand) Undo()
type PropertyConfigFile ¶
type PropertyConfigFile struct {
// contains filtered or unexported fields
}
属性配置文件
func GetPropertyConfigFile ¶
func GetPropertyConfigFile(name string, fallbackToDefault bool) *PropertyConfigFile
func (*PropertyConfigFile) Inherit ¶
func (this *PropertyConfigFile) Inherit() *PropertyConfigFile
func (*PropertyConfigFile) InheritName ¶
func (this *PropertyConfigFile) InheritName() (s string)
func (*PropertyConfigFile) ItemConfig ¶
func (this *PropertyConfigFile) ItemConfig(id string) (*core.TDoc, *PropertyConfigFile)
func (*PropertyConfigFile) Save ¶
func (this *PropertyConfigFile) Save() error
func (*PropertyConfigFile) SetInheritName ¶
func (this *PropertyConfigFile) SetInheritName(s string)
type PropertyItem ¶
type PropertyItem struct {
// contains filtered or unexported fields
}
属性条目的实现
func (*PropertyItem) CfgHidden ¶
func (this *PropertyItem) CfgHidden() (ret bool)
func (*PropertyItem) CfgItemHeight ¶
func (this *PropertyItem) CfgItemHeight() (height float64)
func (*PropertyItem) CfgLabel ¶
func (this *PropertyItem) CfgLabel() (label string)
func (*PropertyItem) CfgOrder ¶
func (this *PropertyItem) CfgOrder() (ret int)
func (*PropertyItem) CfgReadOnly ¶
func (this *PropertyItem) CfgReadOnly() (ret bool)
func (*PropertyItem) CfgWidgetType ¶
func (this *PropertyItem) CfgWidgetType() (typ string)
func (*PropertyItem) Control ¶
func (this *PropertyItem) Control() (ret IPropertyControl)
func (*PropertyItem) GetValue ¶
func (this *PropertyItem) GetValue() interface{}
func (*PropertyItem) GetValueStr ¶
func (this *PropertyItem) GetValueStr() string
func (*PropertyItem) HasExpander ¶
func (this *PropertyItem) HasExpander() bool
func (*PropertyItem) Id ¶
func (this *PropertyItem) Id() string
func (*PropertyItem) IsExpand ¶
func (this *PropertyItem) IsExpand() bool
func (*PropertyItem) IsMultiValue ¶
func (this *PropertyItem) IsMultiValue() bool
IsMultiValue reports whether the bound objects hold different values for this property. Such a row shows multiValueText over an empty editor.
func (*PropertyItem) IsReadOnly ¶
func (this *PropertyItem) IsReadOnly() bool
只读, 属性没有set方法, 或者被配置为只读
func (*PropertyItem) IsVisible ¶
func (this *PropertyItem) IsVisible() bool
func (*PropertyItem) ItemHeight ¶
func (this *PropertyItem) ItemHeight() float64
func (*PropertyItem) Label ¶
func (this *PropertyItem) Label() string
func (*PropertyItem) MultiValueHint ¶
func (this *PropertyItem) MultiValueHint() string
MultiValueHint is the text a control shows in place of a value when the bound objects disagree, and "" when they agree.
func (*PropertyItem) SetCfgHidden ¶
func (this *PropertyItem) SetCfgHidden(b bool)
func (*PropertyItem) SetCfgItemHeight ¶
func (this *PropertyItem) SetCfgItemHeight(height float64)
func (*PropertyItem) SetCfgLabel ¶
func (this *PropertyItem) SetCfgLabel(label string)
func (*PropertyItem) SetCfgOrder ¶
func (this *PropertyItem) SetCfgOrder(order int)
func (*PropertyItem) SetCfgReadOnly ¶
func (this *PropertyItem) SetCfgReadOnly(b bool)
func (*PropertyItem) SetCfgWidgetType ¶
func (this *PropertyItem) SetCfgWidgetType(typ string)
func (*PropertyItem) SetValue ¶
func (this *PropertyItem) SetValue(a interface{})
func (*PropertyItem) SetValueStr ¶
func (this *PropertyItem) SetValueStr(s string) error
设置字符串形式的属性的值, 如果设置失败, 此函数返回错误信息 如果是合并后的属性, 此方法会为所有对象设置新值
func (*PropertyItem) String ¶
func (this *PropertyItem) String() string
func (*PropertyItem) Type ¶
func (this *PropertyItem) Type() reflect.Type
func (*PropertyItem) UpdateControl ¶
func (this *PropertyItem) UpdateControl()
func (*PropertyItem) UpdateControlConfig ¶
func (this *PropertyItem) UpdateControlConfig()
func (*PropertyItem) UpdateControlValue ¶
func (this *PropertyItem) UpdateControlValue()
type PropertyItem1 ¶
type PropertyItem1 struct {
*PropertyItem
}
除了重写部分函数以外, 其他和PropertyItem一致 用于和属性表控件交互
func (*PropertyItem1) SetValue ¶
func (this *PropertyItem1) SetValue(a interface{})
func (*PropertyItem1) SetValueStr ¶
func (this *PropertyItem1) SetValueStr(s string) error
type PropertySheet ¶
type PropertySheet struct {
gui.ScrollArea
// contains filtered or unexported fields
}
属性表视图的实现
func NewPropertySheet ¶
func NewPropertySheet() *PropertySheet
func (*PropertySheet) AddProperty ¶
func (this *PropertySheet) AddProperty(id string, get, set interface{}) (item *PropertyItem, first bool)
func (*PropertySheet) Bind ¶
func (this *PropertySheet) Bind(objs []interface{}, configName string, owner interface{})
func (*PropertySheet) Class ¶
func (this *PropertySheet) Class() string
func (*PropertySheet) Clear ¶
func (this *PropertySheet) Clear(owner interface{})
func (*PropertySheet) DefaultItemHeight ¶
func (this *PropertySheet) DefaultItemHeight() float64
func (*PropertySheet) Draw ¶
func (this *PropertySheet) Draw(g paint.Painter)
func (*PropertySheet) Filter ¶
func (this *PropertySheet) Filter() string
Filter returns the active filter text ("" when unfiltered).
func (*PropertySheet) Icon ¶
func (this *PropertySheet) Icon() paint.Icon
func (*PropertySheet) Init ¶
func (this *PropertySheet) Init(iw gui.IWidget)
func (*PropertySheet) Layout ¶
func (this *PropertySheet) Layout()
func (*PropertySheet) LoadSession ¶
func (this *PropertySheet) LoadSession(doc *core.TDoc) error
func (*PropertySheet) OnLeftDown ¶
func (this *PropertySheet) OnLeftDown(x, y float64)
OnLeftDown handles mouse clicks on category headers to toggle collapse.
func (*PropertySheet) RefreshValues ¶
func (this *PropertySheet) RefreshValues()
RefreshValues updates existing controls after a canvas move/resize or undo. It preserves category/filter state and does not rebuild controls or history.
func (*PropertySheet) SaveSession ¶
func (this *PropertySheet) SaveSession() (doc *core.TDoc, err error)
func (*PropertySheet) SetFilter ¶
func (this *PropertySheet) SetFilter(text string)
SetFilter narrows the sheet to the properties whose label or id matches text (case-insensitive substring); empty text restores every row. A category header goes away with its last matching child and comes back with it. The filter is a view setting and survives Bind/Clear, like the widget palette's (ged/widget-list.go).
func (*PropertySheet) SetIcon ¶
func (this *PropertySheet) SetIcon(icon paint.Icon)
func (*PropertySheet) SetTitle ¶
func (this *PropertySheet) SetTitle(s string)
func (*PropertySheet) Title ¶
func (this *PropertySheet) Title() string
type TextEdit ¶
func NewTextEdit ¶
func NewTextEdit() *TextEdit
func (*TextEdit) BindProperty ¶
func (this *TextEdit) BindProperty(item *PropertyItem1)
func (*TextEdit) Deactivate ¶
func (this *TextEdit) Deactivate()
func (*TextEdit) Draw ¶
Draw adds the 多值 hint over the empty box a disagreeing selection produces, styled like gui.PathEdit's placeholder. Without it an untouched multi-value row is indistinguishable from a value that really is the empty string.
func (*TextEdit) UpdateConfig ¶
func (this *TextEdit) UpdateConfig()
func (*TextEdit) UpdateValue ¶
func (this *TextEdit) UpdateValue()