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

FilterEffectを選択するダイアログを改善 #973

Merged
merged 3 commits into from
Apr 10, 2024
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reactive.Disposables;

using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
Expand All @@ -8,9 +7,7 @@
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using Avalonia.VisualTree;

using Beutl.Reactive;

using FluentAvalonia.Core;

#nullable enable
Expand Down Expand Up @@ -120,7 +117,7 @@ private void OnCloseClick(object? sender, RoutedEventArgs e)

private void OnDragAreaPointerExited(object? sender, PointerEventArgs e)
{
_pressed = false;
// _pressed = false;
}

private void OnDragAreaPointerReleased(object? sender, PointerReleasedEventArgs e)
Expand All @@ -132,30 +129,32 @@ private void OnDragAreaPointerMoved(object? sender, PointerEventArgs e)
{
if (_dragArea == null || !_pressed) return;

PointerPoint pointer = e.GetCurrentPoint(null);
Point point = pointer.Position;
Point delta = point - _point;

if (this.FindLogicalAncestorOfType<Popup>() is { } popup)
{
PointerPoint pointer = e.GetCurrentPoint(null);
Point point = pointer.Position;
Point delta = point - _point;

popup.HorizontalOffset += delta.X;
popup.VerticalOffset += delta.Y;
if (this.FindAncestorOfType<PopupRoot>() == null)
{
_point = point;
}
}
}

private void OnDragAreaPointerPressed(object? sender, PointerPressedEventArgs e)
{
if (_dragArea == null) return;

var root = this.FindAncestorOfType<PopupRoot>();
PointerPoint pointer = e.GetCurrentPoint(null);
if (pointer.Properties.IsLeftButtonPressed)
{
_pressed = true;
_point = pointer.Position;
if (this.FindAncestorOfType<PopupRoot>() is { } root)
{
root.Activate();
}
root?.Activate();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#nullable enable

using System.Diagnostics;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Media.Immutable;
using Beutl.Reactive;
using Beutl.Services;
using FluentAvalonia.UI.Media;
using Reactive.Bindings;

namespace Beutl.Controls.PropertyEditors;

public class FilterEffectPickerFlyoutPresenter : DraggablePickerFlyoutPresenter
{
public static readonly StyledProperty<LibraryItem?> SelectedItemProperty =
AvaloniaProperty.Register<FilterEffectPickerFlyoutPresenter, LibraryItem?>(nameof(SelectedItem));

public static readonly StyledProperty<ReactiveCollection<LibraryItem>?> ItemsProperty =
AvaloniaProperty.Register<FilterEffectPickerFlyoutPresenter, ReactiveCollection<LibraryItem>?>(nameof(Items));

public static readonly StyledProperty<bool> IsBusyProperty =
AvaloniaProperty.Register<FilterEffectPickerFlyoutPresenter, bool>(nameof(IsBusy));

public static readonly StyledProperty<bool> ShowAllProperty =
AvaloniaProperty.Register<FilterEffectPickerFlyoutPresenter, bool>(nameof(ShowAll));

public static readonly StyledProperty<bool> ShowSearchBoxProperty =
AvaloniaProperty.Register<FilterEffectPickerFlyoutPresenter, bool>(nameof(ShowSearchBox));

public static readonly StyledProperty<string?> SearchTextProperty =
AvaloniaProperty.Register<FilterEffectPickerFlyoutPresenter, string?>(nameof(SearchText));

private readonly CompositeDisposable _disposables = [];
private const string SearchBoxPseudoClass = ":search-box";
private const string IsBusyPseudoClass = ":busy";

public LibraryItem? SelectedItem
{
get => GetValue(SelectedItemProperty);
set => SetValue(SelectedItemProperty, value);
}

public ReactiveCollection<LibraryItem>? Items
{
get => GetValue(ItemsProperty);
set => SetValue(ItemsProperty, value);
}

public bool IsBusy
{
get => GetValue(IsBusyProperty);
set => SetValue(IsBusyProperty, value);
}

public bool ShowAll
{
get => GetValue(ShowAllProperty);
set => SetValue(ShowAllProperty, value);
}

public bool ShowSearchBox
{
get => GetValue(ShowSearchBoxProperty);
set => SetValue(ShowSearchBoxProperty, value);
}

public string? SearchText
{
get => GetValue(SearchTextProperty);
set => SetValue(SearchTextProperty, value);
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
_disposables.Clear();
base.OnApplyTemplate(e);
}

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == ShowSearchBoxProperty)
{
PseudoClasses.Set(SearchBoxPseudoClass, ShowSearchBox);
}
else if (change.Property == IsBusyProperty)
{
PseudoClasses.Set(IsBusyPseudoClass, IsBusy);
}
}
}
1 change: 1 addition & 0 deletions src/Beutl.Controls/Styles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<ResourceInclude Source="/Styling/PropertyEditors/SimpleColorPickerFlyoutPresenter.axaml" />
<ResourceInclude Source="/Styling/PropertyEditors/BrushEditorFlyoutPresenter.axaml" />
<ResourceInclude Source="/Styling/PropertyEditors/GradientStopsSlider.axaml" />
<ResourceInclude Source="/Styling/PropertyEditors/FilterEffectPickerFlyoutPresenter.axaml" />
</ResourceDictionary.MergedDictionaries>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviors="using:Beutl.Controls.Behaviors"
xmlns:lang="using:Beutl.Language"
xmlns:service="using:Beutl.Services"
xmlns:local="using:Beutl.Controls.PropertyEditors"
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
x:CompileBindings="True">
<Design.PreviewWith>
<Border Height="600" Padding="50">
<local:FilterEffectPickerFlyoutPresenter VerticalAlignment="Center">
<local:SimpleColorPicker />
</local:FilterEffectPickerFlyoutPresenter>
</Border>
</Design.PreviewWith>

