namespace Terminal.Gui; /// /// Describes how to render a given column in a including and /// textual representation of cells (e.g. date formats) /// See TableView Deep Dive for more information. /// public class ColumnStyle { /// /// Defines a delegate for returning custom alignment per cell based on cell values. When specified this will /// override /// public Func AlignmentGetter; /// /// Defines a delegate for returning a custom color scheme per cell based on cell values. Return null for the /// default /// public CellColorGetterDelegate ColorGetter; /// /// Defines a delegate for returning custom representations of cell values. If not set then /// is used. Return values from your delegate may be truncated e.g. based on /// /// public Func RepresentationGetter; private bool _visible = true; /// /// Defines the default alignment for all values rendered in this column. For custom alignment based on cell /// contents use . /// public Alignment Alignment { get; set; } /// Defines the format for values e.g. "yyyy-MM-dd" for dates public string Format { get; set; } /// /// Set the maximum width of the column in characters. This value will be ignored if more than the tables /// . Defaults to /// public int MaxWidth { get; set; } = TableView.DefaultMaxCellWidth; /// Enables flexible sizing of this column based on available screen space to render into. public int MinAcceptableWidth { get; set; } = TableView.DefaultMinAcceptableWidth; /// /// Set the minimum width of the column in characters. Setting this will ensure that even when a column has short /// content/header it still fills a given width of the control. /// /// This value will be ignored if more than the tables or the /// /// /// For setting a flexible column width (down to a lower limit) use instead /// public int MinWidth { get; set; } /// /// Gets or Sets a value indicating whether the column should be visible to the user. This affects both whether it /// is rendered and whether it can be selected. Defaults to true. /// /// If is 0 then will always return false. public bool Visible { get => MaxWidth >= 0 && _visible; set => _visible = value; } /// /// Returns the alignment for the cell based on and / /// /// /// /// public Alignment GetAlignment (object cellValue) { if (AlignmentGetter is { }) { return AlignmentGetter (cellValue); } return Alignment; } /// /// Returns the full string to render (which may be truncated if too long) that the current style says best /// represents the given /// /// /// public string GetRepresentation (object value) { if (!string.IsNullOrWhiteSpace (Format)) { if (value is IFormattable f) { return f.ToString (Format, null); } } if (RepresentationGetter is { }) { return RepresentationGetter (value); } return value?.ToString (); } }