Skip to content

Commit

Permalink
Raise PointerEvents from floatingContent
Browse files Browse the repository at this point in the history
  • Loading branch information
taivasverkko committed May 9, 2024
1 parent b6b0c3e commit 9ed433b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/LibVLCSharp.Avalonia/VideoView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class VideoView : NativeControlHost
/// </summary>
public static readonly StyledProperty<object?> ContentProperty =
AvaloniaProperty.Register<VideoView, object?>(nameof(Content));

/// <summary>
/// Gets or sets the MediaPlayer that will be displayed.
/// </summary>
Expand Down Expand Up @@ -69,7 +69,7 @@ public object? Content
get => GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}

/// <inheritdoc />
public VideoView()
{
Expand Down Expand Up @@ -210,15 +210,24 @@ private void InitializeNativeOverlay()
DataContext = DataContext
};
_floatingContent.Bind(ContentControl.ContentProperty, this.GetObservable(ContentProperty));
_floatingContent.PointerEntered += FloatingContentOnPointerEvent;
_floatingContent.PointerExited += FloatingContentOnPointerEvent;
_floatingContent.PointerPressed += FloatingContentOnPointerEvent;
_floatingContent.PointerReleased += FloatingContentOnPointerEvent;

ContentProperty.Changed.AddClassHandler<VideoView>((o, _) => o.UpdateOverlayPosition());
BoundsProperty.Changed.AddClassHandler<VideoView>((o, _) => o.UpdateOverlayPosition());
visualRoot.PositionChanged += (_, _) => UpdateOverlayPosition();
}

ShowNativeOverlay(IsEffectivelyVisible);
}

private void FloatingContentOnPointerEvent(object? sender, PointerEventArgs e)
{
RaiseEvent(e);
}

private void ShowNativeOverlay(bool show)
{
if (_floatingContent == null || _floatingContent.IsVisible == show || VisualRoot is not Window visualRoot)
Expand Down Expand Up @@ -257,6 +266,10 @@ protected override void DestroyNativeControlCore(IPlatformHandle control)
Detach();
if (_floatingContent != null)
{
_floatingContent.PointerEntered -= FloatingContentOnPointerEvent;
_floatingContent.PointerExited -= FloatingContentOnPointerEvent;
_floatingContent.PointerPressed -= FloatingContentOnPointerEvent;
_floatingContent.PointerReleased -= FloatingContentOnPointerEvent;
_floatingContent.Close();
_floatingContent = null;
}
Expand Down

0 comments on commit 9ed433b

Please sign in to comment.