Skip to content

Commit

Permalink
UI catalog (gui-cs#387)
Browse files Browse the repository at this point in the history
* key down/up support

* line endings?

* line endings

* KeyDown/Up support

* line endings

* line endings

* Revert "Drop NuGet restore"

This reverts commit 5c7a0d0.

* Revert "Revert "Drop NuGet restore""

This reverts commit 2dc5fce.

* updated demo

* defined styles

* Smarter StatusBar bottom tracking.

* Prepping for gui-cs#376

* Oops.

* Fixed StatusBar 'snap to bottom'

* line endings

* Revert "Fixed StatusBar 'snap to bottom'"

This reverts commit 9a91c95.

* started UICatalog project

* Initial working POC.

* Fix newlines

* merge

* textalignment demo tweaks

* textalignment demo tweaks

* Unicode Menu Scenario

* not sure why this keeps changing

* re-added project to .sln file

* re-enabled status bar

* moved scenarios to dir

* building a dim and pos demo

* terminal.sln

* progress...barely

* fixed exit

* progress with some underlying fixes to Label

* added readme

* fixes build issue

* launch

* made default colors readable on Windows

* major UI Catalog upgrade

* added more demos and updated readme

* refactored and added more tests

* added ref to Issue gui-cs#437

* added OnKeyUp support to Curses and Net drivers

* more tweaks - grab PR gui-cs#438 first

* Added a OpenSelectedItem event to the ListView gui-cs#429

* updates

* moved KeyUpHandler out of special ESC stuff

* more tweaks & improvements

* testing top window bug

* supported OpenSelectedItem

* lots of updates

* fixed regression, fixed gui-cs#444

* better button scenario

* tweaks

* add Ready event to Toplevel

* dotfx .gitignroe

* ready for ready

* updated colors based on feedback; consolodated config code

* tweaked readme

* readme

* Added Editor demonstrating TextView

* Added Editor demonstrating TextView

* added hexeditor scenario

Co-authored-by: Miguel de Icaza <miguel@gnome.org>
Co-authored-by: BDisp <bd.bdisp@gmail.com>
  • Loading branch information
3 people committed May 22, 2020
1 parent a1f9a9b commit b57336d
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions UICatalog/Scenarios/DimAndPosLayout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Terminal.Gui;

namespace UICatalog {
/// <summary>
/// This Scenario demonstrates how to use Termina.gui's Dim and Pos Layout System.
/// [x] - Using Dim.Fill to fill a window
/// [x] - Using Dim.Fill and Dim.Pos to automatically align controls based on an initial control
/// [ ] - ...
/// </summary>
[ScenarioMetadata (Name: "DimAndPosLayout", Description: "Demonstrates using the Dim and Pos Layout System")]
[ScenarioCategory ("Layout")]
class DimAndPosLayout : Scenario {

public override void Setup ()
{
Top.LayoutStyle = LayoutStyle.Computed;
// Demonstrate using Dim to create a ruler that always measures the top-level window's width
// BUGBUG: Dim.Fill returns too big a value sometimes.
//const string rule = "|123456789";
//var labelRuler = new Label ("ruler") {
// 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
//};

//Application.OnResized += () => {
// labelRuler.Text = rule.Repeat ((int)Math.Ceiling((double)(labelRuler.Bounds.Width) / (double)rule.Length))[0..(labelRuler.Bounds.Width)];
//};

//win.Add (labelRuler);

// Demonstrate using Dim to create a window that fills the parent with a margin
int margin = 20;
var subWin = new Window ($"Sub Windoww with {margin} character margin") {
X = margin,
Y = 2,
Width = Dim.Fill (margin),
Height = Dim.Fill ()
};
Win.Add (subWin);

int i = 1;
string txt = "Hello world, how are you doing today";
var labelList = new List<Label> ();
labelList.Add (new Label ($"Label:"));
labelList.Add (new Label ($"{i++}-{txt}") { TextAlignment = Terminal.Gui.TextAlignment.Left, Width = Dim.Fill (1), X = 0, Y = Pos.Bottom (labelList.LastOrDefault ()) + 1, ColorScheme = Colors.Dialog });
labelList.Add (new Label ($"{i++}-{txt}") { TextAlignment = Terminal.Gui.TextAlignment.Right, Width = Dim.Fill (1), X = 0, Y = Pos.Bottom (labelList.LastOrDefault ()) + 1, ColorScheme = Colors.Dialog });
labelList.Add (new Label ($"{i++}-{txt}") { TextAlignment = Terminal.Gui.TextAlignment.Centered, Width = Dim.Fill (1), X = 0, Y = Pos.Bottom (labelList.LastOrDefault ()) + 1, ColorScheme = Colors.Dialog });
labelList.Add (new Label ($"{i++}-{txt}") { TextAlignment = Terminal.Gui.TextAlignment.Justified, Width = Dim.Fill (1), X = 0, Y = Pos.Bottom (labelList.LastOrDefault ()) + 1, ColorScheme = Colors.Dialog });

subWin.Add (labelList.ToArray ());
//subWin.LayoutSubviews ();
}

public override void Run ()
{
base.Run ();
}
}

public static class StringExtensions {
public static string Repeat (this string instr, int n)
{
if (n <= 0) {
return null;
}

if (string.IsNullOrEmpty (instr) || n == 1) {
return instr;
}

return new StringBuilder (instr.Length * n)
.Insert (0, instr, n)
.ToString ();
}
}
}

0 comments on commit b57336d

Please sign in to comment.