mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
Note this PR should not be merged until after #600 is in. I went on a rampage tonight. It all started with wanting to use more/better characters for frame and other UI elements like the round corners:  I decided I needed a character map app that would let me test which fonts had which Unicode sets in them. As a result we have this PR - Fixes `ScrollView` in several key ways: - It now supports Computed layout and has constructors that don't require parameters. - `ScrollBarViews` are now positioned using Computed layout versus error prone absoulte - `ScrollBarViews` now correctly position themselves when one, either, or both are on/off. - `IsVertical` is now a public property that does the expected thing when changed - Mouse handling is better; there's still a bug where the mouse doesn't get grabbed by the `ScrollView` initially but I think this is a broader problem. I need @BDisp's help on this. - The `Scrolling` Scenario was enhanced to demo dynamically adding/removing horizontal/vertical scrollbars (and to prove it was working right). - I Enabled easy "infinite scroll capability" - CharMap literally lets you scroll over `int.MaxValue / 16` rows of data. Filling a `ContentView` with all of this and panning it around won't work. So I needed a way of having `Redraw` give me virtual coordinates. I did this by defining `OnDrawContent(Rect viewport)` and it's associated `event`: ```csharp /// <summary> /// Event invoked when the content area of the View is to be drawn. /// </summary> /// <remarks> /// <para> /// Will be invoked before any subviews added with <see cref="Add(View)"/> have been drawn. /// </para> /// <para> /// Rect provides the view-relative rectangle describing the currently visible viewport into the <see cref="View"/>. /// </para> /// </remarks> public event EventHandler<Rect> DrawContent; /// <summary> /// Enables overrides to draw infinitely scrolled content and/or a background behind added controls. /// </summary> /// <param name="viewport">The view-relative rectangle describing the currently visible viewport into the <see cref="View"/></param> /// <remarks> /// This method will be called before any subviews added with <see cref="Add(View)"/> have been drawn. /// </remarks> public virtual void OnDrawContent (Rect viewport) { DrawContent?.Invoke (this, viewport); } ``` I originally just implemented this pattern in `ScrollView`. Then I realized I wanted the same thing out of ALL `Views`. Namely: the ability to do drawing on an event, particularly to be able to paint something in the background. So I added it to `View`. Note, that these changes mean we are about 3 small steps away from moving the scollbars from `ScrollView` into ALL views. Which makes a lot of sense to me because I don't think we want to implement duplicative logic in, say `ListView` and `TextView` as well. Why not just do it once? Along the way I fixed some other things: - The `Checkbox.Toggled` event now passes state. Here's some gifs.  Note: - Scrollbars appear dynamically. - Fast scrolling of huge data (using no memory). - Static header - Dynamic scrollbars on/off - Note the bottom/right corner now draw correctly in all situations
33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Terminal.Gui;
|
|
|
|
namespace UICatalog {
|
|
[ScenarioMetadata (Name: "Text Alignment", Description: "Demonstrates text alignment")]
|
|
[ScenarioCategory ("Text")]
|
|
class TextAlignments : Scenario {
|
|
public override void Setup ()
|
|
{
|
|
int i = 1;
|
|
string txt = "Hello world, how are you doing today?";
|
|
|
|
var alignments = Enum.GetValues (typeof (Terminal.Gui.TextAlignment)).Cast<Terminal.Gui.TextAlignment> ().ToList();
|
|
|
|
foreach (var alignment in alignments) {
|
|
Win.Add (new Label ($"{alignment}:") { Y = ++i });
|
|
Win.Add (new Label (txt) { TextAlignment = alignment, Y = i++, Width = Dim.Fill(), ColorScheme = Colors.Dialog });
|
|
}
|
|
|
|
// Demonstrate that wrapping labels are not yet implemented (#352)
|
|
txt += "\nSecond line";
|
|
Win.Add (new Label ($"Demonstrating multi-line (note wrap is not yet implemented):") { Y = ++i });
|
|
|
|
foreach (var alignment in alignments) {
|
|
Win.Add (new Label ($"{alignment}:") { Y = ++i });
|
|
Win.Add (new Label (txt) { TextAlignment = alignment, Y = ++i, Width = Dim.Fill (), Height = 2, ColorScheme = Colors.Dialog });
|
|
i += 2;
|
|
}
|
|
}
|
|
}
|
|
} |