Improved Drag+Drop & Dark Mode testing

- Drag+Drop now shows a black line where the item is going to be dropped as an additional visual cue to make it more intuitive
- Avalonia's dark default style is lacking two things:
-- Highlights on ListBoxItem are too bright (easy fix)
-- The window decoration remains white (could be disabled and replaced with custom title bar)
This commit is contained in:
adroslice 2019-12-03 20:12:00 +01:00
parent e107be13c4
commit 18a2d7154f
2 changed files with 47 additions and 10 deletions

View File

@ -126,6 +126,18 @@
<Setter Property="Margin" Value="4,-5,4,4"/>
</Style>
<!-- Drag + Drop -->
<Style Selector="ListBoxItem.BlackBottom">
<Setter Property="BorderThickness" Value="0,0,0,2"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="Margin" Value="0,0,0,-2"/>
</Style>
<Style Selector="ListBoxItem.BlackTop">
<Setter Property="BorderThickness" Value="0,2,0,0"/>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="Margin" Value="0,-2,0,0"/>
</Style>
<!-- Expander Fix -->
<Style Selector="Expander /template/ ToggleButton#PART_toggle /template/ Border">
<Setter Property="Background" Value="Transparent"/>
@ -160,7 +172,7 @@
</Grid>
</Button.Content>
</Button>
<Grid Grid.Column="3" Background="Transparent" Cursor="SizeAll" IsVisible="{Binding $parent.IsPointerOver}" ToolTip.Tip="Click and drag to move this operation." PointerPressed="StartMoveOperation" PointerReleased="EndMoveOperation">
<Grid Grid.Column="3" Background="Transparent" Cursor="SizeAll" IsVisible="{Binding $parent.IsPointerOver}" ToolTip.Tip="Click and drag to move this operation." PointerPressed="StartMoveOperation" PointerReleased="EndMoveOperation" PointerMoved="MoveOperation">
<Path Data="M0,0 L12,0 M0,4 L12,4 M0,8 L12,8" Height="8" VerticalAlignment="Center" Margin="4" Stroke="Black" StrokeThickness="2"/>
</Grid>
<ContentPresenter Grid.ColumnSpan="4" Grid.Row="1" Content="{TemplateBinding Content}" IsVisible="{Binding #OperationExpander.IsExpanded}"/>

View File

@ -15,6 +15,7 @@ using Avalonia.LogicalTree;
using BFR.Helpers;
using BFR.DataModels;
using BFR.Operations;
using Avalonia.Markup.Xaml.Styling;
namespace BFR
{
@ -95,22 +96,40 @@ namespace BFR
Preview();
}
private void ClearDropStyling()
{
foreach (ListBoxItem item in OperationsListBox.GetLogicalChildren())
item.Classes.RemoveAll(new[] { "BlackTop", "BlackBottom" });
}
public void StartMoveOperation(object sender, PointerPressedEventArgs e) =>
DragItem = OperationsListBox.GetLogicalChildren().Cast<ListBoxItem>().Single(x => x.IsPointerOver);
public void MoveOperation(object sender, PointerEventArgs e)
{
if (DragItem == null) return;
var hoveredItem = (ListBoxItem)OperationsListBox.GetLogicalChildren().FirstOrDefault(x => this.GetVisualsAt(e.GetPosition(this)).Contains(((IVisual)x).GetVisualChildren().First()));
var dragItemIndex = OperationsListBox.GetLogicalChildren().ToList().IndexOf(DragItem);
var hoveredItemIndex = OperationsListBox.GetLogicalChildren().ToList().IndexOf(hoveredItem);
ClearDropStyling();
if (hoveredItem != DragItem) hoveredItem?.Classes.Add(dragItemIndex > hoveredItemIndex ? "BlackTop" : "BlackBottom");
}
public void EndMoveOperation(object sender, PointerReleasedEventArgs e)
{
var hoveredItem = (ListBoxItem)OperationsListBox.GetLogicalChildren().FirstOrDefault(x => this.GetVisualsAt(e.GetPosition(this)).Contains(((IVisual)x).GetVisualChildren().First()));
if (DragItem == null ||
hoveredItem == null ||
DragItem == hoveredItem)
return;
if (DragItem != null && hoveredItem != null && DragItem != hoveredItem)
{
Operations.Move(
OperationsListBox.GetLogicalChildren().ToList().IndexOf(DragItem),
OperationsListBox.GetLogicalChildren().ToList().IndexOf(hoveredItem));
DragItem = null;
Preview();
}
ClearDropStyling();
DragItem = null;
}
public void Commit()
{
@ -141,6 +160,12 @@ namespace BFR
OpenDirectory(Environment.OSVersion.Platform == PlatformID.Win32NT ? @"C:/Users/" : @"/home/");
HandleEvents = true;
OperationsListBox = this.Find<ListBox>("OperationsListBox");
/*var dark = new StyleInclude(new Uri("resm:Styles?assembly=ControlCatalog"))
{
Source = new Uri("resm:Avalonia.Themes.Default.Accents.BaseDark.xaml?assembly=Avalonia.Themes.Default")
};
Styles[0] = dark;/**/
}
}
}