From b32a620af0fc4cf0cf47abccc58465d8e3bd9295 Mon Sep 17 00:00:00 2001 From: Chris Pulman Date: Mon, 29 Jul 2024 01:03:42 +0100 Subject: [PATCH] Update Terminal --- .../Views/FeedbackView.xaml.cs | 4 +- src/ReactiveMvvm.Terminal/Extensions.cs | 2 +- src/ReactiveMvvm.Terminal/Program.cs | 2 +- .../ReactiveMvvm.Terminal.csproj | 4 +- .../Views/FeedbackView.cs | 43 ++++++++++--------- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/ReactiveMvvm.Maui/Views/FeedbackView.xaml.cs b/src/ReactiveMvvm.Maui/Views/FeedbackView.xaml.cs index 80f372e..be0b56e 100644 --- a/src/ReactiveMvvm.Maui/Views/FeedbackView.xaml.cs +++ b/src/ReactiveMvvm.Maui/Views/FeedbackView.xaml.cs @@ -21,7 +21,7 @@ public FeedbackView() this.OneWayBind(ViewModel, x => x.TitleLengthMax, x => x.TitleEntry.MaxLength) .DisposeWith(subscriptions); - this.WhenAnyValue(x => x.ViewModel.TitleLength, x => x.ViewModel.TitleLengthMax) + this.WhenAnyValue(x => x.ViewModel!.TitleLength, x => x.ViewModel!.TitleLengthMax) .Select(values => $"{values.Item1} letters used from {values.Item2}") .BindTo(this, x => x.TitleLengthEntry.Text) .DisposeWith(subscriptions); @@ -31,7 +31,7 @@ public FeedbackView() this.OneWayBind(ViewModel, x => x.MessageLengthMax, x => x.MessageEntry.MaxLength) .DisposeWith(subscriptions); - this.WhenAnyValue(x => x.ViewModel.MessageLength, x => x.ViewModel.MessageLengthMax) + this.WhenAnyValue(x => x.ViewModel!.MessageLength, x => x.ViewModel!.MessageLengthMax) .Select(values => $"{values.Item1} letters used from {values.Item2}") .BindTo(this, x => x.MessageLengthEntry.Text) .DisposeWith(subscriptions); diff --git a/src/ReactiveMvvm.Terminal/Extensions.cs b/src/ReactiveMvvm.Terminal/Extensions.cs index cc9795e..69e0766 100644 --- a/src/ReactiveMvvm.Terminal/Extensions.cs +++ b/src/ReactiveMvvm.Terminal/Extensions.cs @@ -9,7 +9,7 @@ public static MemoizedElement StackPanel( TNew control) where TOwner : View where TNew : View => - new MemoizedElement(owner, control); + new(owner, control); public static MemoizedElement Append( this MemoizedElement owner, diff --git a/src/ReactiveMvvm.Terminal/Program.cs b/src/ReactiveMvvm.Terminal/Program.cs index 531ca4c..0d3040d 100644 --- a/src/ReactiveMvvm.Terminal/Program.cs +++ b/src/ReactiveMvvm.Terminal/Program.cs @@ -14,7 +14,7 @@ public static void Main(string[] args) Application.Init(); Application.Run( new FeedbackView( - new FeedbackViewModel( + new( new TerminalSender(), new Clock()))); } diff --git a/src/ReactiveMvvm.Terminal/ReactiveMvvm.Terminal.csproj b/src/ReactiveMvvm.Terminal/ReactiveMvvm.Terminal.csproj index 1e4f254..044a450 100644 --- a/src/ReactiveMvvm.Terminal/ReactiveMvvm.Terminal.csproj +++ b/src/ReactiveMvvm.Terminal/ReactiveMvvm.Terminal.csproj @@ -4,8 +4,10 @@ net8.0 + - + + diff --git a/src/ReactiveMvvm.Terminal/Views/FeedbackView.cs b/src/ReactiveMvvm.Terminal/Views/FeedbackView.cs index 00544c7..a384c1b 100644 --- a/src/ReactiveMvvm.Terminal/Views/FeedbackView.cs +++ b/src/ReactiveMvvm.Terminal/Views/FeedbackView.cs @@ -14,29 +14,28 @@ public sealed class FeedbackView : Window, IViewFor, IDisposa { private readonly CompositeDisposable _subscriptions = []; - public FeedbackView(FeedbackViewModel viewModel) : - base(new Rect(0, 0, 30, 20)) + public FeedbackView(FeedbackViewModel viewModel) { ViewModel = viewModel; ViewModel.Activator.Activate(); this.StackPanel(TimeElapsedLabel()) - .Append(new Label("Issue Title")) + .Append(new Label() { Text = "Issue Title" }) .Append(TitleDescription()) .Append(TitleInput()) - .Append(new Label("Issue Description")) + .Append(new Label() { Text = "Issue Description" }) .Append(MessageDescription()) .Append(MessageInput()) - .Append(new Label("Feedback Type")) + .Append(new Label() { Text = "Feedback Type" }) .Append(IssueCheckBox()) .Append(IdeaCheckBox()) - .Append(new Label("Feedback Category")) + .Append(new Label() { Text = "Feedback Category" }) .Append(SectionRadioGroup()) - .Append(new Button("Send Feedback"), 4); + .Append(new Button() { Text = "Send Feedback" }, 4); } private RadioGroup SectionRadioGroup() { - var radioGroup = new RadioGroup(["User Interface", "Audio", "Video", "Voice"]); + var radioGroup = new RadioGroup() { RadioLabels = ["User Interface", "Audio", "Video", "Voice"] }; this.WhenAnyValue(x => x.ViewModel.Section) .BindTo(radioGroup, x => x.SelectedItem) .DisposeWith(_subscriptions); @@ -51,13 +50,14 @@ private RadioGroup SectionRadioGroup() private CheckBox IssueCheckBox() { - var item = new CheckBox("Issue", ViewModel.Issue); + var item = new CheckBox() { Text = "Issue", State = ViewModel.Issue ? CheckState.Checked : CheckState.UnChecked }; this.WhenAnyValue(x => x.ViewModel.Issue) - .BindTo(item, x => x.Checked) + .Select(issue => issue ? CheckState.Checked : CheckState.UnChecked) + .BindTo(item, x => x.State) .DisposeWith(_subscriptions); item.Events() - .Toggled - .Select(args => item.Checked) + .Toggle + .Select(args => args.NewValue == CheckState.Checked) .BindTo(this, x => x.ViewModel.Issue) .DisposeWith(_subscriptions); this.WhenAnyValue(x => x.ViewModel.Idea) @@ -69,13 +69,14 @@ private CheckBox IssueCheckBox() private CheckBox IdeaCheckBox() { - var item = new CheckBox("Suggestion", ViewModel.Idea); + var item = new CheckBox() { Text = "Suggestion", State = ViewModel.Idea ? CheckState.Checked : CheckState.UnChecked }; this.WhenAnyValue(x => x.ViewModel.Idea) - .BindTo(item, x => x.Checked) + .Select(issue => issue ? CheckState.Checked : CheckState.UnChecked) + .BindTo(item, x => x.State) .DisposeWith(_subscriptions); item.Events() - .Toggled - .Select(old => item.Checked) + .Toggle + .Select(args => args.NewValue == CheckState.Checked) .BindTo(this, x => x.ViewModel.Idea) .DisposeWith(_subscriptions); this.WhenAnyValue(x => x.ViewModel.Issue) @@ -87,7 +88,7 @@ private CheckBox IdeaCheckBox() private Label TimeElapsedLabel() { - var label = new Label("0 seconds passed"); + var label = new Label() { Text = "0 seconds passed" }; this.WhenAnyValue(x => x.ViewModel.Elapsed) .Select(elapsed => (ustring) $"{elapsed} seconds passed") .BindTo(label, x => x.Text) @@ -97,7 +98,7 @@ private Label TimeElapsedLabel() private TextField MessageInput() { - var text = new TextField(ViewModel.Message); + var text = new TextField() { Text = ViewModel.Message, Width = 40 }; this.WhenAnyValue(x => x.ViewModel.Message) .BindTo(text, x => x.Text) .DisposeWith(_subscriptions); @@ -112,7 +113,7 @@ private TextField MessageInput() private Label MessageDescription() { - var label = new Label($"0 letters used from {ViewModel.MessageLengthMax}"); + var label = new Label() { Text = $"0 letters used from {ViewModel.MessageLengthMax}" }; this.WhenAnyValue(x => x.ViewModel.MessageLength, x => x.ViewModel.MessageLengthMax) .Select(values => (ustring) $"{values.Item1} letters used from {values.Item2}") .BindTo(label, x => x.Text) @@ -122,7 +123,7 @@ private Label MessageDescription() private TextField TitleInput() { - var text = new TextField(ViewModel.Title); + var text = new TextField() { Text = ViewModel.Title, Width = 40 }; this.WhenAnyValue(x => x.ViewModel.Title) .BindTo(text, x => x.Text) .DisposeWith(_subscriptions); @@ -137,7 +138,7 @@ private TextField TitleInput() private Label TitleDescription() { - var label = new Label($"0 letters used from {ViewModel.TitleLengthMax}"); + var label = new Label() { Text = $"0 letters used from {ViewModel.TitleLengthMax}" }; this.WhenAnyValue(x => x.ViewModel.TitleLength, x => x.ViewModel.TitleLengthMax) .Select(values => (ustring) $"{values.Item1} letters used from {values.Item2}") .BindTo(label, x => x.Text)