Files
Terminal.Gui/UICatalog/Scenarios/TimeAndDate.cs
Tig 16055c53b0 Fixes #3039. Fix View.HotKey (#3249)
* Added View.DefaultCommand etc... Started on dedicated scenario

* Fixed un-shifted hotkeys -> Fixed Key Equals. Fixed WindowsDriver passing wrong key. Etc.

* Fixed Key Bindings and HotKeys

* Fixed Key Bindings and HotKeys

* Label now correctly supports hotkey

* Disabled unix hot keys because they are annoying and get in the way

* Updated nuget. fixed warnings

* Trying to fix ci/ci issue

* Trying to fix ci/ci issue

* Trying to fix ci/ci issue

* Changed TextChangingEventArgs to inherit from CancelEventArgs

* TextChangingEventArgs -> TextEventArgs

* Simplified Text events by having only on args class

* Fixed unit tests fail

* Simplified by removing TitleEventArgs

* POC of Title being primary for hotkey. Label and Button hacked to work

* POC of Title being primary for hotkey. Label and Button hacked to work - all unit tests pass

* Dropped Microsoft.NETFramework.ReferenceAssemblies

* Fixed Dialogs scenario hotkeys

* Fixed build warnings

* Fixed Border Title render bug

* Regiggering default command handling

* Regiggering default command handling

* Checkbox clean up

* Added StateEventArgs POC

* Command.Default -> Command.HotKey

* Command.Default -> Command.HotKey - fixed TableView

* Command.Default -> Command.HotKey - fixed TableView

* Updated reactive example

* Fixed Toplevel.BringOverlappedTopToFront - was reordering SubViews when it shouldn't

* WIP - broke

* Finished impl of StateEventArgs

* Deleted ToggleEventArgs.cs. Added StateEventArgs.cs

* XML doc fix

* Removed old code

* Removed commented out code

* Label.Clicked -> Label.Accept (missed this before)

* Removed Labels as Buttons scenario as it's not really  useful

* Moved SubView tests to own file

* Moved SubView tests to own file

* Simplified Text test

* Added OnAccept test

* Deleted DefaultCommand

* Modernized CheckBox

* New button test

* Cleaned up RadioGroup; added tests

* KeyCode->Key in ListView

* Added ListView unit tests

* ListView now does Accept correctly

* TreeView now does Accept correctly

* Cleaned up some TextField tests

* TextView now handles Accept properly; updated CharMap and Adornments scenarios to test

* Fixed ComboBox to deal with TextView now handles Accept properly; updated CharMap and Adornments scenarios to test

* Removed un-needed using statement
2024-02-22 15:11:26 -07:00

155 lines
4.6 KiB
C#

using System;
using Terminal.Gui;
namespace UICatalog.Scenarios;
[ScenarioMetadata ("Time And Date", "Illustrates TimeField and time & date handling")]
[ScenarioCategory ("Controls")]
[ScenarioCategory ("DateTime")]
public class TimeAndDate : Scenario
{
private Label _lblDateFmt;
private Label _lblNewDate;
private Label _lblNewTime;
private Label _lblOldDate;
private Label _lblOldTime;
private Label _lblTimeFmt;
public override void Setup ()
{
var longTime = new TimeField
{
X = Pos.Center (),
Y = 2,
IsShortFormat = false,
ReadOnly = false,
Time = DateTime.Now.TimeOfDay
};
longTime.TimeChanged += TimeChanged;
Win.Add (longTime);
var shortTime = new TimeField
{
X = Pos.Center (),
Y = Pos.Bottom (longTime) + 1,
IsShortFormat = true,
ReadOnly = false,
Time = DateTime.Now.TimeOfDay
};
shortTime.TimeChanged += TimeChanged;
Win.Add (shortTime);
var shortDate = new DateField (DateTime.Now)
{
X = Pos.Center (), Y = Pos.Bottom (shortTime) + 1, ReadOnly = true
};
shortDate.DateChanged += DateChanged;
Win.Add (shortDate);
var longDate = new DateField (DateTime.Now)
{
X = Pos.Center (), Y = Pos.Bottom (shortDate) + 1, ReadOnly = false
};
longDate.DateChanged += DateChanged;
Win.Add (longDate);
_lblOldTime = new Label
{
X = Pos.Center (),
Y = Pos.Bottom (longDate) + 1,
TextAlignment = TextAlignment.Centered,
AutoSize = false,
Width = Dim.Fill (),
Text = "Old Time: "
};
Win.Add (_lblOldTime);
_lblNewTime = new Label
{
X = Pos.Center (),
Y = Pos.Bottom (_lblOldTime) + 1,
TextAlignment = TextAlignment.Centered,
AutoSize = false,
Width = Dim.Fill (),
Text = "New Time: "
};
Win.Add (_lblNewTime);
_lblTimeFmt = new Label
{
X = Pos.Center (),
Y = Pos.Bottom (_lblNewTime) + 1,
TextAlignment = TextAlignment.Centered,
AutoSize = false,
Width = Dim.Fill (),
Text = "Time Format: "
};
Win.Add (_lblTimeFmt);
_lblOldDate = new Label
{
X = Pos.Center (),
Y = Pos.Bottom (_lblTimeFmt) + 2,
TextAlignment = TextAlignment.Centered,
AutoSize = false,
Width = Dim.Fill (),
Text = "Old Date: "
};
Win.Add (_lblOldDate);
_lblNewDate = new Label
{
X = Pos.Center (),
Y = Pos.Bottom (_lblOldDate) + 1,
TextAlignment = TextAlignment.Centered,
AutoSize = false,
Width = Dim.Fill (),
Text = "New Date: "
};
Win.Add (_lblNewDate);
_lblDateFmt = new Label
{
X = Pos.Center (),
Y = Pos.Bottom (_lblNewDate) + 1,
TextAlignment = TextAlignment.Centered,
AutoSize = false,
Width = Dim.Fill (),
Text = "Date Format: "
};
Win.Add (_lblDateFmt);
var swapButton = new Button
{
X = Pos.Center (), Y = Pos.Bottom (Win) - 5, Text = "Swap Long/Short & Read/Read Only"
};
swapButton.Accept += (s, e) =>
{
longTime.ReadOnly = !longTime.ReadOnly;
shortTime.ReadOnly = !shortTime.ReadOnly;
longTime.IsShortFormat = !longTime.IsShortFormat;
shortTime.IsShortFormat = !shortTime.IsShortFormat;
longDate.ReadOnly = !longDate.ReadOnly;
shortDate.ReadOnly = !shortDate.ReadOnly;
};
Win.Add (swapButton);
}
private void DateChanged (object sender, DateTimeEventArgs<DateTime> e)
{
_lblOldDate.Text = $"Old Date: {e.OldValue}";
_lblNewDate.Text = $"New Date: {e.NewValue}";
_lblDateFmt.Text = $"Date Format: {e.Format}";
}
private void TimeChanged (object sender, DateTimeEventArgs<TimeSpan> e)
{
_lblOldTime.Text = $"Old Time: {e.OldValue}";
_lblNewTime.Text = $"New Time: {e.NewValue}";
_lblTimeFmt.Text = $"Time Format: {e.Format}";
}
}