mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-28 00:38:00 +01:00
Added Format property to ColumnStyle
This commit is contained in:
@@ -26,6 +26,11 @@ namespace Terminal.Gui.Views {
|
||||
/// </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>
|
||||
@@ -56,6 +61,13 @@ namespace Terminal.Gui.Views {
|
||||
/// <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);
|
||||
|
||||
|
||||
@@ -145,9 +145,7 @@ namespace UICatalog.Scenarios {
|
||||
|
||||
var negativeRight = new ColumnStyle() {
|
||||
|
||||
RepresentationGetter = (v)=> v is double d ?
|
||||
d.ToString("0.##"):
|
||||
v.ToString(),
|
||||
Format = "0.##",
|
||||
MinWidth = 10,
|
||||
AlignmentGetter = (v)=>v is double d ?
|
||||
// align negative values right
|
||||
|
||||
Reference in New Issue
Block a user