question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

View should not turn off AutoSize (in setting Width and/or Height)

See original GitHub issue

Describe the bug In https://github.com/migueldeicaza/gui.cs/pull/1685 from @BDisp, there’s this commit:

Commit a82ac45843d6153f10d7c545721d4aeabb75266d
Author: BDisp <bd.bdisp@gmail.com>
Date: Friday, April 29, 2022 5:12 PM
Parent: 933a1bda

Fixes AutoSize, Window Tile and added option to Border for fill or not.

https://github.com/migueldeicaza/gui.cs/pull/1685/files#diff-4a82080ff9e808d1867c94cdd6ac106755bd80a81509546e43f154aed1fe90deR572

		/// <summary>
		/// Gets or sets the width of the view. Only used the <see cref="LayoutStyle"/> is <see cref="LayoutStyle.Computed"/>.
		/// </summary>
		/// <value>The width.</value>
		/// <remarks>
		/// If <see cref="LayoutStyle"/> is <see cref="LayoutStyle.Absolute"/> changing this property has no effect and its value is indeterminate. 
		/// </remarks>
		public Dim Width {
			get => width;
			set {
				if (!ValidatePosDim (width, value)) {
					throw new ArgumentException ();
				}

				width = value;
				if (autoSize && value.Anchor (0) != TextFormatter.Size.Width) {
					autoSize = false;
				}
				SetNeedsLayout ();
				if (width is Dim.DimAbsolute) {
					frame = new Rect (frame.X, frame.Y, width.Anchor (0), frame.Height);
				}
				TextFormatter.Size = frame.Size;
				SetNeedsDisplay (frame);
			}
		}

See how AutoSize is set to false? This breaks code where a Button (or any View) has been set to autosize and then has it’s text changed and the view has been moved (e.g. in the new Dialog code for justifying buttons).

I found this in coding up Wizard. I noticed that when I changed the text of the NextFinished button from Next... to Finished (which is longer) the button did not resize. A workaround is to re-set AutoSize to true when changing the text, but this should not be needed (and will not work in other scenarios).

This Unit Test should be added once this bug is fixed:

		[Fact, AutoInitShutdown]
		public void AutoSize_Stays_True ()
		{
			var btn = new Button () {
				X = Pos.Center (),
				Y = Pos.Center (),
				Text = "Say Hello δ½ ",
				AutoSize = true
			};

			var win = new Window () {
				Width = Dim.Fill (),
				Height = Dim.Fill (),
				Title = "Test Demo δ½ "
			};
			win.Add (btn);
			Application.Top.Add (win);

			Assert.True (btn.AutoSize);

			Application.Begin (Application.Top);
			((FakeDriver)Application.Driver).SetBufferSize (30, 5);
			var expected = @"
β”Œ Test Demo δ½  ──────────────┐
β”‚                            β”‚
β”‚      [ Say Hello δ½  ]      β”‚
β”‚                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
";

			GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);

			Assert.True (btn.AutoSize);
			btn.Width = Dim.Fill ();
			Assert.True (btn.AutoSize);
		}

@BDisp, can you find another way to solve whatever you fixed by doing this?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
tigcommented, Jun 13, 2022

In the current Wizards scenario note how the β€œFinished” button on the last step has an extra space at end:

image

And see SettingFileName() test in WizardTests.cs.

This happens here (in Wizard.cs): image

0reactions
BDispcommented, Jun 13, 2022
				if (autoSize && value.Anchor (0) != TextFormatter.Size.Width) {
					autoSize = false;
				}

As you can see the autosize only will changed to false if the value.Anchor (0) != TextFormatter.Size.Width. Since the Button.Update handles the TextFormatter.Size before changing the Button.Width, thus the condition always return false. If this happens different in your case, specify where so that I can analyze?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting only `width` when using `autosize: fit` should not ...
The height is set the default config.view.height of 200 , but I'd expect this chart to only "fit" the width (since that is...
Read more >
WPF disable window auto resize
You can set the size (fix size) of your window in its load event when the window got its width and height based...
Read more >
How to stop auto resizing of ExB based off of screen size
Is there something I can do in ExB to stop the autoresizing? They would prefer to have to scroll to see the rest...
Read more >
Can't resize Text Field's width/height
Solved: Hey, for some reason XD won't allow me change the height/width of a text field anymore. When accessing previous project's textΒ ...
Read more >
Turning Off Auto-Size Column Width in Microsoft Power BI
Thanks, Fred Kaffenberger, for sharing your tip with me for the Matrix visual in Microsoft Power BI. Check out this video to see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found