diff --git a/Terminal.Gui/Core.cs b/Terminal.Gui/Core.cs
index c27f59e14..965441ceb 100644
--- a/Terminal.Gui/Core.cs
+++ b/Terminal.Gui/Core.cs
@@ -150,6 +150,13 @@ namespace Terminal.Gui {
/// Using ColorSchemes has the advantage that your application will work both
/// in color as well as black and white displays.
///
+ ///
+ /// Views that are focusable should implement the PositionCursor to make sure that
+ /// the cursor is placed in a location that makes sense. Unix terminals do not have
+ /// a way of hiding the cursor, so it can be distracting to have the cursor left at
+ /// the last focused view. So views should make sure that they place the cursor
+ /// in a visually sensible place.
+ ///
///
public class View : Responder, IEnumerable {
View container = null;
@@ -441,6 +448,28 @@ namespace Terminal.Gui {
return new Rect (x, y, w, h);
}
+ ///
+ /// Sets the Console driver's clip region to the current View's Bounds.
+ ///
+ /// The existing driver's Clip region, which can be then set by setting the Driver.Clip property.
+ public Rect ClipToBounds ()
+ {
+ return SetClip (Bounds);
+ }
+
+ ///
+ /// Sets the clipping region to the specified region, the region is view-relative
+ ///
+ /// The previous clip region.
+ /// Rectangle region to clip into, the region is view-relative.
+ public Rect SetClip (Rect rect)
+ {
+ var bscreen = RectToScreen (rect);
+ var previous = Driver.Clip;
+ Driver.Clip = ScreenClip (RectToScreen (Bounds));
+ return previous;
+ }
+
///
/// Draws a frame in the current view, clipped by the boundary of this view
///
@@ -592,8 +621,12 @@ namespace Terminal.Gui {
///
/// Performs a redraw of this view and its subviews, only redraws the views that have been flagged for a re-display.
///
+ /// The region to redraw, this is relative to the view itself.
///
- /// The region argument is relative to the view itself.
+ ///
+ /// Views should set the color that they want to use on entry, as otherwise this will inherit
+ /// the last color that was set globaly on the driver.
+ ///
///
public virtual void Redraw (Rect region)
{
diff --git a/Terminal.Gui/Driver.cs b/Terminal.Gui/Driver.cs
index 64d77e402..0c9219835 100644
--- a/Terminal.Gui/Driver.cs
+++ b/Terminal.Gui/Driver.cs
@@ -276,7 +276,7 @@ namespace Terminal.Gui {
}
}
- static bool sync = false;
+ static bool sync = true;
public override void AddRune (Rune rune)
{
if (Clip.Contains (ccol, crow)) {
diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs
index 2431d5eb4..999f9cb3f 100644
--- a/Terminal.Gui/Views/ScrollView.cs
+++ b/Terminal.Gui/Views/ScrollView.cs
@@ -14,11 +14,15 @@ namespace Terminal.Gui {
///
///
public class ScrollView : View {
+ View contentView;
+
public ScrollView (Rect frame) : base (frame)
{
+ contentView = new View (frame);
+ base.Add (contentView);
}
- Rect contentSize;
+ Size contentSize;
Point contentOffset;
bool showHorizontalScrollIndicator;
bool showVerticalScrollIndicator;
@@ -27,12 +31,13 @@ namespace Terminal.Gui {
/// Represents the contents of the data shown inside the scrolview
///
/// The size of the content.
- public Rect ContentSize {
+ public Size ContentSize {
get {
return contentSize;
}
set {
contentSize = value;
+ contentView.Frame = new Rect (contentOffset, value);
}
}
@@ -45,10 +50,20 @@ namespace Terminal.Gui {
return contentOffset;
}
set {
- contentOffset = value;
+ contentOffset = new Point (-value.X, -value.Y);
+ contentView.Frame = new Rect (contentOffset, contentSize);
}
}
+ ///
+ /// Adds the view to the scrollview.
+ ///
+ /// The view to add to the scrollview.
+ public override void Add (View view)
+ {
+ contentView.Add (view);
+ }
+
///
/// Gets or sets the visibility for the horizontal scroll indicator.
///
@@ -81,7 +96,12 @@ namespace Terminal.Gui {
public override void Redraw(Rect region)
{
+ var oldClip = ClipToBounds ();
base.Redraw(region);
+ Driver.SetAttribute (ColorScheme.Normal);
+
+ DrawFrame (Bounds);
+ Driver.Clip = oldClip;
}
}
}
diff --git a/demo.cs b/demo.cs
index 70c815ff1..4fbae86f8 100644
--- a/demo.cs
+++ b/demo.cs
@@ -1,6 +1,28 @@
using Terminal.Gui;
+using System;
class Demo {
+ class MyView : View {
+ public MyView (int x, int y) : base (new Rect (x, y, 10, 10))
+ {
+ }
+
+ public override void Redraw(Rect region)
+ {
+ Driver.SetAttribute (ColorScheme.Focus);
+
+ for (int y = 0; y < 10; y++) {
+ Move (0, y);
+ for (int x = 0; x < 10; x++) {
+
+ Driver.AddRune ((Rune)('0' + (x+y)%10));
+ }
+ }
+
+ }
+
+ }
+
static void ShowTextAlignments (View container)
{
container.Add (
@@ -12,6 +34,13 @@ class Demo {
static void ShowEntries (View container)
{
+ var scrollView = new ScrollView (new Rect (50, 10, 20, 8)) {
+ ContentSize = new Size (100, 100),
+ ContentOffset = new Point (-1, -1)
+ };
+
+ scrollView.Add (new MyView (0, 0));
+
container.Add (
new Label (3, 6, "Login: "),
new TextField (14, 6, 40, ""),
@@ -21,6 +50,7 @@ class Demo {
new CheckBox (1, 0, "Remember me"),
new RadioGroup (1, 2, new [] { "_Personal", "_Company" }),
},
+ scrollView,
new Button (3, 19, "Ok"),
new Button (10, 19, "Cancel"),
new Label (3, 22, "Press ESC and 9 to activate the menubar")
@@ -75,7 +105,7 @@ class Demo {
ShowEntries (win);
int count = 0;
- ml = new Label (new Rect (3, 17, 50, 1), "Mouse: ");
+ ml = new Label (new Rect (3, 17, 47, 1), "Mouse: ");
Application.RootMouseEvent += delegate (MouseEvent me) {
ml.Text = $"Mouse: ({me.X},{me.Y}) - {me.Flags} {count++}";