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:
parent
e107be13c4
commit
18a2d7154f
|
@ -126,6 +126,18 @@
|
||||||
<Setter Property="Margin" Value="4,-5,4,4"/>
|
<Setter Property="Margin" Value="4,-5,4,4"/>
|
||||||
</Style>
|
</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 -->
|
<!-- Expander Fix -->
|
||||||
<Style Selector="Expander /template/ ToggleButton#PART_toggle /template/ Border">
|
<Style Selector="Expander /template/ ToggleButton#PART_toggle /template/ Border">
|
||||||
<Setter Property="Background" Value="Transparent"/>
|
<Setter Property="Background" Value="Transparent"/>
|
||||||
|
@ -160,7 +172,7 @@
|
||||||
</Grid>
|
</Grid>
|
||||||
</Button.Content>
|
</Button.Content>
|
||||||
</Button>
|
</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"/>
|
<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>
|
</Grid>
|
||||||
<ContentPresenter Grid.ColumnSpan="4" Grid.Row="1" Content="{TemplateBinding Content}" IsVisible="{Binding #OperationExpander.IsExpanded}"/>
|
<ContentPresenter Grid.ColumnSpan="4" Grid.Row="1" Content="{TemplateBinding Content}" IsVisible="{Binding #OperationExpander.IsExpanded}"/>
|
||||||
|
|
|
@ -15,6 +15,7 @@ using Avalonia.LogicalTree;
|
||||||
using BFR.Helpers;
|
using BFR.Helpers;
|
||||||
using BFR.DataModels;
|
using BFR.DataModels;
|
||||||
using BFR.Operations;
|
using BFR.Operations;
|
||||||
|
using Avalonia.Markup.Xaml.Styling;
|
||||||
|
|
||||||
namespace BFR
|
namespace BFR
|
||||||
{
|
{
|
||||||
|
@ -95,21 +96,39 @@ namespace BFR
|
||||||
Preview();
|
Preview();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ClearDropStyling()
|
||||||
|
{
|
||||||
|
foreach (ListBoxItem item in OperationsListBox.GetLogicalChildren())
|
||||||
|
item.Classes.RemoveAll(new[] { "BlackTop", "BlackBottom" });
|
||||||
|
}
|
||||||
|
|
||||||
public void StartMoveOperation(object sender, PointerPressedEventArgs e) =>
|
public void StartMoveOperation(object sender, PointerPressedEventArgs e) =>
|
||||||
DragItem = OperationsListBox.GetLogicalChildren().Cast<ListBoxItem>().Single(x => x.IsPointerOver);
|
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)
|
public void EndMoveOperation(object sender, PointerReleasedEventArgs e)
|
||||||
{
|
{
|
||||||
var hoveredItem = (ListBoxItem)OperationsListBox.GetLogicalChildren().FirstOrDefault(x => this.GetVisualsAt(e.GetPosition(this)).Contains(((IVisual)x).GetVisualChildren().First()));
|
var hoveredItem = (ListBoxItem)OperationsListBox.GetLogicalChildren().FirstOrDefault(x => this.GetVisualsAt(e.GetPosition(this)).Contains(((IVisual)x).GetVisualChildren().First()));
|
||||||
if (DragItem == null ||
|
if (DragItem != null && hoveredItem != null && DragItem != hoveredItem)
|
||||||
hoveredItem == null ||
|
{
|
||||||
DragItem == hoveredItem)
|
Operations.Move(
|
||||||
return;
|
OperationsListBox.GetLogicalChildren().ToList().IndexOf(DragItem),
|
||||||
Operations.Move(
|
OperationsListBox.GetLogicalChildren().ToList().IndexOf(hoveredItem));
|
||||||
OperationsListBox.GetLogicalChildren().ToList().IndexOf(DragItem),
|
Preview();
|
||||||
OperationsListBox.GetLogicalChildren().ToList().IndexOf(hoveredItem));
|
}
|
||||||
|
ClearDropStyling();
|
||||||
DragItem = null;
|
DragItem = null;
|
||||||
Preview();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Commit()
|
public void Commit()
|
||||||
|
@ -141,6 +160,12 @@ namespace BFR
|
||||||
OpenDirectory(Environment.OSVersion.Platform == PlatformID.Win32NT ? @"C:/Users/" : @"/home/");
|
OpenDirectory(Environment.OSVersion.Platform == PlatformID.Win32NT ? @"C:/Users/" : @"/home/");
|
||||||
HandleEvents = true;
|
HandleEvents = true;
|
||||||
OperationsListBox = this.Find<ListBox>("OperationsListBox");
|
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;/**/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user