More WIndows specific parts moved to this project

This commit is contained in:
Dan Clark
2024-11-02 20:57:13 +00:00
parent 48c63b3bb0
commit 81e39f9895
25 changed files with 528 additions and 68 deletions
+99
View File
@@ -0,0 +1,99 @@
using Toolkit.Foundation;
namespace Toolkit.Windows;
public class TaskbarButton :
ITaskbarButton,
INotificationHandler<PointerReleasedEventArgs>,
INotificationHandler<PointerMovedEventArgs>,
INotificationHandler<PointerDragEventArgs>
{
private readonly IPublisher publisher;
private readonly IDisposer disposer;
private bool isWithinBounds;
private bool isDrag;
public TaskbarButton(string name,
Rect rect,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer)
{
this.publisher = publisher;
this.disposer = disposer;
Name = name;
Rect = rect;
subscriber.Subscribe(this);
}
public Rect Rect { get; internal set; }
public string Name { get; internal set; }
public void Dispose()
{
disposer.Dispose(this);
GC.SuppressFinalize(this);
}
public Task Handle(PointerReleasedEventArgs args)
{
if (!isDrag && isWithinBounds)
{
publisher.Publish(new TaskbarButtonInvokedEventArgs(this));
}
if (isDrag)
{
isDrag = false;
}
return Task.CompletedTask;
}
public Task Handle(PointerDragEventArgs args)
{
if (isWithinBounds)
{
if (isDrag)
{
publisher.Publish(new TaskbarButtonDragOverEventArgs(this));
}
else
{
publisher.Publish(new TaskbarButtonDragEnterEventArgs(this));
}
isDrag = true;
}
else
{
isDrag = false;
}
return Task.CompletedTask;
}
public Task Handle(PointerMovedEventArgs args)
{
if (args.Location.IsWithinBounds(Rect))
{
if (isWithinBounds)
{
return Task.CompletedTask;
}
isWithinBounds = true;
publisher.Publish(new TaskbarButtonEnteredEventArgs(this));
}
else
{
isDrag = false;
isWithinBounds = false;
}
return Task.CompletedTask;
}
}