Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Views to expose "Design Time" default data? #3522

Open
tznind opened this issue May 31, 2024 · 3 comments
Open

Enable Views to expose "Design Time" default data? #3522

tznind opened this issue May 31, 2024 · 3 comments
Assignees
Labels
Milestone

Comments

@tznind
Copy link
Collaborator

tznind commented May 31, 2024

By default, many Views have no good visual representation unless set with "data". E.g. ListView, RadioGroup, and Slider.

This Issue is to come up with a design and implementation that allows a "designer" (TGD) or "tester" (AllViewsTester/Unit Tests) component to say to a View "Hey, go into a good demo mode".

My current (probably lame) thinking is we'd do this by defining an interface that a View that supports such a thing could implement:

public interface ISupportsDesignMode
{
   // Call this to tell the View to load "demo data" 
   public bool LoadDemoData ();
}

 

Background

Slider<> is doing strange things when setting it's Text property.

    [Test]
    public void TestTextSliderString()
    {
        var s = new Slider<string>();
        ClassicAssert.IsEmpty(s.Options);

        var s2 = new Slider<string>();
        s2.Text = "I've got a lovely bunch of coconuts";
        ClassicAssert.IsEmpty(s2.Options);
    }

Text should be completely independent from Options.

It seems Text setter is putting data into Options. This is problematic for many reasons. It happens also with the <int> generic. Notice how if you reverse the properties it will have different result.

  • Set Text first and you can overwrite with Options
  • Set Options first and Text overwrites completely the Options
    [Test]
    public void TestTextSliderInt()
    {
        var o = new SliderOption<int>("hi", new System.Text.Rune('d'), 32);
        var s1 = new Slider<int>
        {
            Text = "fff",
            Options = new List<SliderOption<int>> { o }
        };

        Assert.That(s1.Options.Single(), Is.EqualTo(o));

        var s2 = new Slider<int>
        {
            // When order is reversed
            Options = new List<SliderOption<int>> {o },
            Text = "fff",
        };

        // It fails
        Assert.That(s2.Options.Single(),Is.EqualTo(o));
    }
@tig
Copy link
Collaborator

tig commented May 31, 2024

I wanted Slider to work in AllViewsTester so I made setting Text to a comma delimited string equivalent to setting Options.

Feel free to undo this, but I'd live ideas on how to make AllViewsTester support causing Views to be "useful/visible" without having custom logic per-view.

I did the same thing to RadioGroup.

@tznind
Copy link
Collaborator Author

tznind commented Jun 1, 2024

Hmn, I don't think Text should be the place for this. It looks like a string but it behaves like a method.

In general I think properties are not the place for non deterministic behaviours.

Consider the following example:

    [Test]
    public void TestTextSliderString()
    {
        var s1 = new Slider<string>();
        var s2 = new Slider<string>();
        s2.Text = "I've got a lovely bunch of coconuts, here they are sitting in a row!";
     
        // This line does not do what it looks like
        s1.Text = s2.Text;

        TestContext.Out.WriteLine("Options:" + s1.Options.Count); //2
        TestContext.Out.WriteLine("Options:" + s2.Options.Count); //6!

        ClassicAssert.IsTrue(s1.Options.Count == s2.Options.Count );
    }

tznind added a commit to gui-cs/TerminalGuiDesigner that referenced this issue Jun 1, 2024
@BDisp
Copy link
Collaborator

BDisp commented Jun 1, 2024

I think the Text and Title properties should be independent and have no relationship between them. By default, Text will be drawn inside the view, with the exception of custom drawing. The Title should only be used when a view has a border and is not an empty string.

Edit:
This exposition is just to warn you that in this case Options and Text should not have any relationship between them, with the exception that Text can be used to reflect the string that will be displayed relative to the currently selected Options.

@tig tig added the bug label Jun 9, 2024
@tig tig added this to the V2 Beta milestone Jun 9, 2024
@tig tig changed the title Slider<> strange behaviour of Text property Enable Views to expose "Design Time" default data? Jun 26, 2024
@tig tig self-assigned this Jun 26, 2024
tig added a commit that referenced this issue Jul 3, 2024
Fixes #3522. Adds `IDesignable`: Ability for Views to load design-time/demo data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

3 participants