Skip to content

Commit

Permalink
improvements when the table is larger than the screen, and improvemen…
Browse files Browse the repository at this point in the history
…t for commands with default values ​​(all controls)
  • Loading branch information
Fernando Cerqueira committed Sep 26, 2023
1 parent bb584e0 commit 33fd1c2
Show file tree
Hide file tree
Showing 39 changed files with 2,393 additions and 189 deletions.
2 changes: 1 addition & 1 deletion PromptPlus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Template", "Template", "{04
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PromptPlusTemplate", "Template\PromptPlusTemplate\PromptPlusTemplate.csproj", "{E713CD59-5AB5-40AA-80B3-436D0C6511DA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TableBasicSamples", "Samples\TableBasicSamples\TableBasicSamples.csproj", "{C5189623-17BD-472E-8A11-832115ABD152}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TableSamples", "Samples\TableBasicSamples\TableSamples.csproj", "{C5189623-17BD-472E-8A11-832115ABD152}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
164 changes: 134 additions & 30 deletions Samples/TableBasicSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
// The maintenance and evolution is maintained by the PromptPlus project under MIT license
// ***************************************************************************************

using System.ComponentModel;
using System.Globalization;
using PPlus;
using PPlus.Controls;

namespace TableBasicSamples
namespace TableSamples
{
internal class Program
{
Expand All @@ -21,25 +20,60 @@ public MyComplexCol(string value)
public string Id { get; } = Guid.NewGuid().ToString()[..8];
public string Name { get; }
}

internal class MyTable
{
public int Id { get; set; }
public required string MyText { get; set; }
public DateTime? MyDate { get; set; }
public required MyComplexCol ComplexCol { get; set; }

}


internal class MyTableManyCols
{
public int Id { get; set; }
public required string MyText { get; set; }
public string D01 { get; set; } = new string('x', 20);
public string D02 { get; set; } = new string('x', 20);
public string D03 { get; set; } = new string('x', 20);
public string D04 { get; set; } = new string('x', 20);
public string D05 { get; set; } = new string('x', 20);
public string D06 { get; set; } = new string('x', 20);
public string D07 { get; set; } = new string('x', 20);
public string D08 { get; set; } = new string('x', 20);
public string D09 { get; set; } = new string('x', 20);
public string D10 { get; set; } = new string('x', 20);
public string D11 { get; set; } = new string('x', 20);
public string D12 { get; set; } = new string('x', 20);
public string D13 { get; set; } = new string('x', 20);
public string D14 { get; set; } = new string('x', 20);
public string D15 { get; set; } = new string('x', 20);
public string D16 { get; set; } = new string('x', 20);
public string D17 { get; set; } = new string('x', 20);
public string D18 { get; set; } = new string('x', 20);
public string D19 { get; set; } = new string('x', 20);
public string D20 { get; set; } = new string('x', 20);
public string D21 { get; set; } = new string('x', 20);
public string D22 { get; set; } = new string('x', 20);
public string D23 { get; set; } = new string('x', 20);
public string D24 { get; set; } = new string('x', 20);
public string D25 { get; set; } = new string('x', 20);
public string D26 { get; set; } = new string('x', 20);
public string D27 { get; set; } = new string('x', 20);
public string D28 { get; set; } = new string('x', 20);
public string D29 { get; set; } = new string('x', 20);
public string D30 { get; set; } = new string('x', 20);
public string D31 { get; set; } = new string('x', 20);
}

static void Main()
{
static MyTable[] CreateItems()
static MyTable[] CreateItems(int max)
{
var result = new List<MyTable>();
var flag = false;
result.Add(new MyTable { Id = 0, MyDate = new DateTime(), MyText = $"Test0 linha1{Environment.NewLine}Test3 linha2", ComplexCol = new MyComplexCol("C0") });
for (int i = 1; i < 19; i++)
result.Add(new MyTable { Id = 0, MyDate = DateTime.Now, MyText = $"Test0 linha1{Environment.NewLine}Test0 linha2", ComplexCol = new MyComplexCol("C0") });
for (int i = 1; i < max; i++)
{
flag = !flag;
if (flag)
Expand All @@ -48,7 +82,7 @@ static MyTable[] CreateItems()
}
else
{
result.Add(new MyTable { Id = i, MyDate = new DateTime().AddDays(i), MyText = $"Test{i} very very very very very very very very long", ComplexCol = new MyComplexCol($"C{i}") });
result.Add(new MyTable { Id = i, MyDate = DateTime.Now.AddDays(i), MyText = $"Test{i} very very very very very very very very long" + new string('x',150), ComplexCol = new MyComplexCol($"C{i}") });
}
}
return result.ToArray();
Expand All @@ -57,39 +91,109 @@ static MyTable[] CreateItems()
//Ensure ValueResult Culture for all controls
PromptPlus.Config.DefaultCulture = new CultureInfo("en-us");

var data = CreateItems();
var data = CreateItems(20);

var tbl = PromptPlus.Table<MyTable>("Select Column","Descripion Table")
//.Config(cfg => cfg.ShowOnlyExistingPagination(true))
//.HideHeaders()
//.HideSelectorRow()
//.Default(data[1])
//.ChangeDescription((item,row,col) => $"{item.ComplexCol.Name}")
//.PageSize(6)
//.ColumnsNavigation()
//.SeparatorRows()
//.FilterByColumns(FilterMode.Contains, 1, 4)
//.Layout(TableLayout.SingleGridFull)
//.Title("Test", titleMode: TableTitleMode.InRow)
PromptPlus.DoubleDash("Control:Table - Autofill UserInteraction basic usage");
var tbl = PromptPlus.Table<MyTable>("Your Prompt", "Descripion Table")
.AddItems(data)
.AddItem(new MyTable { Id = data.Length, MyText = $"Test{data.Length} disabled", ComplexCol = new MyComplexCol($"C{data.Length}") }, true)
.AutoFill()
//.AddColumn(field: (item) => item.Id, width: 10)
//.AddColumn(field: (item) => item.MyDate!, width: 15/*,alignment: Alignment.Center*/)
//.AddColumn(field: (item) => item.MyText, width: 120, format: (arg) => $"Text: {arg}", maxslidinglines: 5/*, textcrop:true*/)
//.AddColumn(field: (item) => item.ComplexCol, width: 20, format: (arg) => $"{((MyComplexCol)arg).Id}:{((MyComplexCol)arg).Name}")
//.AddColumn(field: (item) => item.ComplexCol.Name, width: 10)
//.AutoFit(1,2)
.AddFormatType<DateTime>(FmtDate)
.UserInteraction(
selectedTemplate: (item, row, col) => $"Current ID : {item.Id}. [yellow]Current row {row}, Current col {col}[/]",
finishTemplate: (item, row, col) => $"[green]Selected ID : {item.Id}. Current row {row}, Current col {col}[/]")
.Run();
if (!tbl.IsAborted)
{
{
}

PromptPlus.DoubleDash("Control:Table - Autofill UserInteraction with many columns and RowNavigation(Default)");
PromptPlus.Table<MyTableManyCols>("Your Prompt", "Descripion Table")
.Interaction<object>(new Array[5], (ctrl, _) =>
{
ctrl.AddItem(new MyTableManyCols() { MyText = "x" });
})
.AutoFill(10)
.AddFormatType<DateTime>(FmtDate)
.UserInteraction(
selectedTemplate: (item, row, col) => $"Current ID : {item.Id}. [yellow]Current row {row}, Current col {col}[/]",
finishTemplate: (item, row, col) => $"[green]Selected ID : {item.Id}. Current row {row}, Current col {col}[/]")
.Run();

PromptPlus.DoubleDash("Control:Table - Autofill UserInteraction with many columns and ColumnsNavigation");
PromptPlus.Table<MyTableManyCols>("Your Prompt", "Descripion Table")
.Interaction<object>(new Array[5], (ctrl, _) =>
{
ctrl.AddItem(new MyTableManyCols() { MyText = "x" });
})
.AutoFill(10)
.AddFormatType<DateTime>(FmtDate)
.ColumnsNavigation()
.UserInteraction(
selectedTemplate: (item, row, col) => $"Current ID : {item.Id}. [yellow]Current row {row}, Current col {col}[/]",
finishTemplate: (item, row, col) => $"[green]Selected ID : {item.Id}. Current row {row}, Current col {col}[/]")
.Run();

PromptPlus.DoubleDash("Control:Table - UserInteraction with with column definition");
PromptPlus.Table<MyTable>("Your Prompt", "Descripion Table")
.Title("Test", titleMode: TableTitleMode.InRow)
.AddItem(new MyTable { Id = data.Length, MyText = $"Test{data.Length} disabled", ComplexCol = new MyComplexCol($"C{data.Length}") }, true)
.AddItems(data)
.AutoFill(10)
.AddColumn(field: (item) => item.Id, width: 10)
.AddColumn(field: (item) => item.MyDate!, width: 15/*,alignment: Alignment.Center*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text: {arg}", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text1: {arg}", title: $"Mytext1", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text2: {arg}", title: $"Mytext2", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text3: {arg}", title: $"Mytext3", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text4: {arg}", title: $"Mytext4", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text5: {arg}", title: $"Mytext5", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text8: {arg}", title: $"Mytext8", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text9: {arg}", title: $"Mytext9", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.MyText, width: 20, format: (arg) => $"Text10: {arg}", title: $"Mytext10", maxslidinglines: 5/*, textcrop:true*/)
.AddColumn(field: (item) => item.ComplexCol, width: 20, format: (arg) => $"{((MyComplexCol)arg).Id}:{((MyComplexCol)arg).Name}")
.AddColumn(field: (item) => item.ComplexCol.Name, width: 10)
.AddFormatType<DateTime>(FmtDate)
.UserInteraction(
selectedTemplate: (item, row, col) => $"Current ID : {item.Id}. [yellow]Current row {row}, Current col {col}[/]",
finishTemplate: (item, row, col) => $"[green]Selected ID : {item.Id}. Current row {row}, Current col {col}[/]")
.Run();

data = CreateItems(5);

var typelayout = Enum.GetValues(typeof(TableLayout));
var typetit = Enum.GetValues(typeof(TableTitleMode));
//Title mode
foreach (var itemt in typetit)
{
var tm = (TableTitleMode)Enum.Parse(typeof(TableTitleMode), itemt.ToString()!);
//Title Grid mode
foreach (var iteml in typelayout)
{
var hideheaders = true;
for (int h = 0; h < 2; h++)
{
hideheaders = !hideheaders;
var seprow = true;
//SeparatorRows (true/false)
for (int i = 0; i < 2; i++)
{
seprow = !seprow;
PromptPlus.DoubleDash($"Control:Table (Write only) - Autofill Write Table Layout({iteml}) , Title({itemt}) , sep.row({seprow}) hide headers({hideheaders})");
var lt = (TableLayout)Enum.Parse(typeof(TableLayout), iteml.ToString()!);
PromptPlus.Table<MyTable>("")
.Title("Test", Alignment.Center, tm)
.SeparatorRows(seprow)
.HideHeaders(hideheaders)
.Layout(lt)
.AddItems(data)
.AutoFill()
.AddFormatType<DateTime>(FmtDate)
.Run(); PromptPlus.KeyPress("Press any key", cfg => cfg.ShowTooltip(false).HideAfterFinish(true)).Run();
}
}
}
}

Console.ReadKey();
}

private static string FmtDate(object arg)
Expand Down
3 changes: 2 additions & 1 deletion Src/Controls/AddtoList/IControlList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ public interface IControlList : IPromptControls<IEnumerable<string>>
/// <summary>
/// Allow duplicate items.Default value for this control is false.
/// </summary>
/// <param name="value">Allow duplicate items</param>
/// <returns><see cref="IControlList"/></returns>
IControlList AllowDuplicate();
IControlList AllowDuplicate(bool value = true);

/// <summary>
/// Defines a minimum and maximum (optional) range of items in the list
Expand Down
4 changes: 2 additions & 2 deletions Src/Controls/AddtoList/ListControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ public IControlList PageSize(int value)
return this;
}

public IControlList AllowDuplicate()
public IControlList AllowDuplicate(bool value = true)
{
_options.AllowDuplicate = true;
_options.AllowDuplicate = value;
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions Src/Controls/Calendar/CalendarControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public IControlCalendar Config(Action<IPromptConfig> context)
return this;
}

public IControlCalendar DisabledWeekends()
public IControlCalendar DisabledWeekends(bool value = true)
{
_options.DisabledWeekend = true;
_options.DisabledWeekend = value;
return this;
}

Expand Down
5 changes: 3 additions & 2 deletions Src/Controls/Calendar/IControlCalendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ public interface IControlCalendar : IPromptControls<DateTime>
IControlCalendar Range(DateTime minvalue, DateTime maxvalue);

/// <summary>
/// Disabled Weekends.
/// Disabled Weekends.Default false;
/// </summary>
/// <param name="value">Disabled weekends</param>
/// <returns><see cref="IControlCalendar"/></returns>
IControlCalendar DisabledWeekends();
IControlCalendar DisabledWeekends(bool value = true);

/// <summary>
/// Add scope(Note/Highlight/Disabled) items to calendar.
Expand Down
14 changes: 7 additions & 7 deletions Src/Controls/Chart/ChartBarControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,21 @@ public IControlChartBar OrderBy(ChartOrder chartOrder)
return this;
}

public IControlChartBar HideOrdination()
public IControlChartBar HideOrdination(bool value = true)
{
_options.HideInfoOrder= true;
_options.HideInfoOrder= value;
return this;
}

public IControlChartBar HidePercent()
{
_options.HidePercentBar = true;
public IControlChartBar HidePercent(bool value = true)
{
_options.HidePercentBar = value;
return this;
}

public IControlChartBar HideValue()
public IControlChartBar HideValue(bool value = true)
{
_options.HideValueBar = true;
_options.HideValueBar = value;
return this;
}

Expand Down
13 changes: 8 additions & 5 deletions Src/Controls/Chart/IControlChartBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,18 @@ public interface IControlChartBar: IPromptControls<bool>
IControlChartBar OrderBy(ChartOrder chartOrder);

/// <summary>
/// Hide Percent in bar
/// Hide Percent in bar.Default false
/// </summary>
/// <param name="value">Hide Percent</param>
/// <returns><see cref="IControlChartBar"/></returns>
IControlChartBar HidePercent();
IControlChartBar HidePercent(bool value = true);

/// <summary>
/// Hide value in bar
/// Hide value in bar.Default false
/// </summary>
/// <param name="value">Hide value</param>
/// <returns><see cref="IControlChartBar"/></returns>
IControlChartBar HideValue();
IControlChartBar HideValue(bool value = true);

/// <summary>
/// Pad-Left to write ChartBar
Expand All @@ -132,8 +134,9 @@ public interface IControlChartBar: IPromptControls<bool>
/// <summary>
/// Hide info of ordination labels
/// </summary>
/// <param name="value">Hide info of ordination labels.</param>
/// <returns><see cref="IControlChartBar"/></returns>
IControlChartBar HideOrdination();
IControlChartBar HideOrdination(bool value = true);

/// <summary>
/// Enabled Interaction to switch Layout , Legend and order when browse the charts / Legends.
Expand Down
8 changes: 5 additions & 3 deletions Src/Controls/Input/IControlMaskEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ public interface IControlMaskEdit : IPromptControls<ResultMasked>
/// Accept empty value
/// <br>Valid only for type not equal MaskedType.Generic, otherwise this set will be ignored.</br>
/// </summary>
/// <param name="value">Accept empty value</param>
/// <returns><see cref="IControlMaskEdit"/></returns>
IControlMaskEdit AcceptEmptyValue();
IControlMaskEdit AcceptEmptyValue(bool value = true);

/// <summary>
/// Default value (with mask!) when finished value is empty.
Expand All @@ -86,13 +87,14 @@ public interface IControlMaskEdit : IPromptControls<ResultMasked>
IControlMaskEdit DefaultIfEmpty(string value,bool zeroIsEmpty = true);

/// <summary>
/// Fill zeros mask.
/// Fill zeros mask.Default false.
/// <br>Not valid for type MaskedType.Generic (this set will be ignored).</br>
/// <br>When used this feature the AcceptEmptyValue feature will be ignored.</br>
/// <br>When MaskedType.Number or MaskedType.Currency this feature is always on.</br>
/// </summary>
/// <param name="value">Fill zeros mask</param>
/// <returns><see cref="IControlMaskEdit"/></returns>
IControlMaskEdit FillZeros();
IControlMaskEdit FillZeros(bool value = true);

/// <summary>
/// <see cref="CultureInfo"/> to validate input when the type is not generic.
Expand Down
Loading

0 comments on commit 33fd1c2

Please sign in to comment.