Skip to content

Commit

Permalink
Merge pull request #705 from b-editor/improve-xaml
Browse files Browse the repository at this point in the history
XAMLの改善
  • Loading branch information
yuto-trd authored Sep 10, 2023
2 parents cbae61a + 56781c5 commit 94e45bc
Show file tree
Hide file tree
Showing 14 changed files with 784 additions and 803 deletions.
10 changes: 0 additions & 10 deletions src/Beutl.Controls/Behaviors/SharedContent.cs

This file was deleted.

30 changes: 0 additions & 30 deletions src/Beutl.Controls/Behaviors/SharedContentTemplate.cs

This file was deleted.

27 changes: 0 additions & 27 deletions src/Beutl.Controls/Behaviors/TextBoxBehaviour.cs

This file was deleted.

20 changes: 4 additions & 16 deletions src/Beutl.Controls/Styles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<ResourceInclude Source="/Styling/SegmentedControl.axaml" />
<ResourceInclude Source="/Styling/LiteNav.axaml" />
<ResourceInclude Source="/Styling/FlipButton.axaml" />
<ResourceInclude Source="/Styling/OptionsDisplayItem.axaml" />
<ResourceInclude Source="/Styling/BcTabItem.axaml" />
<ResourceInclude Source="/Styling/BcTabView.axaml" />
<ResourceInclude Source="/Styling/Player.axaml" />

<ResourceInclude Source="/Styling/PropertyEditors/PropertyEditorResources.axaml" />
<ResourceInclude Source="/Styling/PropertyEditors/StringEditor.axaml" />
Expand Down Expand Up @@ -84,18 +88,6 @@
<Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
</Style>

<Style Selector="TextBox">
<Setter Property="(i:Interaction.Behaviors)">
<b:SharedContentTemplate>
<b:SharedContent>
<i:BehaviorCollection>
<b:TextBoxBehaviour />
</i:BehaviorCollection>
</b:SharedContent>
</b:SharedContentTemplate>
</Setter>
</Style>

<Style Selector=":is(InputElement).transparent">
<Setter Property="Opacity" Value="0" />
<Setter Property="IsHitTestVisible" Value="False" />
Expand All @@ -111,9 +103,5 @@
<Setter Property="Height" Value="24" />
</Style>

<StyleInclude Source="avares://Beutl.Controls/Styling/BcTabItem.axaml" />
<StyleInclude Source="avares://Beutl.Controls/Styling/BcTabView.axaml" />
<StyleInclude Source="avares://Beutl.Controls/Styling/NavigationView.axaml" />
<StyleInclude Source="avares://Beutl.Controls/Styling/OptionsDisplayItem.axaml" />
<StyleInclude Source="avares://Beutl.Controls/Styling/Player.axaml" />
</Styles>
329 changes: 164 additions & 165 deletions src/Beutl.Controls/Styling/BcTabItem.axaml

Large diffs are not rendered by default.

656 changes: 325 additions & 331 deletions src/Beutl.Controls/Styling/BcTabView.axaml

Large diffs are not rendered by default.

392 changes: 195 additions & 197 deletions src/Beutl.Controls/Styling/OptionsDisplayItem.axaml

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/Beutl.Controls/Styling/Player.axaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Beutl.Controls"
xmlns:icons="using:FluentIcons.FluentAvalonia">
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Beutl.Controls"
xmlns:icons="using:FluentIcons.FluentAvalonia">
<Design.PreviewWith>
<controls:Player Width="600"
Height="300"
Value="00:00:00"
Duration="00:10:00" />
</Design.PreviewWith>

<Style Selector="controls|Player">
<ControlTheme x:Key="{x:Type controls:Player}" TargetType="controls:Player">
<Setter Property="Template">
<ControlTemplate>
<Grid RowDefinitions="*,Auto">
Expand Down Expand Up @@ -106,5 +106,5 @@
</Grid>
</ControlTemplate>
</Setter>
</Style>
</Styles>
</ControlTheme>
</ResourceDictionary>
78 changes: 78 additions & 0 deletions src/Beutl.Controls/TextBoxAttachment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;

