Gui.cs: ComboBox assumes constructor initialization; needs to support object initialization

Created on 27 May 2020  Â·  3Comments  Â·  Source: migueldeicaza/gui.cs

If someone is using Computed Layout they have to use the only constructor provided:

    public ComboBox(int x, int y, int w, int h, IList<string> source)

Like this, which is gross:

        var comboBox = new ComboBox (0, 0, 0, 0, new List<string> () { " ~  s  gui.cs   master ↑10" } ) { 
            X = Pos.Right (label) + 1, 
            Y = Pos.Y (label), 
            Width = Dim.Percent (50),
             }

It also appears it was never tested with object initialziation because this causes it to crash:

        var comboBox = new ComboBox (0, 0, 0, 0, new List<string> () { " ~  s  gui.cs   master ↑10" } ) { 
            X = Pos.Right (label) + 1, 
            Y = Pos.Y (label), 
            Width = Dim.Percent (50),
                         Text = "foo",
             }

In general View classes should

  1. Not require use of a parametrized constructor (except when forcing Absolute Layout *)
  2. Avoid doing initialization via constructors. Instead use a property so consumers can use object initialization (e.g. var foo = new Foo() { a = b };).

** We should support specifying absolute coordinates via fields on View

1.0 bug

All 3 comments

@tig please assign this to me. I Have been looking at it, I'm about 70% done with the fix.

@fergusonr Suggest you pull down #586 and #587 as you do this work.

Fix is done. PR #607

Was this page helpful?
0 / 5 - 0 ratings