TemplateDesigner: Redesign des TemplateSkripts
This commit is contained in:
@@ -30,14 +30,18 @@ public sealed class LayoutOverlayEditor : Control
|
||||
AvaloniaProperty.Register<LayoutOverlayEditor, bool>(nameof(SnapToGrid), true);
|
||||
public static readonly StyledProperty<double> GridSizeProperty =
|
||||
AvaloniaProperty.Register<LayoutOverlayEditor, double>(nameof(GridSize), 1);
|
||||
public static readonly StyledProperty<string> PageTemplateNameProperty =
|
||||
AvaloniaProperty.Register<LayoutOverlayEditor, string>(nameof(PageTemplateName), "first");
|
||||
|
||||
private readonly Pen _normalPen = new(new SolidColorBrush(Color.Parse("#2563EB")), 1.5);
|
||||
private readonly Pen _selectedPen = new(new SolidColorBrush(Color.Parse("#DC2626")), 2.5);
|
||||
private readonly Pen _measurePen = new(new SolidColorBrush(Color.Parse("#D97706")), 2);
|
||||
private readonly Pen _gridPen = new(new SolidColorBrush(Color.FromArgb(55, 37, 99, 235)), 1);
|
||||
private readonly Pen _flowPen = new(new SolidColorBrush(Color.Parse("#7C3AED")), 2, dashStyle: DashStyle.Dash);
|
||||
private readonly IBrush _normalFill = new SolidColorBrush(Color.FromArgb(30, 37, 99, 235));
|
||||
private readonly IBrush _selectedFill = new SolidColorBrush(Color.FromArgb(35, 220, 38, 38));
|
||||
private readonly IBrush _handleFill = new SolidColorBrush(Color.Parse("#DC2626"));
|
||||
private readonly IBrush _flowFill = new SolidColorBrush(Color.FromArgb(38, 124, 58, 237));
|
||||
private readonly List<OverlayItem> _items = [];
|
||||
private OverlayItem? _selected;
|
||||
private Point? _pointerStartDsl;
|
||||
@@ -52,6 +56,7 @@ public sealed class LayoutOverlayEditor : Control
|
||||
public OverlayEditorMode Mode { get => GetValue(ModeProperty); set => SetValue(ModeProperty, value); }
|
||||
public bool SnapToGrid { get => GetValue(SnapToGridProperty); set => SetValue(SnapToGridProperty, value); }
|
||||
public double GridSize { get => GetValue(GridSizeProperty); set => SetValue(GridSizeProperty, value); }
|
||||
public string PageTemplateName { get => GetValue(PageTemplateNameProperty); set => SetValue(PageTemplateNameProperty, value); }
|
||||
|
||||
public event EventHandler<OverlayMeasurement>? MeasurementCompleted;
|
||||
public event EventHandler<OverlayElementGeometry>? ElementGeometryChanged;
|
||||
@@ -61,7 +66,8 @@ public sealed class LayoutOverlayEditor : Control
|
||||
static LayoutOverlayEditor()
|
||||
{
|
||||
AffectsRender<LayoutOverlayEditor>(PreviewImageProperty, LayoutSourceProperty, PageWidthProperty,
|
||||
PageHeightProperty, PageUnitProperty, ModeProperty, SnapToGridProperty, GridSizeProperty);
|
||||
PageHeightProperty, PageUnitProperty, ModeProperty, SnapToGridProperty, GridSizeProperty,
|
||||
PageTemplateNameProperty);
|
||||
}
|
||||
|
||||
public LayoutOverlayEditor() { Focusable = true; ClipToBounds = true; }
|
||||
@@ -80,7 +86,9 @@ public sealed class LayoutOverlayEditor : Control
|
||||
var geometry = ReferenceEquals(item, _selected) && _workingRectDsl is { } working ? working : item.Rect;
|
||||
var rect = ToControl(geometry, page);
|
||||
var selected = ReferenceEquals(item, _selected);
|
||||
context.DrawRectangle(selected ? _selectedFill : _normalFill, selected ? _selectedPen : _normalPen,
|
||||
var fill = selected ? _selectedFill : item.IsFlowSlot ? _flowFill : _normalFill;
|
||||
var pen = selected ? _selectedPen : item.IsFlowSlot ? _flowPen : _normalPen;
|
||||
context.DrawRectangle(fill, pen,
|
||||
rect, 2, 2);
|
||||
if (selected && item.Resizable)
|
||||
context.FillRectangle(_handleFill, new Rect(rect.Right - 6, rect.Bottom - 6, 12, 12), 2);
|
||||
@@ -188,7 +196,11 @@ public sealed class LayoutOverlayEditor : Control
|
||||
try
|
||||
{
|
||||
var layout = new LayoutParser().Parse(LayoutSource);
|
||||
foreach (var element in layout.Elements)
|
||||
var pageTemplate = layout.PageTemplates.FirstOrDefault(x =>
|
||||
x.Name.Equals(PageTemplateName, StringComparison.OrdinalIgnoreCase))
|
||||
?? layout.PageTemplates.FirstOrDefault();
|
||||
var visibleElements = pageTemplate?.Elements ?? layout.Elements;
|
||||
foreach (var element in visibleElements)
|
||||
{
|
||||
if (element is BackgroundElement) continue;
|
||||
var keyword = element switch
|
||||
@@ -201,8 +213,11 @@ public sealed class LayoutOverlayEditor : Control
|
||||
ImageElement image => (image.Width * ImageScale(image), image.Height * ImageScale(image), true),
|
||||
_ => ((double)element.Width, element.Height, true),
|
||||
};
|
||||
_items.Add(new(element.Line, keyword, new Rect(element.X, element.Y, width, height), resizable));
|
||||
_items.Add(new(element.Line, keyword, new Rect(element.X, element.Y, width, height), resizable, false));
|
||||
}
|
||||
if (pageTemplate is not null)
|
||||
foreach (var slot in pageTemplate.FlowSlots)
|
||||
_items.Add(new(slot.Line, "FLOW", new Rect(slot.X, slot.Y, slot.Width, slot.Height), true, true));
|
||||
if (_selected is not null)
|
||||
_selected = _items.FirstOrDefault(x => x.Line == _selected.Line);
|
||||
}
|
||||
@@ -243,7 +258,7 @@ public sealed class LayoutOverlayEditor : Control
|
||||
private double PointsToUnit(double points) => PageUnit.ToLowerInvariant() switch
|
||||
{ "mm" => points * 25.4 / 72, "cm" => points * 2.54 / 72, "in" => points / 72, _ => points };
|
||||
|
||||
private sealed record OverlayItem(int Line, string Keyword, Rect Rect, bool Resizable);
|
||||
private sealed record OverlayItem(int Line, string Keyword, Rect Rect, bool Resizable, bool IsFlowSlot);
|
||||
private enum DragKind { None, Measure, Move, Resize }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user