namespace Beutl.Controls;

public static class TextBoxAttachment
{
public static readonly AttachedProperty<EnterBehaviorMode> EnterDownBehaviorProperty =
AvaloniaProperty.RegisterAttached<TextBox, EnterBehaviorMode>("EnterDownBehavior", typeof(TextBoxAttachment), EnterBehaviorMode.None);

static TextBoxAttachment()
{
EnterDownBehaviorProperty.Changed.Subscribe(ev =>
{
if (ev.Sender is TextBox tb && ev.NewValue.HasValue)
{
if (ev.NewValue.Value != EnterBehaviorMode.None)
{
tb.AddHandler(InputElement.KeyDownEvent, OnTextBoxKeyDown, RoutingStrategies.Tunnel);
}
else
{
tb.RemoveHandler(InputElement.KeyDownEvent, OnTextBoxKeyDown);
}
}
});
}

public enum EnterBehaviorMode
{
None,
LostFocus,
Auto
}

public static EnterBehaviorMode GetEnterDownBehavior(TextBox obj)
{
return obj.GetValue(EnterDownBehaviorProperty);
}

public static void SetEnterDownBehavior(TextBox obj, EnterBehaviorMode value)
{
obj.SetValue(EnterDownBehaviorProperty, value);
}

private static void OnTextBoxKeyDown(object sender, KeyEventArgs e)
{
if (sender is TextBox tb
&& e.Key == Key.Enter)
{
EnterBehaviorMode mode = GetEnterDownBehavior(tb);
if (mode == EnterBehaviorMode.None) return;
if (mode == EnterBehaviorMode.Auto && tb.AcceptsReturn && !e.KeyModifiers.HasFlag(KeyModifiers.Control)) return;

foreach (InputElement item in tb.GetLogicalSiblings().SkipWhile(v => v != tb).Skip(1).OfType<InputElement>())
{
if (item.Focus())
{
e.Handled = true;
return;
}
}


foreach (InputElement item in tb.GetLogicalAncestors().OfType<InputElement>())
{
if (item.Focus())
{
e.Handled = true;
return;
}
}
}
}
}
17 changes: 2 additions & 15 deletions src/Beutl/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
xmlns:uip="using:FluentAvalonia.UI.Controls.Primitives">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--<ResourceInclude Source="avares://Avalonia.Themes.Fluent/Controls/ContextMenu.xaml" />-->
</ResourceDictionary.MergedDictionaries>

<convert:AvaloniaPixelSizeConverter x:Key="PixelSizeConverter" />
<convert:TimeSpanToDoubleConverter x:Key="TimeSpanToDoubleConverter" />
<aconverters:ColorToBrushConverter x:Key="ColorToBrushConverter" />

<ControlTheme x:Key="LabelTextBlockStyle" TargetType="TextBlock">
Expand Down Expand Up @@ -53,13 +47,6 @@
<StyleInclude Source="avares://Beutl.Controls/Styles.axaml" />
<StyleInclude Source="avares://FluentAvalonia.BreadcrumbBar/Styling/Styles.axaml" />

<Style Selector="TextBlock.ErrorTextBlockStyle">
<Setter Property="Foreground" Value="{DynamicResource SystemFillColorCriticalBrush}" />
<Setter Property="Opacity" Value="0.7" />
<Setter Property="FontWeight" Value="SemiBold" />
<Setter Property="FontSize" Value="12" />
</Style>

<Style Selector="TextBlock.error">
<Setter Property="Foreground" Value="{DynamicResource SystemFillColorCriticalBrush}" />
<Setter Property="FontWeight" Value="SemiBold" />
Expand Down Expand Up @@ -154,8 +141,8 @@
<Setter Property="ClipToBounds" Value="False" />
</Style>

<Style Selector="ui|CommandBar /template/ ItemsControl#PrimaryItemsControl">
<Setter Property="HorizontalAlignment" Value="{Binding ItemsAlignment, RelativeSource={RelativeSource TemplatedParent}}" />
<Style Selector="TextBox">
<Setter Property="(TextBoxAttachment.EnterDownBehavior)" Value="Auto" />
</Style>
</Application.Styles>
</Application>
2 changes: 2 additions & 0 deletions src/Beutl/Converters/TimeSpanToDoubleConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Beutl.Converters;

