func (cb ComboBox) Create(builder *Builder) error { if _, ok := cb.Model.([]string); ok && (cb.BindingMember != "" || cb.DisplayMember != "") { return errors.New("ComboBox.Create: BindingMember and DisplayMember must be empty for []string models.") } var w *walk.ComboBox var err error if cb.Editable { w, err = walk.NewComboBox(builder.Parent()) } else { w, err = walk.NewDropDownBox(builder.Parent()) } if err != nil { return err } return builder.InitWidget(cb, w, func() error { w.SetFormat(cb.Format) w.SetPrecision(cb.Precision) w.SetMaxLength(cb.MaxLength) if err := w.SetBindingMember(cb.BindingMember); err != nil { return err } if err := w.SetDisplayMember(cb.DisplayMember); err != nil { return err } if err := w.SetModel(cb.Model); err != nil { return err } if cb.OnCurrentIndexChanged != nil { w.CurrentIndexChanged().Attach(cb.OnCurrentIndexChanged) } if cb.AssignTo != nil { *cb.AssignTo = w } return nil }) }
func NewDropDownBox(parent walk.Container, text string, width, height, x, y int) *DropDownBox { b := new(DropDownBox) b.ComboBox, _ = walk.NewDropDownBox(parent) b.SetWidth(width) b.SetHeight(height) b.SetY(y) b.SetX(x) b.model = NewDropDownBoxModel() b.SetModel(b.model) return b }