Skip to content

Commit

Permalink
refactor: Status bar collapses after 5 secs
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilien-noal committed Dec 29, 2024
1 parent 9366924 commit 4620a44
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Spice86/ViewModels/DebugWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public DebugWindowViewModel(State cpuState, Stack stack, IMemory memory, Midi ex
_messenger = messenger;
_uiDispatcher = uiDispatcher;
BreakpointsViewModel = new(emulatorBreakpointsManager);
StatusMessageViewModel = new(_messenger);
StatusMessageViewModel = new(_uiDispatcher, _messenger);
_pauseHandler = pauseHandler;
IsPaused = pauseHandler.IsPaused;
pauseHandler.Pausing += () => uiDispatcher.Post(() => IsPaused = true);
Expand Down
15 changes: 14 additions & 1 deletion src/Spice86/ViewModels/StatusMessageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@ namespace Spice86.ViewModels;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;

using Spice86.Infrastructure;
using Spice86.Messages;

public partial class StatusMessageViewModel : ViewModelBase, IRecipient<StatusMessage> {
private readonly IUIDispatcher _uiDispatcher;

[ObservableProperty]
private StatusMessage? _message;

public StatusMessageViewModel(IMessenger messenger) => messenger.Register(this);
[ObservableProperty]
private bool _isVisible;

public StatusMessageViewModel(IUIDispatcher dispatcher, IMessenger messenger) {
messenger.Register(this);
_uiDispatcher = dispatcher;
}

public void Receive(StatusMessage message) {
Message = message;
IsVisible = true;
Task.Delay(millisecondsDelay: 5000).ContinueWith(_ => {
_uiDispatcher.Post(() => IsVisible = false);
});
}
}
2 changes: 1 addition & 1 deletion src/Spice86/Views/StatusMessageView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Spice86.Views.StatusMessageView"
x:DataType="viewModels:StatusMessageViewModel">
<controls:StatusBar>
<controls:StatusBar IsVisible="{Binding IsVisible}">
<controls:StatusBarItem>
<TextBlock DataContext="{Binding Message}">
<Run Text="{Binding Time}" />
Expand Down

0 comments on commit 4620a44

Please sign in to comment.