diff --git a/QuestPDF.Previewer/InteractiveCanvas.cs b/QuestPDF.Previewer/InteractiveCanvas.cs index 8a08550..6107a40 100644 --- a/QuestPDF.Previewer/InteractiveCanvas.cs +++ b/QuestPDF.Previewer/InteractiveCanvas.cs @@ -253,7 +253,7 @@ class InteractiveCanvas : ICustomDrawOperation #region inner viewport gradient private const int InnerGradientSize = (int)SafeZone; - private static readonly SKColor InnerGradientColor = SKColor.Parse("#666"); + private static readonly SKColor InnerGradientColor = SKColor.Parse("#555"); private void DrawInnerGradient(SKCanvas canvas) { @@ -312,25 +312,32 @@ class InteractiveCanvas : ICustomDrawOperation if (location == null) return; - var size = 4 / Scale; - size = Math.Min(size, 2); + var size = 6 / Scale; + size = Math.Min(size, 3); - using var strokePaint = new SKPaint + using var strokePaint1 = new SKPaint { StrokeWidth = size, IsStroke = true, - PathEffect = SKPathEffect.CreateDash(new[] { size * 4, size * 2 }, 0), - Color = SKColor.Parse("#444"), - StrokeJoin = SKStrokeJoin.Round + Color = SKColor.Parse("#42A5F5") + }; + + using var strokePaint2 = new SKPaint + { + StrokeWidth = size, + IsStroke = true, + PathEffect = SKPathEffect.CreateDash(new[] { size * 3, size * 3 }, 0), + Color = SKColor.Parse("#1E88E5") }; using var backgroundPaint = new SKPaint { - Color = SKColor.Parse("#4444"), + Color = SKColor.Parse("#442196F3"), }; canvas.DrawRect(location.Left, location.Top, location.Width, location.Height, backgroundPaint); - canvas.DrawRect(location.Left + size / 2, location.Top + size / 2, location.Width - size, location.Height - size, strokePaint); + canvas.DrawRect(location.Left + size / 2, location.Top + size / 2, location.Width - size, location.Height - size, strokePaint1); + canvas.DrawRect(location.Left + size / 2, location.Top + size / 2, location.Width - size, location.Height - size, strokePaint2); } #endregion diff --git a/QuestPDF.Previewer/MyHierarchy.axaml b/QuestPDF.Previewer/MyHierarchy.axaml new file mode 100644 index 0000000..fcd6efd --- /dev/null +++ b/QuestPDF.Previewer/MyHierarchy.axaml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/QuestPDF.Previewer/MyHierarchy.axaml.cs b/QuestPDF.Previewer/MyHierarchy.axaml.cs new file mode 100644 index 0000000..3fa585a --- /dev/null +++ b/QuestPDF.Previewer/MyHierarchy.axaml.cs @@ -0,0 +1,115 @@ +using System.Windows.Input; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Data; +using Avalonia.Input; +using Avalonia.Interactivity; +using Avalonia.Markup.Xaml; +using Avalonia.Media; +using Color = System.Drawing.Color; + +namespace QuestPDF.Previewer +{ + public partial class MyHierarchy : UserControl + { + public static readonly StyledProperty HierarchyProperty = + AvaloniaProperty.Register(nameof(Hierarchy)); + + public InspectionElement Hierarchy + { + get => GetValue(HierarchyProperty); + set => SetValue(HierarchyProperty, value); + } + + public static readonly StyledProperty SelectionProperty = + AvaloniaProperty.Register(nameof(Selection)); + + public InspectionElement? Selection + { + get => GetValue(SelectionProperty); + set => SetValue(SelectionProperty, value); + } + + public event Action? OnSelected; + + public bool Extended { get; set; } + + public MyHierarchy() + { + InitializeComponent(); + + HierarchyProperty.Changed.Subscribe(x => + { + Configure(); + }); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + Configure(); + } + + private void Configure() + { + var panel = this.FindControl("Panel"); + panel.IsVisible = Hierarchy?.Children?.Any() ?? false; + + this.FindControl("Indentation").Width = (Hierarchy?.Level ?? 0) * 24; + + UpdateIcon(); + + this.FindControl("ElementName").Text = Hierarchy?.Text; + this.FindControl("ElementName").Foreground = new SolidColorBrush(Avalonia.Media.Color.Parse(Hierarchy?.FontColor ?? "#FFF")); + } + + private const string ExtendedIcon = "M7,15L12,10L17,15H7Z"; + private const string CollapsedIcon = "M7,10L12,15L17,10H7Z"; + + private void Toggle(object? sender, PointerPressedEventArgs e) + { + Extended = !Extended; + + UpdateIcon(); + this.FindControl("Repeater").Items = Extended ? Hierarchy?.Children : Array.Empty(); + } + + private void UpdateIcon() + { + var iconControl = this.FindControl("Icon"); + + iconControl.Data = new PathGeometry + { + Figures = PathFigures.Parse(Extended ? ExtendedIcon : CollapsedIcon) + }; + } + + private void InputElement_OnDoubleTapped(object? sender, RoutedEventArgs e) + { + Toggle(null, null); + } + + private void Highlight_OnPointerEnter(object? sender, PointerEventArgs e) + { + Cursor = Cursor.Parse("hand"); + this.FindControl("Highlight").Background = new SolidColorBrush(Avalonia.Media.Color.Parse("#1FFF")); + } + + private void Indentation_OnPointerLeave(object? sender, PointerEventArgs e) + { + Cursor = Cursor.Default; + this.FindControl("Highlight").Background = new SolidColorBrush(Avalonia.Media.Color.Parse("#0000")); + } + + private void Clicked(object? sender, PointerPressedEventArgs e) + { + OnSelected?.Invoke(Hierarchy); + } + + private void MyHierarchy_OnOnSelected(InspectionElement selected) + { + OnSelected?.Invoke(selected); + Selection = selected; + } + } +} diff --git a/QuestPDF.Previewer/PreviewerControl.cs b/QuestPDF.Previewer/PreviewerControl.cs index bb883f2..6796aa1 100644 --- a/QuestPDF.Previewer/PreviewerControl.cs +++ b/QuestPDF.Previewer/PreviewerControl.cs @@ -35,9 +35,9 @@ namespace QuestPDF.Previewer set => SetValue(ScrollViewportSizeProperty, value); } - public static readonly StyledProperty> HierarchyProperty = AvaloniaProperty.Register>(nameof(Hierarchy)); + public static readonly StyledProperty HierarchyProperty = AvaloniaProperty.Register(nameof(Hierarchy)); - public ObservableCollection Hierarchy + public InspectionElement Hierarchy { get => GetValue(HierarchyProperty); set => SetValue(HierarchyProperty, value); @@ -90,7 +90,7 @@ namespace QuestPDF.Previewer void FindHighlightedElement(int pageNumber, float x, float y) { - var possible = FlattenHierarchy(Hierarchy.First(), 0) + var possible = FlattenHierarchy(Hierarchy, 0) .Select(x => { var location = x.element.Location.First(y => y.PageNumber == pageNumber); diff --git a/QuestPDF.Previewer/PreviewerWindow.axaml b/QuestPDF.Previewer/PreviewerWindow.axaml index ce991db..8bcbb74 100644 --- a/QuestPDF.Previewer/PreviewerWindow.axaml +++ b/QuestPDF.Previewer/PreviewerWindow.axaml @@ -3,137 +3,128 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:previewer="clr-namespace:QuestPDF.Previewer" + xmlns:visualBasic="clr-namespace:Microsoft.VisualBasic;assembly=Microsoft.VisualBasic.Core" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="QuestPDF.Previewer.PreviewerWindow" x:DataType="previewer:PreviewerWindowViewModel" x:CompileBindings="True" WindowStartupLocation="CenterScreen" ExtendClientAreaToDecorationsHint="true" - ExtendClientAreaTitleBarHeightHint="-1" - Background="#666" + ExtendClientAreaTitleBarHeightHint="56" + Background="#555" Icon="/Resources/Logo.png" UseLayoutRounding="True" Title="QuestPDF Document Preview"> - + + + + + + - + + - + - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - + + + + - - - - - - - - + + - - + + + + + + + + + + + + - + - - + + @@ -141,9 +132,9 @@ - + - - Items { get; set; } - + private InspectionElement _selectedItem; public InspectionElement SelectedItem { @@ -99,18 +97,37 @@ namespace QuestPDF.Previewer set => this.RaiseAndSetIfChanged(ref _selectedItem, value); } + private InspectionElement items; + public InspectionElement Items + { + get => items; + set => this.RaiseAndSetIfChanged(ref items, value); + } + public void LoadItems() { - Items = new ObservableCollection(); - var text = File.ReadAllText("hierarchy.json"); - var hierarchy = JsonSerializer.Deserialize(text); + Items = JsonSerializer.Deserialize(text); + UpdateLevel(Items); + } - Items.Add(hierarchy); + private void UpdateLevel(InspectionElement root) + { + var currentLevel = 1; + Traverse(root); + + void Traverse(InspectionElement element) + { + element.Level = currentLevel; + + currentLevel++; + element.Children.ForEach(Traverse); + currentLevel--; + } } } - internal class InspectionElementLocation + public class InspectionElementLocation { public int PageNumber { get; set; } public float Top { get; set; } @@ -119,7 +136,7 @@ namespace QuestPDF.Previewer public float Height { get; set; } } - internal class Metadata + public class Metadata { public string Label { get; set; } public string Value { get; set; } @@ -130,17 +147,18 @@ namespace QuestPDF.Previewer Value = value; } } - - internal class InspectionElement + + public class InspectionElement { public string Element { get; set; } public List Location { get; set; } public Dictionary Properties { get; set; } public List Children { get; set; } - public Thickness Margin { get; set; } + public int Level { get; set; } public string FontColor => Element == "DebugPointer" ? "#FFF" : "#AFFF"; public string Text => Element == "DebugPointer" ? Properties.First(x => x.Key == "Target").Value : Element; + public bool Expanded { get; set; } public IList Metadata => ListMetadata().ToList(); diff --git a/QuestPDF/Drawing/DocumentContainer.cs b/QuestPDF/Drawing/DocumentContainer.cs index 18a8cc9..304e623 100644 --- a/QuestPDF/Drawing/DocumentContainer.cs +++ b/QuestPDF/Drawing/DocumentContainer.cs @@ -16,6 +16,7 @@ namespace QuestPDF.Drawing var container = new Container(); container + .DebugPointer("Document") .Column(column => { Pages diff --git a/QuestPDF/Drawing/DocumentGenerator.cs b/QuestPDF/Drawing/DocumentGenerator.cs index 61abecc..740b900 100644 --- a/QuestPDF/Drawing/DocumentGenerator.cs +++ b/QuestPDF/Drawing/DocumentGenerator.cs @@ -290,7 +290,7 @@ namespace QuestPDF.Drawing } } } - + internal static void RenderPass(PageContext pageContext, TCanvas canvas, Container content, DocumentMetadata documentMetadata, DebuggingState? debuggingState) where TCanvas : ICanvas, IRenderingCanvas { diff --git a/QuestPDF/Elements/Page.cs b/QuestPDF/Elements/Page.cs index 36365c5..c6ba31d 100644 --- a/QuestPDF/Elements/Page.cs +++ b/QuestPDF/Elements/Page.cs @@ -41,6 +41,7 @@ namespace QuestPDF.Elements layers .PrimaryLayer() + .DebugPointer("Page content") .MinWidth(MinSize.Width) .MinHeight(MinSize.Height)