mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 09:47:58 +01:00
Merge branch 'main' of tig:migueldeicaza/gui.cs
This commit is contained in:
@@ -6,72 +6,6 @@ using System.Linq;
|
||||
|
||||
namespace Terminal.Gui {
|
||||
|
||||
/// <summary>
|
||||
/// A single tab in a <see cref="TabView"/>
|
||||
/// </summary>
|
||||
public class Tab {
|
||||
private ustring text;
|
||||
|
||||
/// <summary>
|
||||
/// The text to display in a <see cref="TabView"/>
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public ustring Text { get => text ?? "Unamed"; set => text = value; }
|
||||
|
||||
/// <summary>
|
||||
/// The control to display when the tab is selected
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public View View { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new unamed tab with no controls inside
|
||||
/// </summary>
|
||||
public Tab ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new tab with the given text hosting a view
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="view"></param>
|
||||
public Tab (string text, View view)
|
||||
{
|
||||
this.Text = text;
|
||||
this.View = view;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes render stylistic selections of a <see cref="TabView"/>
|
||||
/// </summary>
|
||||
public class TabStyle {
|
||||
|
||||
/// <summary>
|
||||
/// True to show the top lip of tabs. False to directly begin with tab text during
|
||||
/// rendering. When true header line occupies 3 rows, when false only 2.
|
||||
/// Defaults to true.
|
||||
///
|
||||
/// <para>When <see cref="TabsOnBottom"/> is enabled this instead applies to the
|
||||
/// bottommost line of the control</para>
|
||||
/// </summary>
|
||||
public bool ShowTopLine { get; set; } = true;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// True to show a solid box around the edge of the control. Defaults to true.
|
||||
/// </summary>
|
||||
public bool ShowBorder { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// True to render tabs at the bottom of the view instead of the top
|
||||
/// </summary>
|
||||
public bool TabsOnBottom { get; set; } = false;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Control that hosts multiple sub views, presenting a single one at once
|
||||
/// </summary>
|
||||
@@ -481,6 +415,8 @@ namespace Terminal.Gui {
|
||||
SetNeedsDisplay ();
|
||||
}
|
||||
|
||||
#region Nested Types
|
||||
|
||||
private class TabToRender {
|
||||
public int X { get; set; }
|
||||
public Tab Tab { get; set; }
|
||||
@@ -808,32 +744,100 @@ namespace Terminal.Gui {
|
||||
return tabs.LastOrDefault (t => x >= t.X && x < t.X + t.Width)?.Tab;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes a change in <see cref="TabView.SelectedTab"/>
|
||||
/// </summary>
|
||||
public class TabChangedEventArgs : EventArgs {
|
||||
|
||||
/// <summary>
|
||||
/// The previously selected tab. May be null
|
||||
/// A single tab in a <see cref="TabView"/>
|
||||
/// </summary>
|
||||
public Tab OldTab { get; }
|
||||
public class Tab {
|
||||
private ustring text;
|
||||
|
||||
/// <summary>
|
||||
/// The currently selected tab. May be null
|
||||
/// </summary>
|
||||
public Tab NewTab { get; }
|
||||
/// <summary>
|
||||
/// The text to display in a <see cref="TabView"/>
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public ustring Text { get => text ?? "Unamed"; set => text = value; }
|
||||
|
||||
/// <summary>
|
||||
/// Documents a tab change
|
||||
/// </summary>
|
||||
/// <param name="oldTab"></param>
|
||||
/// <param name="newTab"></param>
|
||||
public TabChangedEventArgs (Tab oldTab, Tab newTab)
|
||||
{
|
||||
OldTab = oldTab;
|
||||
NewTab = newTab;
|
||||
/// <summary>
|
||||
/// The control to display when the tab is selected
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public View View { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new unamed tab with no controls inside
|
||||
/// </summary>
|
||||
public Tab ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new tab with the given text hosting a view
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <param name="view"></param>
|
||||
public Tab (string text, View view)
|
||||
{
|
||||
this.Text = text;
|
||||
this.View = view;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes render stylistic selections of a <see cref="TabView"/>
|
||||
/// </summary>
|
||||
public class TabStyle {
|
||||
|
||||
/// <summary>
|
||||
/// True to show the top lip of tabs. False to directly begin with tab text during
|
||||
/// rendering. When true header line occupies 3 rows, when false only 2.
|
||||
/// Defaults to true.
|
||||
///
|
||||
/// <para>When <see cref="TabsOnBottom"/> is enabled this instead applies to the
|
||||
/// bottommost line of the control</para>
|
||||
/// </summary>
|
||||
public bool ShowTopLine { get; set; } = true;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// True to show a solid box around the edge of the control. Defaults to true.
|
||||
/// </summary>
|
||||
public bool ShowBorder { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// True to render tabs at the bottom of the view instead of the top
|
||||
/// </summary>
|
||||
public bool TabsOnBottom { get; set; } = false;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes a change in <see cref="TabView.SelectedTab"/>
|
||||
/// </summary>
|
||||
public class TabChangedEventArgs : EventArgs {
|
||||
|
||||
/// <summary>
|
||||
/// The previously selected tab. May be null
|
||||
/// </summary>
|
||||
public Tab OldTab { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The currently selected tab. May be null
|
||||
/// </summary>
|
||||
public Tab NewTab { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Documents a tab change
|
||||
/// </summary>
|
||||
/// <param name="oldTab"></param>
|
||||
/// <param name="newTab"></param>
|
||||
public TabChangedEventArgs (Tab oldTab, Tab newTab)
|
||||
{
|
||||
OldTab = oldTab;
|
||||
NewTab = newTab;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -6,137 +6,7 @@ using System.Linq;
|
||||
|
||||
namespace Terminal.Gui {
|
||||
|
||||
/// <summary>
|
||||
/// Describes how to render a given column in a <see cref="TableView"/> including <see cref="Alignment"/>
|
||||
/// and textual representation of cells (e.g. date formats)
|
||||
///
|
||||
/// <a href="https://migueldeicaza.github.io/gui.cs/articles/tableview.html">See TableView Deep Dive for more information</a>.
|
||||
/// </summary>
|
||||
public class ColumnStyle {
|
||||
|
||||
/// <summary>
|
||||
/// Defines the default alignment for all values rendered in this column. For custom alignment based on cell contents use <see cref="AlignmentGetter"/>.
|
||||
/// </summary>
|
||||
public TextAlignment Alignment {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Defines a delegate for returning custom alignment per cell based on cell values. When specified this will override <see cref="Alignment"/>
|
||||
/// </summary>
|
||||
public Func<object,TextAlignment> AlignmentGetter;
|
||||
|
||||
/// <summary>
|
||||
/// Defines a delegate for returning custom representations of cell values. If not set then <see cref="object.ToString()"/> is used. Return values from your delegate may be truncated e.g. based on <see cref="MaxWidth"/>
|
||||
/// </summary>
|
||||
public Func<object,string> RepresentationGetter;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the format for values e.g. "yyyy-MM-dd" for dates
|
||||
/// </summary>
|
||||
public string Format{get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Set the maximum width of the column in characters. This value will be ignored if more than the tables <see cref="TableView.MaxCellWidth"/>. Defaults to <see cref="TableView.DefaultMaxCellWidth"/>
|
||||
/// </summary>
|
||||
public int MaxWidth {get;set;} = TableView.DefaultMaxCellWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Set the minimum width of the column in characters. This value will be ignored if more than the tables <see cref="TableView.MaxCellWidth"/> or the <see cref="MaxWidth"/>
|
||||
/// </summary>
|
||||
public int MinWidth {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the alignment for the cell based on <paramref name="cellValue"/> and <see cref="AlignmentGetter"/>/<see cref="Alignment"/>
|
||||
/// </summary>
|
||||
/// <param name="cellValue"></param>
|
||||
/// <returns></returns>
|
||||
public TextAlignment GetAlignment(object cellValue)
|
||||
{
|
||||
if(AlignmentGetter != null)
|
||||
return AlignmentGetter(cellValue);
|
||||
|
||||
return Alignment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the full string to render (which may be truncated if too long) that the current style says best represents the given <paramref name="value"/>
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public string GetRepresentation (object value)
|
||||
{
|
||||
if(!string.IsNullOrWhiteSpace(Format)) {
|
||||
|
||||
if(value is IFormattable f)
|
||||
return f.ToString(Format,null);
|
||||
}
|
||||
|
||||
|
||||
if(RepresentationGetter != null)
|
||||
return RepresentationGetter(value);
|
||||
|
||||
return value?.ToString();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Defines rendering options that affect how the table is displayed.
|
||||
///
|
||||
/// <a href="https://migueldeicaza.github.io/gui.cs/articles/tableview.html">See TableView Deep Dive for more information</a>.
|
||||
/// </summary>
|
||||
public class TableStyle {
|
||||
|
||||
/// <summary>
|
||||
/// When scrolling down always lock the column headers in place as the first row of the table
|
||||
/// </summary>
|
||||
public bool AlwaysShowHeaders {get;set;} = false;
|
||||
|
||||
/// <summary>
|
||||
/// True to render a solid line above the headers
|
||||
/// </summary>
|
||||
public bool ShowHorizontalHeaderOverline {get;set;} = true;
|
||||
|
||||
/// <summary>
|
||||
/// True to render a solid line under the headers
|
||||
/// </summary>
|
||||
public bool ShowHorizontalHeaderUnderline {get;set;} = true;
|
||||
|
||||
/// <summary>
|
||||
/// True to render a solid line vertical line between cells
|
||||
/// </summary>
|
||||
public bool ShowVerticalCellLines {get;set;} = true;
|
||||
|
||||
/// <summary>
|
||||
/// True to render a solid line vertical line between headers
|
||||
/// </summary>
|
||||
public bool ShowVerticalHeaderLines {get;set;} = true;
|
||||
|
||||
/// <summary>
|
||||
/// Collection of columns for which you want special rendering (e.g. custom column lengths, text alignment etc)
|
||||
/// </summary>
|
||||
public Dictionary<DataColumn,ColumnStyle> ColumnStyles {get;set; } = new Dictionary<DataColumn, ColumnStyle>();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the entry from <see cref="ColumnStyles"/> for the given <paramref name="col"/> or null if no custom styling is defined for it
|
||||
/// </summary>
|
||||
/// <param name="col"></param>
|
||||
/// <returns></returns>
|
||||
public ColumnStyle GetColumnStyleIfAny (DataColumn col)
|
||||
{
|
||||
return ColumnStyles.TryGetValue(col,out ColumnStyle result) ? result : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an existing <see cref="ColumnStyle"/> for the given <paramref name="col"/> or creates a new one with default options
|
||||
/// </summary>
|
||||
/// <param name="col"></param>
|
||||
/// <returns></returns>
|
||||
public ColumnStyle GetOrCreateColumnStyle (DataColumn col)
|
||||
{
|
||||
if(!ColumnStyles.ContainsKey(col))
|
||||
ColumnStyles.Add(col,new ColumnStyle());
|
||||
|
||||
return ColumnStyles[col];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// View for tabular data based on a <see cref="DataTable"/>.
|
||||
@@ -1234,114 +1104,247 @@ namespace Terminal.Gui {
|
||||
|
||||
return colStyle != null ? colStyle.GetRepresentation(value): value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes a desire to render a column at a given horizontal position in the UI
|
||||
/// </summary>
|
||||
internal class ColumnToRender {
|
||||
|
||||
#region Nested Types
|
||||
/// <summary>
|
||||
/// The column to render
|
||||
/// Describes how to render a given column in a <see cref="TableView"/> including <see cref="Alignment"/>
|
||||
/// and textual representation of cells (e.g. date formats)
|
||||
///
|
||||
/// <a href="https://migueldeicaza.github.io/gui.cs/articles/tableview.html">See TableView Deep Dive for more information</a>.
|
||||
/// </summary>
|
||||
public DataColumn Column {get;set;}
|
||||
public class ColumnStyle {
|
||||
|
||||
/// <summary>
|
||||
/// The horizontal position to begin rendering the column at
|
||||
/// </summary>
|
||||
public int X{get;set;}
|
||||
/// <summary>
|
||||
/// Defines the default alignment for all values rendered in this column. For custom alignment based on cell contents use <see cref="AlignmentGetter"/>.
|
||||
/// </summary>
|
||||
public TextAlignment Alignment { get; set; }
|
||||
|
||||
public ColumnToRender (DataColumn col, int x)
|
||||
{
|
||||
Column = col;
|
||||
X = x;
|
||||
/// <summary>
|
||||
/// Defines a delegate for returning custom alignment per cell based on cell values. When specified this will override <see cref="Alignment"/>
|
||||
/// </summary>
|
||||
public Func<object, TextAlignment> AlignmentGetter;
|
||||
|
||||
/// <summary>
|
||||
/// Defines a delegate for returning custom representations of cell values. If not set then <see cref="object.ToString()"/> is used. Return values from your delegate may be truncated e.g. based on <see cref="MaxWidth"/>
|
||||
/// </summary>
|
||||
public Func<object, string> RepresentationGetter;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the format for values e.g. "yyyy-MM-dd" for dates
|
||||
/// </summary>
|
||||
public string Format { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Set the maximum width of the column in characters. This value will be ignored if more than the tables <see cref="TableView.MaxCellWidth"/>. Defaults to <see cref="TableView.DefaultMaxCellWidth"/>
|
||||
/// </summary>
|
||||
public int MaxWidth { get; set; } = TableView.DefaultMaxCellWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Set the minimum width of the column in characters. This value will be ignored if more than the tables <see cref="TableView.MaxCellWidth"/> or the <see cref="MaxWidth"/>
|
||||
/// </summary>
|
||||
public int MinWidth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the alignment for the cell based on <paramref name="cellValue"/> and <see cref="AlignmentGetter"/>/<see cref="Alignment"/>
|
||||
/// </summary>
|
||||
/// <param name="cellValue"></param>
|
||||
/// <returns></returns>
|
||||
public TextAlignment GetAlignment (object cellValue)
|
||||
{
|
||||
if (AlignmentGetter != null)
|
||||
return AlignmentGetter (cellValue);
|
||||
|
||||
return Alignment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the full string to render (which may be truncated if too long) that the current style says best represents the given <paramref name="value"/>
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public string GetRepresentation (object value)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace (Format)) {
|
||||
|
||||
if (value is IFormattable f)
|
||||
return f.ToString (Format, null);
|
||||
}
|
||||
|
||||
|
||||
if (RepresentationGetter != null)
|
||||
return RepresentationGetter (value);
|
||||
|
||||
return value?.ToString ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines the event arguments for <see cref="TableView.SelectedCellChanged"/>
|
||||
/// </summary>
|
||||
public class SelectedCellChangedEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// The current table to which the new indexes refer. May be null e.g. if selection change is the result of clearing the table from the view
|
||||
/// Defines rendering options that affect how the table is displayed.
|
||||
///
|
||||
/// <a href="https://migueldeicaza.github.io/gui.cs/articles/tableview.html">See TableView Deep Dive for more information</a>.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public DataTable Table {get;}
|
||||
public class TableStyle {
|
||||
|
||||
/// <summary>
|
||||
/// When scrolling down always lock the column headers in place as the first row of the table
|
||||
/// </summary>
|
||||
public bool AlwaysShowHeaders { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The previous selected column index. May be invalid e.g. when the selection has been changed as a result of replacing the existing Table with a smaller one
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int OldCol {get;}
|
||||
/// <summary>
|
||||
/// True to render a solid line above the headers
|
||||
/// </summary>
|
||||
public bool ShowHorizontalHeaderOverline { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// True to render a solid line under the headers
|
||||
/// </summary>
|
||||
public bool ShowHorizontalHeaderUnderline { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// The newly selected column index.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int NewCol {get;}
|
||||
/// <summary>
|
||||
/// True to render a solid line vertical line between cells
|
||||
/// </summary>
|
||||
public bool ShowVerticalCellLines { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// True to render a solid line vertical line between headers
|
||||
/// </summary>
|
||||
public bool ShowVerticalHeaderLines { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// The previous selected row index. May be invalid e.g. when the selection has been changed as a result of deleting rows from the table
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int OldRow {get;}
|
||||
/// <summary>
|
||||
/// Collection of columns for which you want special rendering (e.g. custom column lengths, text alignment etc)
|
||||
/// </summary>
|
||||
public Dictionary<DataColumn, ColumnStyle> ColumnStyles { get; set; } = new Dictionary<DataColumn, ColumnStyle> ();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the entry from <see cref="ColumnStyles"/> for the given <paramref name="col"/> or null if no custom styling is defined for it
|
||||
/// </summary>
|
||||
/// <param name="col"></param>
|
||||
/// <returns></returns>
|
||||
public ColumnStyle GetColumnStyleIfAny (DataColumn col)
|
||||
{
|
||||
return ColumnStyles.TryGetValue (col, out ColumnStyle result) ? result : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The newly selected row index.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int NewRow {get;}
|
||||
/// <summary>
|
||||
/// Returns an existing <see cref="ColumnStyle"/> for the given <paramref name="col"/> or creates a new one with default options
|
||||
/// </summary>
|
||||
/// <param name="col"></param>
|
||||
/// <returns></returns>
|
||||
public ColumnStyle GetOrCreateColumnStyle (DataColumn col)
|
||||
{
|
||||
if (!ColumnStyles.ContainsKey (col))
|
||||
ColumnStyles.Add (col, new ColumnStyle ());
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of arguments describing a change in selected cell in a <see cref="TableView"/>
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <param name="oldCol"></param>
|
||||
/// <param name="newCol"></param>
|
||||
/// <param name="oldRow"></param>
|
||||
/// <param name="newRow"></param>
|
||||
public SelectedCellChangedEventArgs(DataTable t, int oldCol, int newCol, int oldRow, int newRow)
|
||||
{
|
||||
Table = t;
|
||||
OldCol = oldCol;
|
||||
NewCol = newCol;
|
||||
OldRow = oldRow;
|
||||
NewRow = newRow;
|
||||
return ColumnStyles [col];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes a selected region of the table
|
||||
/// </summary>
|
||||
public class TableSelection
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Corner of the <see cref="Rect"/> where selection began
|
||||
/// Describes a desire to render a column at a given horizontal position in the UI
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Point Origin{get;set;}
|
||||
internal class ColumnToRender {
|
||||
|
||||
/// <summary>
|
||||
/// Area selected
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Rect Rect { get; set;}
|
||||
/// <summary>
|
||||
/// The column to render
|
||||
/// </summary>
|
||||
public DataColumn Column { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new selected area starting at the origin corner and covering the provided rectangular area
|
||||
/// </summary>
|
||||
/// <param name="origin"></param>
|
||||
/// <param name="rect"></param>
|
||||
public TableSelection(Point origin, Rect rect)
|
||||
{
|
||||
Origin = origin;
|
||||
Rect = rect;
|
||||
/// <summary>
|
||||
/// The horizontal position to begin rendering the column at
|
||||
/// </summary>
|
||||
public int X { get; set; }
|
||||
|
||||
public ColumnToRender (DataColumn col, int x)
|
||||
{
|
||||
Column = col;
|
||||
X = x;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines the event arguments for <see cref="TableView.SelectedCellChanged"/>
|
||||
/// </summary>
|
||||
public class SelectedCellChangedEventArgs : EventArgs {
|
||||
/// <summary>
|
||||
/// The current table to which the new indexes refer. May be null e.g. if selection change is the result of clearing the table from the view
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public DataTable Table { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The previous selected column index. May be invalid e.g. when the selection has been changed as a result of replacing the existing Table with a smaller one
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int OldCol { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The newly selected column index.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int NewCol { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The previous selected row index. May be invalid e.g. when the selection has been changed as a result of deleting rows from the table
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int OldRow { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The newly selected row index.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int NewRow { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of arguments describing a change in selected cell in a <see cref="TableView"/>
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <param name="oldCol"></param>
|
||||
/// <param name="newCol"></param>
|
||||
/// <param name="oldRow"></param>
|
||||
/// <param name="newRow"></param>
|
||||
public SelectedCellChangedEventArgs (DataTable t, int oldCol, int newCol, int oldRow, int newRow)
|
||||
{
|
||||
Table = t;
|
||||
OldCol = oldCol;
|
||||
NewCol = newCol;
|
||||
OldRow = oldRow;
|
||||
NewRow = newRow;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes a selected region of the table
|
||||
/// </summary>
|
||||
public class TableSelection {
|
||||
|
||||
/// <summary>
|
||||
/// Corner of the <see cref="Rect"/> where selection began
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Point Origin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Area selected
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Rect Rect { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new selected area starting at the origin corner and covering the provided rectangular area
|
||||
/// </summary>
|
||||
/// <param name="origin"></param>
|
||||
/// <param name="rect"></param>
|
||||
public TableSelection (Point origin, Rect rect)
|
||||
{
|
||||
Origin = origin;
|
||||
Rect = rect;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace UICatalog.Scenarios {
|
||||
}
|
||||
|
||||
|
||||
private void OnSelectedCellChanged (SelectedCellChangedEventArgs e)
|
||||
private void OnSelectedCellChanged (TableView.SelectedCellChangedEventArgs e)
|
||||
{
|
||||
selectedCellLabel.Text = $"{tableView.SelectedRow},{tableView.SelectedColumn}";
|
||||
|
||||
|
||||
@@ -436,9 +436,9 @@ namespace UICatalog {
|
||||
Height = Dim.Fill ()
|
||||
};
|
||||
|
||||
tabView.AddTab (new Tab ("Find", FindTab ()), isFind);
|
||||
tabView.AddTab (new TabView.Tab ("Find", FindTab ()), isFind);
|
||||
var replace = ReplaceTab ();
|
||||
tabView.AddTab (new Tab ("Replace", replace), !isFind);
|
||||
tabView.AddTab (new TabView.Tab ("Replace", replace), !isFind);
|
||||
tabView.SelectedTabChanged += (s, e) => tabView.SelectedTab.View.FocusFirst ();
|
||||
winDialog.Add (tabView);
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace UICatalog.Scenarios {
|
||||
New ();
|
||||
}
|
||||
|
||||
private void UpdateStatus (Tab newTab)
|
||||
private void UpdateStatus (TabView.Tab newTab)
|
||||
{
|
||||
lblStatus.Text = $"Len:{(newTab?.View?.Text?.Length ?? 0)}";
|
||||
}
|
||||
@@ -212,7 +212,7 @@ namespace UICatalog.Scenarios {
|
||||
return true;
|
||||
}
|
||||
|
||||
private class OpenedFile : Tab {
|
||||
private class OpenedFile : TabView.Tab {
|
||||
|
||||
|
||||
public FileInfo File { get; set; }
|
||||
|
||||
@@ -60,18 +60,18 @@ namespace UICatalog.Scenarios {
|
||||
};
|
||||
|
||||
|
||||
tabView.AddTab (new Tab ("Tab1", new Label ("hodor!")), false);
|
||||
tabView.AddTab (new Tab ("Tab2", new Label ("durdur")), false);
|
||||
tabView.AddTab (new Tab ("Interactive Tab", GetInteractiveTab ()), false);
|
||||
tabView.AddTab (new Tab ("Big Text", GetBigTextFileTab ()), false);
|
||||
tabView.AddTab (new Tab (
|
||||
tabView.AddTab (new TabView.Tab ("Tab1", new Label ("hodor!")), false);
|
||||
tabView.AddTab (new TabView.Tab ("Tab2", new Label ("durdur")), false);
|
||||
tabView.AddTab (new TabView.Tab ("Interactive Tab", GetInteractiveTab ()), false);
|
||||
tabView.AddTab (new TabView.Tab ("Big Text", GetBigTextFileTab ()), false);
|
||||
tabView.AddTab (new TabView.Tab (
|
||||
"Long name Tab, I mean seriously long. Like you would not believe how long this tab's name is its just too much really woooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooowwww thats long",
|
||||
new Label ("This tab has a very long name which should be truncated. See TabView.MaxTabTextWidth")),
|
||||
false);
|
||||
tabView.AddTab (new Tab ("Les Mise" + Char.ConvertFromUtf32 (Int32.Parse ("0301", NumberStyles.HexNumber)) + "rables", new Label ("This tab name is unicode")), false);
|
||||
tabView.AddTab (new TabView.Tab ("Les Mise" + Char.ConvertFromUtf32 (Int32.Parse ("0301", NumberStyles.HexNumber)) + "rables", new Label ("This tab name is unicode")), false);
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
tabView.AddTab (new Tab ($"Tab{i}", new Label ($"Welcome to tab {i}")), false);
|
||||
tabView.AddTab (new TabView.Tab ($"Tab{i}", new Label ($"Welcome to tab {i}")), false);
|
||||
}
|
||||
|
||||
tabView.SelectedTab = tabView.Tabs.First ();
|
||||
@@ -120,7 +120,7 @@ namespace UICatalog.Scenarios {
|
||||
|
||||
private void AddBlankTab ()
|
||||
{
|
||||
tabView.AddTab (new Tab (), false);
|
||||
tabView.AddTab (new TabView.Tab (), false);
|
||||
}
|
||||
|
||||
private View GetInteractiveTab ()
|
||||
|
||||
@@ -235,19 +235,19 @@ namespace UICatalog.Scenarios {
|
||||
|
||||
private void SetDemoTableStyles ()
|
||||
{
|
||||
var alignMid = new ColumnStyle() {
|
||||
var alignMid = new TableView.ColumnStyle () {
|
||||
Alignment = TextAlignment.Centered
|
||||
};
|
||||
var alignRight = new ColumnStyle() {
|
||||
var alignRight = new TableView.ColumnStyle () {
|
||||
Alignment = TextAlignment.Right
|
||||
};
|
||||
|
||||
var dateFormatStyle = new ColumnStyle() {
|
||||
var dateFormatStyle = new TableView.ColumnStyle () {
|
||||
Alignment = TextAlignment.Right,
|
||||
RepresentationGetter = (v)=> v is DateTime d ? d.ToString("yyyy-MM-dd"):v.ToString()
|
||||
};
|
||||
|
||||
var negativeRight = new ColumnStyle() {
|
||||
var negativeRight = new TableView.ColumnStyle () {
|
||||
|
||||
Format = "0.##",
|
||||
MinWidth = 10,
|
||||
|
||||
@@ -14,13 +14,13 @@ namespace Terminal.Gui.Views {
|
||||
return GetTabView (out _, out _);
|
||||
}
|
||||
|
||||
private TabView GetTabView (out Tab tab1, out Tab tab2)
|
||||
private TabView GetTabView (out TabView.Tab tab1, out TabView.Tab tab2)
|
||||
{
|
||||
InitFakeDriver ();
|
||||
|
||||
var tv = new TabView ();
|
||||
tv.AddTab (tab1 = new Tab ("Tab1", new TextField ("hi")), false);
|
||||
tv.AddTab (tab2 = new Tab ("Tab2", new Label ("hi2")), false);
|
||||
tv.AddTab (tab1 = new TabView.Tab ("Tab1", new TextField ("hi")), false);
|
||||
tv.AddTab (tab2 = new TabView.Tab ("Tab2", new Label ("hi2")), false);
|
||||
return tv;
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@ namespace Terminal.Gui.Views {
|
||||
InitFakeDriver ();
|
||||
|
||||
var tv = new TabView ();
|
||||
Tab tab1;
|
||||
Tab tab2;
|
||||
tv.AddTab (tab1 = new Tab ("Tab1", new TextField ("hi")), false);
|
||||
tv.AddTab (tab2 = new Tab ("Tab1", new Label ("hi2")), true);
|
||||
TabView.Tab tab1;
|
||||
TabView.Tab tab2;
|
||||
tv.AddTab (tab1 = new TabView.Tab ("Tab1", new TextField ("hi")), false);
|
||||
tv.AddTab (tab2 = new TabView.Tab ("Tab1", new Label ("hi2")), true);
|
||||
|
||||
Assert.Equal (2, tv.Tabs.Count);
|
||||
Assert.Equal (tab2, tv.SelectedTab);
|
||||
@@ -82,8 +82,8 @@ namespace Terminal.Gui.Views {
|
||||
|
||||
tv.SelectedTab = tab1;
|
||||
|
||||
Tab oldTab = null;
|
||||
Tab newTab = null;
|
||||
TabView.Tab oldTab = null;
|
||||
TabView.Tab newTab = null;
|
||||
int called = 0;
|
||||
|
||||
tv.SelectedTabChanged += (s, e) => {
|
||||
@@ -143,13 +143,13 @@ namespace Terminal.Gui.Views {
|
||||
{
|
||||
var tv = GetTabView (out var tab1, out var tab2);
|
||||
|
||||
Tab tab3;
|
||||
Tab tab4;
|
||||
Tab tab5;
|
||||
TabView.Tab tab3;
|
||||
TabView.Tab tab4;
|
||||
TabView.Tab tab5;
|
||||
|
||||
tv.AddTab (tab3 = new Tab (), false);
|
||||
tv.AddTab (tab4 = new Tab (), false);
|
||||
tv.AddTab (tab5 = new Tab (), false);
|
||||
tv.AddTab (tab3 = new TabView.Tab (), false);
|
||||
tv.AddTab (tab4 = new TabView.Tab (), false);
|
||||
tv.AddTab (tab5 = new TabView.Tab (), false);
|
||||
|
||||
tv.SelectedTab = tab1;
|
||||
|
||||
|
||||
@@ -297,7 +297,7 @@ namespace Terminal.Gui.Views {
|
||||
|
||||
// select the last row
|
||||
tableView.MultiSelectedRegions.Clear();
|
||||
tableView.MultiSelectedRegions.Push(new TableSelection(new Point(0,3), new Rect(0,3,4,1)));
|
||||
tableView.MultiSelectedRegions.Push(new TableView.TableSelection (new Point(0,3), new Rect(0,3,4,1)));
|
||||
|
||||
Assert.Equal(4,tableView.GetAllSelectedCells().Count());
|
||||
|
||||
@@ -399,8 +399,8 @@ namespace Terminal.Gui.Views {
|
||||
*/
|
||||
|
||||
tableView.MultiSelectedRegions.Clear();
|
||||
tableView.MultiSelectedRegions.Push(new TableSelection(new Point(1,1),new Rect(1,1,2,2)));
|
||||
tableView.MultiSelectedRegions.Push(new TableSelection(new Point(7,3),new Rect(7,3,2,1)));
|
||||
tableView.MultiSelectedRegions.Push(new TableView.TableSelection(new Point(1,1),new Rect(1,1,2,2)));
|
||||
tableView.MultiSelectedRegions.Push(new TableView.TableSelection (new Point(7,3),new Rect(7,3,2,1)));
|
||||
|
||||
tableView.SelectedColumn = 8;
|
||||
tableView.SelectedRow = 3;
|
||||
|
||||
Reference in New Issue
Block a user