View should not turn off AutoSize (in setting Width and/or Height)
See original GitHub issueDescribe 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.
/// <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:
- Created a year ago
- Comments:13
Top GitHub Comments
In the current Wizards scenario note how the βFinishedβ button on the last step has an extra space at end:
And see
SettingFileName()
test inWizardTests.cs
.This happens here (in
Wizard.cs
):As you can see the autosize only will changed to
false
if thevalue.Anchor (0) != TextFormatter.Size.Width
. Since theButton.Update
handles theTextFormatter.Size
before changing theButton.Width
, thus the condition always returnfalse
. If this happens different in your case, specify where so that I can analyze?