public sealed class TimeSpanToDoubleConverter : IValueConverter
{
public static readonly TimeSpanToDoubleConverter Instance = new();

public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is TimeSpan ts)
Expand Down
4 changes: 2 additions & 2 deletions src/Beutl/Views/Dialogs/CreateNewProject.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ui:ContentDialog x:Class="Beutl.Views.Dialogs.CreateNewProject"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="using:Beutl.Converters"
xmlns:converters="clr-namespace:Beutl.Converters;assembly=Beutl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:icons="using:FluentIcons.FluentAvalonia"
xmlns:lang="using:Beutl.Language"
Expand All @@ -25,7 +25,7 @@
<Carousel.Items>
<StackPanel Spacing="8">
<TextBlock Text="{x:Static lang:Strings.Name}" />
<TextBox Classes="enableIME" Text="{CompiledBinding Name.Value, Mode=TwoWay}" />
<TextBox Text="{CompiledBinding Name.Value, Mode=TwoWay}" />

<TextBlock Margin="0,8,0,0" Text="{x:Static lang:Strings.Location}" />

Expand Down
3 changes: 2 additions & 1 deletion src/Beutl/Views/Dialogs/CreateNewScene.axaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<ui:ContentDialog x:Class="Beutl.Views.Dialogs.CreateNewScene"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:Beutl.Converters;assembly=Beutl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:icons="using:FluentIcons.FluentAvalonia"
xmlns:lang="using:Beutl.Language"
Expand Down Expand Up @@ -37,7 +38,7 @@
</Panel>

<TextBlock Margin="0,8,0,0" Text="{x:Static lang:Strings.Size}" />
<TextBox Text="{CompiledBinding Size.Value, Mode=TwoWay, Converter={StaticResource PixelSizeConverter}}" />
<TextBox Text="{CompiledBinding Size.Value, Mode=TwoWay, Converter={x:Static converters:AvaloniaPixelSizeConverter.Instance}}" />

<CheckBox Margin="0,8,0,0"
Content="{x:Static lang:Strings.AddToCurrentProject}"
Expand Down
5 changes: 3 additions & 2 deletions src/Beutl/Views/EditView.axaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<UserControl x:Class="Beutl.Views.EditView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:Beutl.Converters;assembly=Beutl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:editors="using:Beutl.Views.Editors"
xmlns:local="using:Beutl.Views"
Expand Down Expand Up @@ -103,13 +104,13 @@
CurrentTime="{CompiledBinding Player.CurrentFrame.Value, StringFormat={}{0:hh\\:mm\\:ss\\.ff}}"
EndButtonCommand="{CompiledBinding Player.End}"
IsPlaying="{CompiledBinding Player.IsPlaying.Value, Mode=TwoWay}"
Maximum="{CompiledBinding Player.Duration.Value, Converter={StaticResource TimeSpanToDoubleConverter}}"
Maximum="{CompiledBinding Player.Duration.Value, Converter={x:Static converters:TimeSpanToDoubleConverter.Instance}}"
NextButtonCommand="{CompiledBinding Player.Next}"
PlayButtonCommand="{CompiledBinding Player.PlayPause}"
PreviousButtonCommand="{CompiledBinding Player.Previous}"
Source="{CompiledBinding Player.PreviewImage.Value, Mode=OneWay}"
StartButtonCommand="{CompiledBinding Player.Start}"
Value="{CompiledBinding Player.CurrentFrame.Value, Converter={StaticResource TimeSpanToDoubleConverter}}"
Value="{CompiledBinding Player.CurrentFrame.Value, Converter={x:Static converters:TimeSpanToDoubleConverter.Instance}}"
Duration="{CompiledBinding Player.Duration.Value, StringFormat={}{0:hh\\:mm\\:ss\\.ff}}" />
</Grid>

Expand Down

0 comments on commit 94e45bc

Please sign in to comment.