Ensure correct Width/Height when orientation is changed.

This commit is contained in:
BDisp
2024-08-17 00:03:54 +01:00
parent 9b896573ec
commit 3386d06c31

View File

@@ -1,4 +1,5 @@
using Terminal.Gui;
using System;
using Terminal.Gui;
namespace UICatalog.Scenarios;
@@ -56,8 +57,13 @@ public class ScrollDemo : Scenario
scrollWidthHeight.ValueChanging += (s, e) =>
{
if (e.NewValue < 1)
if (e.NewValue < 1
|| (e.NewValue
> (scroll.Orientation == Orientation.Vertical
? scroll.SuperView?.GetContentSize ().Width
: scroll.SuperView?.GetContentSize ().Height)))
{
// TODO: This must be handled in the ScrollSlider if Width and Height being virtual
e.Cancel = true;
return;
@@ -93,6 +99,7 @@ public class ScrollDemo : Scenario
scroll.Orientation = Orientation.Vertical;
scroll.X = Pos.AnchorEnd ();
scroll.Y = 0;
scrollWidthHeight.Value = Math.Min (scrollWidthHeight.Value, scroll.SuperView.GetContentSize ().Width);
scroll.Width = scrollWidthHeight.Value;
scroll.Height = Dim.Fill ();
scroll.Size /= 3;
@@ -103,6 +110,8 @@ public class ScrollDemo : Scenario
scroll.X = 0;
scroll.Y = Pos.AnchorEnd ();
scroll.Width = Dim.Fill ();
scrollWidthHeight.Value = Math.Min (scrollWidthHeight.Value, scroll.SuperView.GetContentSize ().Height);
scroll.Height = scrollWidthHeight.Value;
scroll.Size *= 3;
}