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

同じ色の要素が連なっているとき、どのフレームの境界がわかりにくいので、縁を表示した #713

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Beutl/ViewModels/ElementViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Beutl.Services;
using Beutl.Utilities;

using FluentAvalonia.UI.Media;

using Reactive.Bindings;
using Reactive.Bindings.Extensions;

Expand Down Expand Up @@ -65,6 +67,9 @@ public ElementViewModel(Element element, TimelineViewModel timeline)
.ToReactiveProperty()
.AddTo(_disposables);

RestBorderColor = Color.Select(v => (Avalonia.Media.Color)((Color2)v).LightenPercent(-0.15f))
.ToReadOnlyReactivePropertySlim()!;

TextColor = Color.Select(GetTextColor)
.ToReadOnlyReactivePropertySlim()
.AddTo(_disposables);
Expand Down Expand Up @@ -148,6 +153,8 @@ public ElementViewModel(Element element, TimelineViewModel timeline)

public ReactiveProperty<Avalonia.Media.Color> Color { get; }

public ReadOnlyReactivePropertySlim<Avalonia.Media.Color> RestBorderColor { get; }

public ReadOnlyReactivePropertySlim<Avalonia.Media.Color> TextColor { get; }

public ReactiveCommand<Func<TimeSpan>?> Split { get; } = new();
Expand Down
8 changes: 5 additions & 3 deletions src/Beutl/Views/ElementView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
Margin="{Binding BorderMargin.Value}"
HorizontalAlignment="Left"
Background="{Binding Color.Value, Converter={StaticResource ColorToBrushConverter}}"
BorderBrush="{DynamicResource TextControlForeground}"
BorderThickness="1"
Classes.selected="{Binding IsSelected.Value}">
<Border.Styles>
<Style Selector="Border.selected">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Padding" Value="-1" />
<Setter Property="BorderBrush" Value="{DynamicResource TextControlForeground}" />
</Style>
<Style Selector="Border:not(.selected)">
<Setter Property="BorderBrush" Value="{Binding RestBorderColor.Value, Converter={StaticResource ColorToBrushConverter}}" />
</Style>
</Border.Styles>
<Border.Resources>
Expand Down
29 changes: 13 additions & 16 deletions src/Beutl/Views/ElementView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

using FluentAvalonia.UI.Controls;

using Reactive.Bindings.Extensions;

using Setter = Avalonia.Styling.Setter;

namespace Beutl.Views;
Expand All @@ -29,9 +31,9 @@ namespace Beutl.Views;

public sealed partial class ElementView : UserControl
{
private readonly CompositeDisposable _disposables = new();
private Timeline? _timeline;
private TimeSpan _pointerPosition;
private IDisposable? _disposable1;
private static ColorPickerFlyout? s_colorPickerFlyout;

public ElementView()
Expand Down Expand Up @@ -70,8 +72,7 @@ protected override void OnKeyDown(KeyEventArgs e)
private void OnDataContextDetached(ElementViewModel obj)
{
obj.AnimationRequested = (_, _) => Task.CompletedTask;
_disposable1?.Dispose();
_disposable1 = null;
_disposables.Clear();
}

private void OnDataContextAttached(ElementViewModel obj)
Expand Down Expand Up @@ -139,8 +140,15 @@ await Dispatcher.UIThread.InvokeAsync(async () =>
});
};

_disposable1 = obj.Model.GetObservable(Element.IsEnabledProperty)
.Subscribe(b => Dispatcher.UIThread.InvokeAsync(() => border.Opacity = b ? 1 : 0.5));
obj.Model.GetObservable(Element.IsEnabledProperty)
.ObserveOnUIDispatcher()
.Subscribe(b => border.Opacity = b ? 1 : 0.5)
.DisposeWith(_disposables);

obj.IsSelected
.ObserveOnUIDispatcher()
.Subscribe(v => ZIndex = v ? 5 : 0)
.DisposeWith(_disposables);
}

protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
Expand Down Expand Up @@ -541,7 +549,6 @@ protected override void OnAttached()
if (AssociatedObject != null)
{
AssociatedObject.AddHandler(PointerPressedEvent, OnPointerPressed, RoutingStrategies.Tunnel);
AssociatedObject.AddHandler(PointerReleasedEvent, OnPointerReleased, RoutingStrategies.Tunnel);
AssociatedObject.border.AddHandler(PointerPressedEvent, OnBorderPointerPressed);
AssociatedObject.border.AddHandler(PointerReleasedEvent, OnBorderPointerReleased);
}
Expand All @@ -553,7 +560,6 @@ protected override void OnDetaching()
if (AssociatedObject != null)
{
AssociatedObject.AddHandler(PointerPressedEvent, OnPointerPressed, RoutingStrategies.Tunnel);
AssociatedObject.AddHandler(PointerReleasedEvent, OnPointerReleased, RoutingStrategies.Tunnel);
AssociatedObject.border.RemoveHandler(PointerPressedEvent, OnBorderPointerPressed);
AssociatedObject.border.RemoveHandler(PointerReleasedEvent, OnBorderPointerReleased);
}
Expand All @@ -563,22 +569,13 @@ private void OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (AssociatedObject is { } obj)
{
obj.ZIndex = 5;
if (!obj.textBox.IsFocused)
{
obj.Focus();
}
}
}

private void OnPointerReleased(object? sender, PointerReleasedEventArgs e)
{
if (AssociatedObject is { } obj)
{
obj.ZIndex = 0;
}
}

private void OnBorderPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (AssociatedObject is { _timeline: { } } obj)
Expand Down