Browse Source

Finished node picker

flabbet 11 months ago
parent
commit
75216063db

+ 3 - 2
src/PixiEditor.UI.Common/Controls/ListBoxItem.axaml

@@ -5,9 +5,10 @@
         <Setter Property="Background" Value="Transparent" />
         <Setter Property="Background" Value="Transparent" />
         <Setter Property="BorderBrush" Value="Transparent" />
         <Setter Property="BorderBrush" Value="Transparent" />
         <Setter Property="BorderThickness" Value="0" />
         <Setter Property="BorderThickness" Value="0" />
+        <Setter Property="Height" Value="30"/>
         <Setter Property="Template">
         <Setter Property="Template">
             <ControlTemplate>
             <ControlTemplate>
-                <Border Height="40" 
+                <Border MinHeight="20" 
                         BorderBrush="{TemplateBinding BorderBrush}"
                         BorderBrush="{TemplateBinding BorderBrush}"
                         BorderThickness="{TemplateBinding BorderThickness}"
                         BorderThickness="{TemplateBinding BorderThickness}"
                         Background="{TemplateBinding Background}"
                         Background="{TemplateBinding Background}"
@@ -19,7 +20,7 @@
                     </Border.Styles>
                     </Border.Styles>
                     
                     
                     <Grid>
                     <Grid>
-                        <Rectangle RadiusX="8" RadiusY="8" Width="16" Height="32" IsVisible="False" Fill="{DynamicResource ThemeAccentBrush}" HorizontalAlignment="Left">
+                        <Rectangle RadiusX="8" RadiusY="8" Width="16" MinHeight="20" IsVisible="False" Fill="{DynamicResource ThemeAccentBrush}" HorizontalAlignment="Left">
                             <Rectangle.Styles>
                             <Rectangle.Styles>
                                 <Style Selector=":selected /template/ Rectangle">
                                 <Style Selector=":selected /template/ Rectangle">
                                     <Setter Property="IsVisible" Value="True"></Setter>
                                     <Setter Property="IsVisible" Value="True"></Setter>

+ 2 - 1
src/PixiEditor/Styles/Templates/NodePicker.axaml

@@ -23,6 +23,7 @@
                                     Name="PART_InputBox" />
                                     Name="PART_InputBox" />
 
 
                     <ListBox Grid.Column="0" Grid.Row="1" ItemsSource="{TemplateBinding FilteredCategories}"
                     <ListBox Grid.Column="0" Grid.Row="1" ItemsSource="{TemplateBinding FilteredCategories}"
+                             BorderBrush="{DynamicResource ThemeBorderLowBrush}" BorderThickness="0 0 1 0"
                              SelectedItem="{Binding SelectedCategory, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}">
                              SelectedItem="{Binding SelectedCategory, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}">
                         <ListBox.ItemTemplate>
                         <ListBox.ItemTemplate>
                             <DataTemplate>
                             <DataTemplate>
@@ -32,7 +33,7 @@
                             </DataTemplate>
                             </DataTemplate>
                         </ListBox.ItemTemplate>
                         </ListBox.ItemTemplate>
                     </ListBox>
                     </ListBox>
-
+                    
                     <ScrollViewer Grid.Row="1" Grid.Column="1" Name="PART_ScrollViewer"
                     <ScrollViewer Grid.Row="1" Grid.Column="1" Name="PART_ScrollViewer"
                                   Offset="{Binding ScrollOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}">
                                   Offset="{Binding ScrollOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}">
                         <ItemsControl MinHeight="200" Name="PART_NodeList"
                         <ItemsControl MinHeight="200" Name="PART_NodeList"

+ 15 - 3
src/PixiEditor/Views/Nodes/NodePicker.cs

@@ -5,6 +5,7 @@ using Avalonia.Controls;
 using Avalonia.Controls.Metadata;
 using Avalonia.Controls.Metadata;
 using Avalonia.Controls.Primitives;
 using Avalonia.Controls.Primitives;
 using Avalonia.Input;
 using Avalonia.Input;
+using Avalonia.Threading;
 using PixiEditor.Helpers.Nodes;
 using PixiEditor.Helpers.Nodes;
 using PixiEditor.ViewModels.Nodes;
 using PixiEditor.ViewModels.Nodes;
 using PixiEditor.Views.Input;
 using PixiEditor.Views.Input;
@@ -95,6 +96,7 @@ public partial class NodePicker : TemplatedControl
 
 
     private ItemsControl? _itemsControl;
     private ItemsControl? _itemsControl;
     private ScrollViewer? _scrollViewer;
     private ScrollViewer? _scrollViewer;
+    private InputBox? _inputBox;
 
 
     private const string MiscCategory = "MISC";
     private const string MiscCategory = "MISC";
 
 
@@ -109,15 +111,21 @@ public partial class NodePicker : TemplatedControl
 
 
     protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
     protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
     {
     {
-        var inputBox = e.NameScope.Find<InputBox>("PART_InputBox");
+        _inputBox = e.NameScope.Find<InputBox>("PART_InputBox");
 
 
-        inputBox.KeyDown += OnInputBoxKeyDown;
+        _inputBox.KeyDown += OnInputBoxKeyDown;
 
 
         _itemsControl = e.NameScope.Find<ItemsControl>("PART_NodeList");
         _itemsControl = e.NameScope.Find<ItemsControl>("PART_NodeList");
         _scrollViewer = e.NameScope.Find<ScrollViewer>("PART_ScrollViewer");
         _scrollViewer = e.NameScope.Find<ScrollViewer>("PART_ScrollViewer");
         _scrollViewer.ScrollChanged += Scrolled;
         _scrollViewer.ScrollChanged += Scrolled;
     }
     }
 
 
+    protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
+    {
+        base.OnAttachedToVisualTree(e);
+        Dispatcher.UIThread.Post(() => _inputBox?.Focus(), DispatcherPriority.Input);
+    }
+
     private void Scrolled(object? sender, ScrollChangedEventArgs e)
     private void Scrolled(object? sender, ScrollChangedEventArgs e)
     {
     {
         if (e.OffsetDelta.Y != 0)
         if (e.OffsetDelta.Y != 0)
@@ -168,6 +176,8 @@ public partial class NodePicker : TemplatedControl
                 FilterCategories(nodePicker);
                 FilterCategories(nodePicker);
             }
             }
         }
         }
+        
+        nodePicker.SelectedCategory = nodePicker.FilteredCategories.FirstOrDefault();
     }
     }
 
 
 
 
@@ -255,6 +265,8 @@ public partial class NodePicker : TemplatedControl
 
 
             nodePicker.FilteredNodeGroups = nodePicker.NodeTypeGroupsFromQuery(null); 
             nodePicker.FilteredNodeGroups = nodePicker.NodeTypeGroupsFromQuery(null); 
             FilterCategories(nodePicker);
             FilterCategories(nodePicker);
+            
+            nodePicker.SelectedCategory = nodePicker.FilteredCategories.FirstOrDefault();
         }
         }
     }
     }
 
 
@@ -274,7 +286,7 @@ public partial class NodePicker : TemplatedControl
     {
     {
         if (e.Sender is NodePicker nodePicker)
         if (e.Sender is NodePicker nodePicker)
         {
         {
-            if (nodePicker.SuppressCategoryChanged)
+            if (nodePicker.SuppressCategoryChanged || nodePicker._scrollViewer == null)
             {
             {
                 return;
                 return;
             }
             }