DatePicker now uses DimAuto with caveats

This commit is contained in:
Tig
2024-05-15 09:41:25 -07:00
parent d21489cbf8
commit 11da4cffe0
2 changed files with 30 additions and 16 deletions

View File

@@ -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;

View File

@@ -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 ();
}
}