<ControlTheme x:Key="{x:Type local:FilterEffectPickerFlyoutPresenter}"
TargetType="local:FilterEffectPickerFlyoutPresenter">
<Setter Property="Width" Value="240" />
<Setter Property="ShowHideButtons" Value="True" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="Background" Value="{DynamicResource FlyoutPresenterBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource FlyoutBorderThemeBrush}" />
<Setter Property="BorderThickness" Value="{StaticResource FlyoutBorderThemeThickness}" />
<Setter Property="Padding" Value="0" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="CornerRadius" Value="{DynamicResource OverlayCornerRadius}" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
<Setter Property="Template">
<ControlTemplate>
<ui:FABorder Padding="{DynamicResource FlyoutBorderThemePadding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Grid RowDefinitions="Auto,Auto,Auto">
<Grid Name="DragArea"
Height="40"
VerticalAlignment="Top"
Background="Transparent"
ColumnDefinitions="*,Auto">
<WrapPanel Name="TabLayout" Margin="4,4,0,4">
<ToggleButton IsChecked="{TemplateBinding ShowSearchBox, Mode=TwoWay}"
Name="ShowSearchBoxButton">
<ui:SymbolIcon Symbol="Find" />
</ToggleButton>
<ToggleButton Name="ShowAllButton" IsChecked="{TemplateBinding ShowAll, Mode=TwoWay}">
<ui:SymbolIcon Symbol="More" />
</ToggleButton>
</WrapPanel>

<Button Name="CloseButton"
Grid.Column="1"
Width="32"
Height="32"
Margin="4"
Padding="0"
HorizontalAlignment="Right"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Theme="{StaticResource TransparentButton}">
<ui:FontIcon FontFamily="{DynamicResource SymbolThemeFontFamily}" Glyph="&#xE711;" />
</Button>
</Grid>

<Border Grid.Row="2"
BorderBrush="{DynamicResource PickerFlyoutPresenterDivider}"
BorderThickness="0,1,0,0">

<Panel Name="AcceptDismissContainer"
Height="{DynamicResource PickerAcceptDismissRegionHeight}"
IsVisible="False">
<Grid ColumnDefinitions="*,*">
<Button Name="AcceptButton"
Margin="4,4,2,4"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Theme="{StaticResource FlyoutAcceptDismiss}">
<ui:SymbolIcon FontSize="18" Symbol="Checkmark" />
</Button>
<Button Name="DismissButton"
Grid.Column="1"
Margin="2,4,4,4"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Theme="{StaticResource FlyoutAcceptDismiss}">
<ui:SymbolIcon FontSize="16" Symbol="Dismiss" />
</Button>
</Grid>

</Panel>
</Border>

<StackPanel Grid.Row="1">
<TextBox x:Name="SearchTextBox"
Classes="clearButton"
Text="{TemplateBinding SearchText, Mode=TwoWay}"
Margin="6,0,6,6"
IsVisible="False"
Watermark="{x:Static lang:Strings.Search}" />

<ListBox x:Name="PART_ListBox" SelectedItem="{TemplateBinding SelectedItem, Mode=TwoWay}"
ItemsSource="{TemplateBinding Items}" Height="250">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="service:LibraryItem">
<TextBlock VerticalAlignment="Center" Text="{Binding DisplayName}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>

<ProgressRing Name="PART_ProgressRing"
IsVisible="False"
IsIndeterminate="False"
Grid.RowSpan="3"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Grid>
</ui:FABorder>
</ControlTemplate>
</Setter>

<Style Selector="^:acceptdismiss /template/ Panel#AcceptDismissContainer">
<Setter Property="IsVisible" Value="True" />
</Style>
<Style Selector="^:acceptdismiss /template/ Button#CloseButton">
<Setter Property="IsVisible" Value="False" />
</Style>

<Style Selector="^:search-box /template/ TextBox#SearchTextBox">
<Setter Property="IsVisible" Value="True" />
</Style>

<Style Selector="^:busy /template/ ProgressRing#PART_ProgressRing">
<Setter Property="IsVisible" Value="True" />
<Setter Property="IsIndeterminate" Value="True" />
</Style>

<Style Selector="^ /template/ WrapPanel#TabLayout">
<Style Selector="^ > ToggleButton">
<Setter Property="Width" Value="32" />
<Setter Property="Height" Value="32" />
<Setter Property="Margin" Value="0,0,4,0" />
<Setter Property="Theme" Value="{StaticResource ColorPickerTypeTransparentToggleButtonStyle}" />

<Style Selector="^ > ui|FontIcon">
<Setter Property="FontFamily" Value="{DynamicResource SymbolThemeFontFamily}" />
</Style>
</Style>
</Style>
</ControlTheme>
</ResourceDictionary>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Beutl.ViewModels.Dialogs;
public sealed class SelectFilterEffectTypeViewModel : SelectLibraryItemDialogViewModel
{
public SelectFilterEffectTypeViewModel()
: base(KnownLibraryItemFormats.FilterEffect, typeof(FilterEffect), Strings.SelectFilterEffect)
: base(KnownLibraryItemFormats.FilterEffect, typeof(FilterEffect))
{
}
}
Loading
Loading