()
| 114 | } |
| 115 | |
| 116 | func (fm *Form) Init() { |
| 117 | fm.Frame.Init() |
| 118 | fm.Styler(func(s *styles.Style) { |
| 119 | s.Align.Items = styles.Center |
| 120 | if fm.Inline { |
| 121 | return |
| 122 | } |
| 123 | s.Display = styles.Grid |
| 124 | if fm.SizeClass() == SizeCompact { |
| 125 | s.Columns = 1 |
| 126 | } else { |
| 127 | s.Columns = 2 |
| 128 | } |
| 129 | }) |
| 130 | |
| 131 | fm.Maker(func(p *tree.Plan) { |
| 132 | if reflectx.AnyIsNil(fm.Struct) { |
| 133 | return |
| 134 | } |
| 135 | |
| 136 | fm.getStructFields() |
| 137 | |
| 138 | sc := true |
| 139 | if len(NoSentenceCaseFor) > 0 { |
| 140 | sc = !noSentenceCaseForType(types.TypeNameValue(fm.Struct)) |
| 141 | } |
| 142 | |
| 143 | for i, f := range fm.structFields { |
| 144 | label := f.path |
| 145 | if sc { |
| 146 | label = strcase.ToSentence(label) |
| 147 | } |
| 148 | if lt, ok := f.field.Tag.Lookup("label"); ok { |
| 149 | label = lt |
| 150 | } |
| 151 | labnm := fmt.Sprintf("label-%s", f.path) |
| 152 | // we must have a different name for different types |
| 153 | // so that the widget can be re-made for a new type |
| 154 | typnm := reflectx.ShortTypeName(f.field.Type) |
| 155 | // we must have a different name for invalid values |
| 156 | // so that the widget can be re-made for valid values |
| 157 | if !reflectx.Underlying(f.value).IsValid() { |
| 158 | typnm = "invalid" |
| 159 | } |
| 160 | valnm := fmt.Sprintf("value-%s-%s", f.path, typnm) |
| 161 | readOnlyTag := f.field.Tag.Get("edit") == "-" |
| 162 | def, hasDef := f.field.Tag.Lookup("default") |
| 163 | |
| 164 | var labelWidget *Text |
| 165 | var valueWidget Value |
| 166 | |
| 167 | tree.AddAt(p, labnm, func(w *Text) { |
| 168 | labelWidget = w |
| 169 | w.Styler(func(s *styles.Style) { |
| 170 | s.SetTextWrap(false) |
| 171 | }) |
| 172 | doc, _ := types.GetDoc(f.value, f.parent, f.field, label) |
| 173 | w.SetTooltip(doc) |
nothing calls this directly
no test coverage detected