Przeglądaj źródła

fixed clipping once and for all

Charlie Kindel 5 lat temu
rodzic
commit
d035fb1116

+ 2 - 2
Example/demo.cs

@@ -30,7 +30,7 @@ static class Demo {
 			throw new NotImplementedException ();
 		}
 
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			//Point pos = new Point (region.X, region.Y);
 			Driver.SetAttribute (ColorScheme.Focus);
@@ -53,7 +53,7 @@ static class Demo {
 		{
 		}
 
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			Driver.SetAttribute (ColorScheme.Focus);
 			var f = Frame;

+ 1 - 1
Terminal.Gui/Core/ConsoleDriver.cs

@@ -5,7 +5,7 @@
 //   Miguel de Icaza ([email protected])
 //
 // Define this to enable diagnostics drawing for Window Frames
-#define DRAW_WINDOW_FRAME_DIAGNOSTICS
+//#define DRAW_WINDOW_FRAME_DIAGNOSTICS
 using NStack;
 using System;
 using System.Runtime.CompilerServices;

+ 3 - 3
Terminal.Gui/Core/Toplevel.cs

@@ -257,18 +257,18 @@ namespace Terminal.Gui {
 		}
 
 		///<inheritdoc cref="Redraw"/>
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			Application.CurrentView = this;
 
 			if (IsCurrentTop || this == Application.Top) {
 				if (NeedDisplay != null && !NeedDisplay.IsEmpty) {
 					Driver.SetAttribute (Colors.TopLevel.Normal);
-					Clear (region);
+					Clear (bounds);
 					Driver.SetAttribute (Colors.Base.Normal);
 				}
 				foreach (var view in Subviews) {
-					if (view.Frame.IntersectsWith (region)) {
+					if (view.Frame.IntersectsWith (bounds)) {
 						view.SetNeedsLayout ();
 						view.SetNeedsDisplay (view.Bounds);
 					}

+ 16 - 19
Terminal.Gui/Core/View.cs

@@ -618,7 +618,7 @@ namespace Terminal.Gui {
 		}
 
 		/// <summary>
-		/// Converts a view-relative (col,row) position to a screen-relative positino (col,row). The values are optionally clamped to the screen dimensions.
+		/// Converts a view-relative (col,row) position to a screen-relative position (col,row). The values are optionally clamped to the screen dimensions.
 		/// </summary>
 		/// <param name="col">View-relative column.</param>
 		/// <param name="row">View-relative row.</param>
@@ -660,11 +660,13 @@ namespace Terminal.Gui {
 			}
 		}
 
-		// Converts a rectangle in view-relative coordinates to screen-relative coordinates.
-		internal Rect RectToScreen (Rect rect)
+		/// <summary>
+		/// Converts a region in view-relative coordinates to screen-relative coordinates.
+		/// </summary>
+		internal Rect ViewToScreen (Rect region)
 		{
-			ViewToScreen (rect.X, rect.Y, out var x, out var y, clipped: false);
-			return new Rect (x, y, rect.Width, rect.Height);
+			ViewToScreen (region.X, region.Y, out var x, out var y, clipped: false);
+			return new Rect (x, y, region.Width, region.Height);
 		}
 
 		// Clips a rectangle in screen coordinates to the dimensions currently available on the screen
@@ -697,9 +699,8 @@ namespace Terminal.Gui {
 		/// <param name="region">View-relative clip region.</param>
 		public Rect SetClip (Rect region)
 		{
-			var bscreen = RectToScreen (region);
 			var previous = Driver.Clip;
-			Driver.Clip = ScreenClip (RectToScreen (Bounds)); 
+			Driver.Clip = Rect.Intersect (previous, ViewToScreen (region));
 			return previous;
 		}
 
@@ -711,7 +712,7 @@ namespace Terminal.Gui {
 		/// <param name="fill">If set to <c>true</c> it fill will the contents.</param>
 		public void DrawFrame (Rect region, int padding = 0, bool fill = false)
 		{
-			var scrRect = RectToScreen (region);
+			var scrRect = ViewToScreen (region);
 			var savedClip = ClipToBounds ();
 			Driver.DrawFrame (scrRect, padding, fill);
 			Driver.Clip = savedClip;
@@ -910,7 +911,7 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// Redraws this view and its subviews; only redraws the views that have been flagged for a re-display.
 		/// </summary>
-		/// <param name="region">The view-relative region to redraw.</param>
+		/// <param name="bounds">The view-relative region to redraw.</param>
 		/// <remarks>
 		/// <para>
 		///    Views should set the color that they want to use on entry, as otherwise this will inherit
@@ -921,28 +922,24 @@ namespace Terminal.Gui {
 		///    larger than the <c>region</c> parameter.
 		/// </para>
 		/// </remarks>
-		public virtual void Redraw (Rect region)
+		public virtual void Redraw (Rect bounds)
 		{
 			var clipRect = new Rect (Point.Empty, frame.Size);
 
 			if (subviews != null) {
 				foreach (var view in subviews) {
 					if (view.NeedDisplay != null && (!view.NeedDisplay.IsEmpty || view.childNeedsDisplay)) {
-						if (view.Frame.IntersectsWith (clipRect) && view.Frame.IntersectsWith (region)) {
+						if (view.Frame.IntersectsWith (clipRect) && view.Frame.IntersectsWith (bounds)) {
 
 							// FIXED: optimize this by computing the intersection of region and view.Bounds
 							if (view.layoutNeeded)
 								view.LayoutSubviews ();
 							Application.CurrentView = view;
 
-							// Ensure we don't make the Driver's clip rect any bigger
-							if (Driver.Clip.IsEmpty || Driver.Clip.Contains(RectToScreen (view.Frame))) {
-								var savedClip = view.ClipToBounds ();
-								view.Redraw (view.Bounds);
-								Driver.Clip = savedClip;
-							} else {
-								view.Redraw (view.Bounds);
-							}
+							// Clip the sub-view
+							var savedClip = ClipToBounds ();
+							view.Redraw (view.Bounds);
+							Driver.Clip = savedClip;
 						}
 						view.NeedDisplay = Rect.Empty;
 						view.childNeedsDisplay = false;

+ 7 - 10
Terminal.Gui/Core/Window.cs

@@ -29,7 +29,7 @@ namespace Terminal.Gui {
 			public ContentView (Rect frame) : base (frame) { }
 			public ContentView () : base () { }
 #if false
-			public override void Redraw (Rect region)
+			public override void Redraw (Rect bounds)
 			{
 				Driver.SetAttribute (ColorScheme.Focus);
 
@@ -159,7 +159,7 @@ namespace Terminal.Gui {
 		{
 			//var padding = 0;
 			Application.CurrentView = this;
-			var scrRect = RectToScreen (new Rect (0, 0, Frame.Width, Frame.Height));
+			var scrRect = ViewToScreen (new Rect (0, 0, Frame.Width, Frame.Height));
 
 			// BUGBUG: Why do we draw the frame twice? This call is here to clear the content area, I think. Why not just clear that area?
 			if (NeedDisplay != null && !NeedDisplay.IsEmpty) {
@@ -167,13 +167,10 @@ namespace Terminal.Gui {
 				Driver.DrawFrame (scrRect, padding, true);
 			}
 
-			if (Driver.Clip.IsEmpty || Driver.Clip.Contains (contentView.RectToScreen (contentView.Frame))) { 
-				var savedClip = ClipToBounds ();
-				contentView.Redraw (contentView.Bounds);
-				Driver.Clip = savedClip;
-			} else {
-				contentView.Redraw (contentView.Bounds);
-			}
+			var savedClip = ClipToBounds ();
+			contentView.Redraw (contentView.Bounds);
+			Driver.Clip = savedClip;
+
 			ClearNeedsDisplay ();
 			Driver.SetAttribute (ColorScheme.Normal);
 			Driver.DrawFrame (scrRect, padding, false);
@@ -204,7 +201,7 @@ namespace Terminal.Gui {
 				if (dragPosition.HasValue) {
 					if (SuperView == null) {
 						Application.Top.SetNeedsDisplay (Frame);
-						Application.Top.Redraw (Frame);
+						Application.Top.Redraw (Bounds);
 					} else {
 						SuperView.SetNeedsDisplay (Frame);
 					}

+ 1 - 1
Terminal.Gui/Views/Button.cs

@@ -152,7 +152,7 @@ namespace Terminal.Gui {
 		}
 
 		///<inheritdoc cref="Redraw(Rect)"/>
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			Driver.SetAttribute (HasFocus ? ColorScheme.Focus : ColorScheme.Normal);
 			Move (0, 0);

+ 1 - 1
Terminal.Gui/Views/Checkbox.cs

@@ -98,7 +98,7 @@ namespace Terminal.Gui {
 		}
 
 		///<inheritdoc cref="Redraw"/>
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			Driver.SetAttribute (HasFocus ? ColorScheme.Focus : ColorScheme.Normal);
 			Move (0, 0);

+ 12 - 8
Terminal.Gui/Views/FrameView.cs

@@ -136,20 +136,24 @@ namespace Terminal.Gui {
 		{
 			var padding = 0;
 			Application.CurrentView = this;
-			var scrRect = RectToScreen (new Rect (0, 0, Frame.Width, Frame.Height));
+			var scrRect = ViewToScreen (new Rect (0, 0, Frame.Width, Frame.Height));
 
 			if (NeedDisplay != null && !NeedDisplay.IsEmpty) {
 				Driver.SetAttribute (ColorScheme.Normal);
 				Driver.DrawFrame (scrRect, padding, true);
 			}
 
-			if (Driver.Clip.IsEmpty || Driver.Clip.Contains (contentView.RectToScreen (contentView.Frame))) {
-				var savedClip = ClipToBounds (); 
-				contentView.Redraw (contentView.Bounds);
-				Driver.Clip = savedClip;
-			} else {
-				contentView.Redraw (contentView.Bounds);
-			}
+			var savedClip = ClipToBounds ();
+			contentView.Redraw (contentView.Bounds);
+			Driver.Clip = savedClip;
+
+			//if (Driver.Clip.IsEmpty || Driver.Clip.Contains (ViewToScreen (contentView.Frame))) { 
+			//	var savedClip = ClipToBounds ();
+			//	contentView.Redraw (contentView.Bounds);
+			//	Driver.Clip = savedClip;
+			//} else {
+			//	contentView.Redraw (contentView.Bounds);
+			//}
 			ClearNeedsDisplay ();
 			Driver.SetAttribute (ColorScheme.Normal);
 			Driver.DrawFrame (scrRect, padding, false);

+ 2 - 2
Terminal.Gui/Views/HexView.cs

@@ -130,7 +130,7 @@ namespace Terminal.Gui {
 		}
 
 		///<inheritdoc cref="Redraw"/>
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			Attribute currentAttribute;
 			var current = ColorScheme.Focus;
@@ -149,7 +149,7 @@ namespace Terminal.Gui {
 
 			for (int line = 0; line < frame.Height; line++) {
 				var lineRect = new Rect (0, line, frame.Width, 1);
-				if (!region.Contains (lineRect))
+				if (!bounds.Contains (lineRect))
 					continue;
 				
 				Move (0, line);

+ 2 - 2
Terminal.Gui/Views/Label.cs

@@ -161,7 +161,7 @@ namespace Terminal.Gui {
 		}
 
 		///<inheritdoc cref="Redraw"/>
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			if (recalcPending)
 				Recalc ();
@@ -173,7 +173,7 @@ namespace Terminal.Gui {
 
 			Clear ();
 			for (int line = 0; line < lines.Count; line++) {
-				if (line < region.Top || line > region.Bottom)
+				if (line < bounds.Top || line > bounds.Bottom)
 					continue;
 				var str = lines [line];
 				int x;

+ 1 - 1
Terminal.Gui/Views/ListView.cs

@@ -272,7 +272,7 @@ namespace Terminal.Gui {
 		}
 
 		///<inheritdoc cref="Redraw(Rect)"/>
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			var current = ColorScheme.Focus;
 			Driver.SetAttribute (current);

+ 3 - 3
Terminal.Gui/Views/Menu.cs

@@ -276,10 +276,10 @@ namespace Terminal.Gui {
 			return ColorScheme.Normal;
 		}
 
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			Driver.SetAttribute (ColorScheme.Normal);
-			DrawFrame (region, padding: 0, fill: true);
+			DrawFrame (bounds, padding: 0, fill: true);
 
 			for (int i = 0; i < barItems.Children.Length; i++) {
 				var item = barItems.Children [i];
@@ -624,7 +624,7 @@ namespace Terminal.Gui {
 		}
 
 		///<inheritdoc cref="Redraw"/>
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			Move (0, 0);
 			Driver.SetAttribute (Colors.Menu.Normal);

+ 2 - 2
Terminal.Gui/Views/RadioGroup.cs

@@ -108,7 +108,7 @@ namespace Terminal.Gui {
 		}
 
 		///<inheritdoc cref="Redraw(Rect)"/>
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			for (int i = 0; i < radioLabels.Length; i++) {
 				Move (0, i);
@@ -116,7 +116,7 @@ namespace Terminal.Gui {
 				Driver.AddStr (i == selected ? "(o) " : "( ) ");
 				DrawHotString (radioLabels [i], HasFocus && i == cursor, ColorScheme);
 			}
-			base.Redraw (region);
+			base.Redraw (bounds);
 		}
 
 		///<inheritdoc cref="PositionCursor"/>

+ 7 - 4
Terminal.Gui/Views/ScrollView.cs

@@ -397,19 +397,22 @@ namespace Terminal.Gui {
 		/// This event is raised when the contents have scrolled
 		/// </summary>
 		//public event Action<ScrollView> Scrolled;
-
 		public override void Redraw(Rect region)
 		{
 			SetViewsNeedsDisplay ();
 			Driver.SetAttribute (ColorScheme.Normal);
 			Clear ();
 
-			//if (Driver.Clip.IsEmpty || Driver.Clip.Contains (RectToScreen (contentView.Frame))) {
+			var savedClip = ClipToBounds ();
+			contentView.Redraw (contentView.Bounds);
+			Driver.Clip = savedClip;
+
+			//if (Driver.Clip.IsEmpty || Driver.Clip.Contains (ViewToScreen (contentView.Frame))) { 
 			//	var savedClip = ClipToBounds ();
-			//	contentView.Redraw (contentView.Frame);
+			//	contentView.Redraw (contentView.Bounds);
 			//	Driver.Clip = savedClip;
 			//} else {
-				contentView.Redraw (contentView.Bounds);
+			//	contentView.Redraw (contentView.Bounds);
 			//}
 			vertical.Redraw (vertical.Bounds);
 			horizontal.Redraw (vertical.Bounds);

+ 1 - 1
Terminal.Gui/Views/StatusBar.cs

@@ -151,7 +151,7 @@ namespace Terminal.Gui {
 		}
 
 		///<inheritdoc cref="Redraw"/>
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			//if (Frame.Y != Driver.Rows - 1) {
 			//	Frame = new Rect (Frame.X, Driver.Rows - 1, Frame.Width, Frame.Height);

+ 1 - 1
Terminal.Gui/Views/TextField.cs

@@ -184,7 +184,7 @@ namespace Terminal.Gui {
 		}
 
 		///<inheritdoc cref="Redraw(Rect)"/>
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			ColorScheme color = Colors.Menu;
 			SetSelectedStartSelectedLength ();

+ 9 - 9
Terminal.Gui/Views/TextView.cs

@@ -525,31 +525,31 @@ namespace Terminal.Gui {
 		}
 
 		///<inheritdoc cref="Redraw(Rect)"/>
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			ColorNormal ();
 
-			int bottom = region.Bottom;
-			int right = region.Right;
-			for (int row = region.Top; row < bottom; row++) 
+			int bottom = bounds.Bottom;
+			int right = bounds.Right;
+			for (int row = bounds.Top; row < bottom; row++) 
 			{
 				int textLine = topRow + row;
 				if (textLine >= model.Count) 
 				{
 					ColorNormal ();
-					ClearRegion (region.Left, row, region.Right, row + 1);
+					ClearRegion (bounds.Left, row, bounds.Right, row + 1);
 					continue;
 				}
 				var line = model.GetLine (textLine);
 				int lineRuneCount = line.Count;
-				if (line.Count < region.Left)
+				if (line.Count < bounds.Left)
 				{
-					ClearRegion (region.Left, row, region.Right, row + 1);
+					ClearRegion (bounds.Left, row, bounds.Right, row + 1);
 					continue;
 				}
 
-				Move (region.Left, row);
-				for (int col = region.Left; col < right; col++) 
+				Move (bounds.Left, row);
+				for (int col = bounds.Left; col < right; col++) 
 				{
 					var lineCol = leftColumn + col;
 					var rune = lineCol >= lineRuneCount ? ' ' : line [lineCol];

+ 8 - 5
Terminal.Gui/Windows/FileDialog.cs

@@ -159,7 +159,7 @@ namespace Terminal.Gui {
 
 			Move (allowsMultipleSelection ? 3 : 2, line);
 			int byteLen = ustr.Length;
-			int used = 0;
+			int used = allowsMultipleSelection ? 2 : 1;
 			for (int i = 0; i < byteLen;) {
 				(var rune, var size) = Utf8.DecodeRune (ustr, i, i - byteLen);
 				var count = Rune.ColumnWidth (rune);
@@ -169,12 +169,12 @@ namespace Terminal.Gui {
 				used += count;
 				i += size;
 			}
-			for (; used < width; used++) {
+			for (; used < width - 1; used++) {
 				Driver.AddRune (' ');
 			}
 		}
 
-		public override void Redraw (Rect region)
+		public override void Redraw (Rect bounds)
 		{
 			var current = ColorScheme.Focus;
 			Driver.SetAttribute (current);
@@ -182,7 +182,7 @@ namespace Terminal.Gui {
 			var f = Frame;
 			var item = top;
 			bool focused = HasFocus;
-			var width = region.Width;
+			var width = bounds.Width;
 
 			for (int row = 0; row < f.Height; row++, item++) {
 				bool isSelected = item == selected;
@@ -463,7 +463,7 @@ namespace Terminal.Gui {
 			dirListView = new DirListView (this) {
 				X = 1,
 				Y = 3 + msgLines + 2,
-				Width = Dim.Fill () - 3,
+				Width = Dim.Fill () - 1,
 				Height = Dim.Fill () - 2,
 			};
 			DirectoryPath = Path.GetFullPath (Environment.CurrentDirectory);
@@ -488,6 +488,9 @@ namespace Terminal.Gui {
 			};
 			AddButton (this.prompt);
 
+			Width = Dim.Percent (80);
+			Height = Dim.Percent (80);
+
 			// On success, we will set this to false.
 			canceled = true;
 		}

+ 51 - 23
UICatalog/Scenarios/Clipping.cs

@@ -32,42 +32,70 @@ namespace UICatalog {
 			//Win.Y = 2;
 			//Win.Width = Dim.Fill () - 4;
 			//Win.Height = Dim.Fill () - 2;
-			var label = new Label ("ScrollView (new Rect (2, 2, 50, 20)) with a 200, 100 ContentSize...") {
+			var label = new Label ("ScrollView (new Rect (5, 5, 100, 60)) with a 200, 100 ContentSize...") {
 				X = 0, Y = 0,
 				ColorScheme = Colors.Dialog
 			};
 			Top.Add (label);
 
-			var scrollView = new ScrollView (new Rect (2, 2, 50, 20));
-			scrollView.ColorScheme = Colors.TopLevel;
-			scrollView.ContentSize = new Size (200, 100);
+			var scrollView = new ScrollView (new Rect (3, 3, 50, 20));
+			scrollView.ColorScheme = Colors.Menu;
+			scrollView.ContentSize = new Size (100, 60);
 			//ContentOffset = new Point (0, 0),
 			scrollView.ShowVerticalScrollIndicator = true;
 			scrollView.ShowHorizontalScrollIndicator = true;
 
-			const string rule = "|123456789";
-			var horizontalRuler = new Label ("") {
-				X = 0,
-				Y = 0,
-				Width = Dim.Fill (1),  // BUGBUG: I don't think this should be needed; DimFill() should respect container's frame. X does.
-				ColorScheme = Colors.Error
+			//const string rule = "|123456789";
+			//var horizontalRuler = new Label ("") {
+			//	X = 0,
+			//	Y = 0,
+			//	Width = Dim.Fill (1),  // BUGBUG: I don't think this should be needed; DimFill() should respect container's frame. X does.
+			//	ColorScheme = Colors.Error
+			//};
+			//scrollView.Add (horizontalRuler);
+			//const string vrule = "|\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
+
+			//var verticalRuler = new Label ("") {
+			//	X = 0,
+			//	Y = 0,
+			//	Width = 1,
+			//	Height = Dim.Fill (),
+			//	ColorScheme = Colors.Error
+			//};
+			//scrollView.Add (verticalRuler);
+
+			//Application.Resized += (sender, a) => {
+			//	horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)];
+			//	verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height * 2)];
+			//};
+
+			var embedded1 = new Window ("1") {
+				X = 3,
+				Y = 3,
+				Width = Dim.Fill (3),
+				Height = Dim.Fill (3),
+				ColorScheme = Colors.Dialog
 			};
-			scrollView.Add (horizontalRuler);
-			const string vrule = "|\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
-
-			var verticalRuler = new Label ("") {
-				X = 0,
-				Y = 0,
-				Width = 1,
-				Height = Dim.Fill (),
+
+			var embedded2 = new Window ("2") {
+				X = 3,
+				Y = 3,
+				Width = Dim.Fill (3),
+				Height = Dim.Fill (3),
 				ColorScheme = Colors.Error
 			};
-			scrollView.Add (verticalRuler);
-
-			Application.Resized += (sender, a) => {
-				horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)];
-				verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height * 2)];
+			embedded1.Add (embedded2);
+
+			var embedded3 = new Window ("3") {
+				X = 3,
+				Y = 3,
+				Width = Dim.Fill (3),
+				Height = Dim.Fill (3),
+				ColorScheme = Colors.TopLevel
 			};
+			embedded2.Add (embedded3);
+
+			scrollView.Add (embedded1);
 
 			//scrollView.Add (new Button ("Press me!") {
 			//	X = 3,

+ 5 - 5
UICatalog/Scenarios/Scrolling.cs

@@ -9,10 +9,10 @@ namespace UICatalog {
 	class Scrolling : Scenario {
 		public override void Setup ()
 		{
-			Win.X = 1;
-			Win.Y = 2;
-			Win.Width = Dim.Fill () - 4;
-			Win.Height = Dim.Fill () - 2;
+			Win.X = 3;
+			Win.Y = 3;
+			Win.Width = Dim.Fill () - 3;
+			Win.Height = Dim.Fill () - 3;
 			var label = new Label ("ScrollView (new Rect (2, 2, 50, 20)) with a 200, 100 ContentSize...") {
 				X = 0, Y = 0,
 				ColorScheme = Colors.Dialog
@@ -60,7 +60,7 @@ namespace UICatalog {
 			scrollView.Add (new Button ("A very long button. Should be wide enough to demo clipping!") {
 				X = 3,
 				Y = 4,
-				Width = 50,
+				Width = Dim.Fill(6),
 				Clicked = () => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No")
 			});