Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading spinner #684

Merged
merged 13 commits into from
Dec 19, 2023
Merged

Loading spinner #684

merged 13 commits into from
Dec 19, 2023

Conversation

falko17
Copy link
Collaborator

@falko17 falko17 commented Dec 16, 2023

This implements a loading spinner, intended to be displayed for long-running operations.
The spinner is displayed in the upper left corner of the screen (as the other corners are already occupied) – if there is more than one long-running process active, a small number will be displayed indicating how many processes are currently running. Hovering over the spinner yields a tooltip containing a short message describing the running processes.

Usage

The loading spinner can be accessed via static methods. A short, and especially a unique message should be passed to the Show method – this is what's shown to the user.
This message is used to identify the loading process, and is later used to hide the spinner again once the process has completed running. If no message is passed to Show, a random one will be generated to ensure uniqueness.

Recommended method

using (LoadingSpinner.Show("Loading message")) 
{
     // Do something that takes a long time here.
     // The loading spinner will be shown while this is running,
     // and hidden once control flow leaves this block.
}

Alternative: Using the IDisposable

IDisposable disposable = LoadingSpinner.Show("Loading message"); 
// Do something that takes a long time here.
disposable.Dispose();

Alternative: Using the message

LoadingSpinner.Show("Loading message");
// Do something that takes a long time here.
LoadingSpinner.Hide("Loading message");  // must be the same message!

Additional changes

  • A utility method RunOnMainThread has been implemented by request of @Leon2796. When called from the thread pool, it switches to the main thread only for the given action. This is useful because certain methods and properties are not accessible from the thread pool.
  • A bug in the tooltip has been fixed that lead to it appearing when it is disabled and then enabled.

@falko17 falko17 added the enhancement New feature or request label Dec 16, 2023
@falko17 falko17 requested review from koschke and Leon2796 December 16, 2023 22:04
@falko17 falko17 self-assigned this Dec 16, 2023
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few bad patterns I found which you should check.

Copy link
Collaborator

@koschke koschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Only one minor change request.

I answered the TODO questions. You can replace the TODO comments accordingly.

@falko17 falko17 force-pushed the loading-spinner branch 2 times, most recently from 10730fd to 4481719 Compare December 18, 2023 15:31
@falko17 falko17 requested a review from koschke December 18, 2023 15:40
@koschke koschke merged commit 9823b7d into master Dec 19, 2023
@koschke koschke deleted the loading-spinner branch December 19, 2023 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants