-
Notifications
You must be signed in to change notification settings - Fork 693
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
Removing and Re-Adding a MenuBar breaks Width #3136
Comments
This is likely related to the spaghetti code that is "Toplevel". See the issues listed here: #3135 |
I've added your test to #3135 and changed it to this in order to pass for now (use View instead of Window) var w = new View ();
menuBar2 = new Terminal.Gui.MenuBar ();
menuBar = new Terminal.Gui.MenuBar ();
w.Width = Dim.Fill (0);
w.Height = Dim.Fill (0);
w.X = 0;
w.Y = 0;
w.Visible = true;
//w.Modal = false; |
The affecting code is the internal void RemoveMenuStatusBar (View view)
{
if (view is MenuBar) {
//MenuBar?.Dispose ();
MenuBar = null;
}
if (view is StatusBar) {
//StatusBar?.Dispose ();
StatusBar = null;
}
} The ///<inheritdoc/>
public override void Remove (View view)
{
RemoveMenuStatusBar (view);
base.Remove (view);
} Unit test for the [Fact]
public void RemoveAndThenAddStatusBar_ShouldNotChangeWidth ()
{
StatusBar statusBar;
StatusBar statusBar2;
var w = new Window ();
statusBar2 = new StatusBar () { Id = "statusBar2" };
statusBar = new StatusBar () { Id = "statusBar" };
w.Width = Dim.Fill (0);
w.Height = Dim.Fill (0);
w.X = 0;
w.Y = 0;
w.Visible = true;
w.Modal = false;
w.Title = "";
statusBar.Width = Dim.Fill (0);
statusBar.Height = 1;
statusBar.X = 0;
statusBar.Y = 0;
statusBar.Visible = true;
w.Add (statusBar);
Assert.Equal (w.StatusBar, statusBar);
statusBar2.Width = Dim.Fill (0);
statusBar2.Height = 1;
statusBar2.X = 0;
statusBar2.Y = 4;
statusBar2.Visible = true;
w.Add (statusBar2);
Assert.Equal (w.StatusBar, statusBar2);
var menuBars = w.Subviews.OfType<StatusBar> ().ToArray ();
Assert.Equal (2, menuBars.Length);
Assert.Equal (Dim.Fill (0), menuBars [0].Width);
Assert.Equal (Dim.Fill (0), menuBars [1].Width);
// Goes wrong here
w.Remove (statusBar);
w.Remove (statusBar2);
w.Add (statusBar);
w.Add (statusBar2);
// These assertions fail
Assert.Equal (Dim.Fill (0), menuBars [0].Width);
Assert.Equal (Dim.Fill (0), menuBars [1].Width);
} |
…works. Fixes `AutoSize` etc... (#3130) * Removes CheckAbsoulte and updates unit tests to match * Fixed code that was dependent on ToString behavior vs. direct test for null * Dim/Pos != null WIP * Moved AutoSize specific tests out of Pos/Dim tests * Broke out AutoSize = false tests to new file * Commented test TODOs * New test * Removed unused API and cleaned up code * Removed unused API and cleaned up code * Cleaned up code * Cleaned up code * reorg'd Toplevel tests * Fixed Create and related unit tests * Added test from #3136 * Removed TopLevel.Create * Fixed SetCurrentOverlappedAsTop * Updated pull request template * Updated pull request template * Revert "Updated pull request template" This reverts commit d807190. * reverting * re-reverting * Fixed every thing but autosize scenarios?? * Fixed hexview * Fixed contextmenu * Fixed more minor issues in tests * Fixed more minor issues in tests * Debugging Dialog test failure * Fixed bad Dialog test. Was cleary invalid * Fixed OnResizeNeeded bug * Fixed OnResizeNeeded bug * Fixed UICatalog to not eat exceptions * Fixed TextView * Removed Frame overrides * Made Frame non-virtual * Fixed radioGroup * Fixed TabView * Hcked ScrolLBarView unit tests to pass * All AutoSize tests pass! * All tests pass!!!!!!! * Updated API docs. Cleaned up code. * Fixed ColorPicker * Added 'Bounds =' unit tests * Refactored TextFormatter.Size setting logic * Cleaned up OnResizeNeeded (api docs and usages) * Merges in #3019 changes. Makes OnResizeNeeded non-virtual. If we find a use-case where someone wants to override it we can change this back. * Fixed FileDialog bounds warning * Removed resharper settings from editorconfig * Added Pos.Center test to AllViewsTests.cs. Modernized RadioGroup. Fixed ProgressBar. * Reverted formatting * Reverted formatting * Reverted formatting * Reverted formatting * Reverted formatting * Reverted formatting * Reverted formatting * Code cleanup * Code cleanup * Code cleanup * Code cleanup * Code cleanup * Code cleanup * Code cleanup * Code cleanup * Reverted formatting
I think that some of what is stated here has already been implemented, right? |
Describe the bug
Removing and Re-Adding a View should not change any of it's size/position parameters.
But for MenuBar it does, it changes
Dim.Fill(0)
toDim.Absolute(0)
Strangely it manifests only for the second menu bar and not the first. Do not understand why but is consistent. I first noticed this in gui-cs/TerminalGuiDesigner#287 .
TerminalGuiDesigner will sometimes remove and re-add a View to a parent. This sometimes is for sensible reasons (e.g. dragging into a new view container). Also sometimes to avoid Exceptions being thrown for changing some properties while mounted. It is important that removing and re-adding does not modify properties (other than parent :) )
The text was updated successfully, but these errors were encountered: