From 11da4cffe089eba2327ac06987f8cb5eb9fde0aa Mon Sep 17 00:00:00 2001 From: Tig Date: Wed, 15 May 2024 09:41:25 -0700 Subject: [PATCH] DatePicker now uses DimAuto with caveats --- Terminal.Gui/Views/DatePicker.cs | 30 ++++++++++++++++-------------- UICatalog/Scenarios/DatePickers.cs | 16 ++++++++++++++-- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Terminal.Gui/Views/DatePicker.cs b/Terminal.Gui/Views/DatePicker.cs index 075c9f890..a044f2a70 100644 --- a/Terminal.Gui/Views/DatePicker.cs +++ b/Terminal.Gui/Views/DatePicker.cs @@ -65,8 +65,6 @@ public class DatePicker : View base.Dispose (disposing); } - private int CalculateCalendarWidth () { return _calendar.Style.ColumnStyles.Sum (c => c.Value.MinWidth) + 7; } - private void ChangeDayDate (int day) { _date = new DateTime (_date.Year, _date.Month, day); @@ -160,7 +158,8 @@ public class DatePicker : View _table.Columns.Add (abbreviatedDayName); } - _calendar.Width = CalculateCalendarWidth (); + // TODO: Get rid of the +7 which is hackish + _calendar.Width = _calendar.Style.ColumnStyles.Sum (c => c.Value.MinWidth) + 7; } private string GetBackButtonText () { return Glyphs.LeftArrow + Glyphs.LeftArrow.ToString (); } @@ -189,15 +188,6 @@ public class DatePicker : View Date = date; _dateLabel = new Label { X = 0, Y = 0, Text = "Date: " }; - _dateField = new DateField (DateTime.Now) - { - X = Pos.Right (_dateLabel), - Y = 0, - Width = Dim.Fill (1), - Height = 1, - Culture = Culture - }; - _calendar = new TableView { X = 0, @@ -212,6 +202,15 @@ public class DatePicker : View } }; + _dateField = new DateField (DateTime.Now) + { + X = Pos.Right (_dateLabel), + Y = 0, + Width = 12,//Dim.Width (_calendar) - Dim.Width(_dateLabel), // BUGBUG: Fix when Dim.Auto(subviews) fully works + Height = 1, + Culture = Culture + }; + _previousMonthButton = new Button { X = Pos.Center () - 2, @@ -274,8 +273,11 @@ public class DatePicker : View Text = _date.ToString (Format); }; - Width = CalculateCalendarWidth () + 2; - Height = _calendar.Height + 3; + Height = Dim.Auto (); + Width = Dim.Auto (); + + // BUGBUG: Remove when Dim.Auto(subviews) fully works + SetContentSize(new (_calendar.Style.ColumnStyles.Sum (c => c.Value.MinWidth) + 7, _calendar.Frame.Height + 1)); _dateField.DateChanged += DateField_DateChanged; diff --git a/UICatalog/Scenarios/DatePickers.cs b/UICatalog/Scenarios/DatePickers.cs index 7cfe9430e..1790c7dbc 100644 --- a/UICatalog/Scenarios/DatePickers.cs +++ b/UICatalog/Scenarios/DatePickers.cs @@ -7,10 +7,22 @@ namespace UICatalog.Scenarios; [ScenarioCategory ("DateTime")] public class DatePickers : Scenario { - public override void Setup () + public override void Main () { + Application.Init (); + + Window app = new () + { + Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}" + }; + var datePicker = new DatePicker { Y = Pos.Center (), X = Pos.Center () }; - Win.Add (datePicker); + app.Add (datePicker); + + Application.Run (app); + app.Dispose (); + + Application.Shutdown (); } }