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

Fixes #3366 - Add ability to disable AutoSize #3402

Merged
merged 3 commits into from
Apr 14, 2024

Conversation

tznind
Copy link
Collaborator

@tznind tznind commented Apr 13, 2024

Fixes

Proposed Changes/Todos

Adds a static variable that allows disableing AutoSize.

Disables AutoSize instead of throwing Exception when setting Width/Height on a View

Currently the designer emits code as follows:

 this.lblLoading = new Terminal.Gui.Label();
 this.lblLoading.Data = "lblLoading";
 this.lblLoading.Text = "Please wait ...";
 this.lblLoading.Width = 36;
 this.lblLoading.Height = 1;
 this.lblLoading.X = 1;
 this.lblLoading.Y = 1;
 this.lblLoading.TextAlignment = TextAlignment.Left;
 this.Add(this.lblLoading);

I looked into adding AutoSize = false on every single view generated and every piece of code emitted. That kinda worked but was ugly. Then I realized I had to update all my existing .Designer.cs files code with this AutoSize=false too.

I think this is a better solution, the ability to disable autosize across the board.

This can be removed once AutoSize itself is removed.

Pull Request checklist:

  • I've named my PR in the form of "Fixes #issue. Terse description."
  • My code follows the style guidelines of Terminal.Gui - if you use Visual Studio, hit CTRL-K-D to automatically reformat your files before committing.
  • My code follows the Terminal.Gui library design guidelines
  • I ran dotnet test before commit
  • I have made corresponding changes to the API documentation (using /// style comments)
  • My changes generate no new warnings
  • I have checked my code and corrected any poor grammar or misspellings
  • I conducted basic QA to assure all features are working

@tznind tznind requested a review from tig as a code owner April 13, 2024 14:08
@tig
Copy link
Collaborator

tig commented Apr 13, 2024

Love.

I'll look deeper later today.

@tig
Copy link
Collaborator

tig commented Apr 13, 2024

I have a better idea. Now that the exception I put in has weeded out all/most code that is incorrect, we can remove it and instead just change AutoSize to false:

    public Dim Width
    {
        get => VerifyIsInitialized (_width, nameof (Width));
        set
        {
            if (Equals (_width, value))
            {
                return;
            }

            _width = value ?? throw new ArgumentNullException (nameof (value), @$"{nameof (Width)} cannot be null");

            if (AutoSize)
            {
                Debug.WriteLine (@$"Must set AutoSize to false before setting {nameof (Width)}.");
                AutoSize = false;
            }

            bool isValidNewAutoSize = AutoSize && IsValidAutoSizeWidth (_width);

            if (IsAdded && AutoSize && !isValidNewAutoSize)
            {
                Debug.WriteLine (@$"Must set AutoSize to false before setting {nameof (Width)}.");
                AutoSize = false;
            }

            OnResizeNeeded ();
        }
    }

If I do this, all unit tests pass and I see no functional issues in some light tests...

@tznind
Copy link
Collaborator Author

tznind commented Apr 13, 2024

we can remove it and instead just change AutoSize to false

Works for me! Although when I remove the lines (in Button etc) setting AutoSize = true I do get unit test failures.

@tznind
Copy link
Collaborator Author

tznind commented Apr 13, 2024

Ah I see how you mean. Replace the exception with AutoSize = false; Yeah that would work nicely.

@tznind
Copy link
Collaborator Author

tznind commented Apr 14, 2024

@tig I have changed this PR to do as you suggest (Set AutoSize=false instead of throw Exception).

Please let me know if I have misunderstood.

tznind added a commit to gui-cs/TerminalGuiDesigner that referenced this pull request Apr 14, 2024
Further work requires updating once gui-cs/Terminal.Gui#3402 is merged and published
@tig tig merged commit 78bde18 into gui-cs:v2_develop Apr 14, 2024
1 check passed
@tznind tznind deleted the disable-autosize branch April 14, 2024 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants