Skip to content

Commit cc459e4

Browse files
committed
Made the SVG Move util do the move in real time
1 parent 2ac0535 commit cc459e4

File tree

5 files changed

+51
-48
lines changed

5 files changed

+51
-48
lines changed
Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
11
@using BlazorMonaco.Editor
22
@using ProgrammerAl.SvgHelpers.Components.AnimatedComponents
33

4-
<div class="flex flex-col gap-4 m-5 @(IsMoving ? "disabled" : "")">
5-
<div class="flex gap-2">
6-
<p class="mt-2">X:</p>
7-
<input id="xInput" type="number" @bind=XAmount
8-
class="border border-black min-w-16 py-2 px-4" />
9-
</div>
10-
<div class="flex gap-2">
11-
<p class="mt-2">Y:</p>
12-
<input id="yInput" type="number" @bind=YAmount
13-
class="border border-black min-w-16 py-2 px-4" />
14-
</div>
4+
<div class="flex flex-col gap-2">
155

16-
<button type="button" @onclick=MoveSvgAsync
17-
class="border border-black bg-green-800 min-h-12 text-gray-200">
18-
Modify Elements
19-
</button>
20-
</div>
6+
<p class="text-sm">Move the X and Y coordinates of all elements in the given SVG. The XML provided can be a portion of the entire SVG, not the entire image.</p>
217

22-
<div class="flex flex-row justify-between px-4">
23-
<p class="text-lg font-semibold">Original</p>
24-
<p class="text-lg font-semibold">Modified</p>
25-
</div>
8+
<div class="flex flex-row gap-12">
9+
<div class="flex gap-2">
10+
<p class="mt-2">X:</p>
11+
<input id="xInput" type="number"
12+
@bind-value=XAmount
13+
@bind-value:event="onchange"
14+
@oninput=HandleXAmountChangedAsync
15+
class="border border-black min-w-16 py-2 px-4" />
16+
</div>
17+
<div class="flex gap-2">
18+
<p class="mt-2">Y:</p>
19+
<input id="yInput"
20+
type="number"
21+
@bind-value=YAmount
22+
@bind-value:event="onchange"
23+
@oninput=HandleYAmountChangedAsync
24+
class="border border-black min-w-16 py-2 px-4" />
25+
</div>
26+
</div>
27+
28+
<div class="flex flex-row justify-between px-4 mt-4">
29+
<p class="text-lg font-semibold">Original</p>
30+
<p class="text-lg font-semibold">Modified</p>
31+
</div>
2632

27-
@if (IsMoving)
28-
{
29-
<GreenSpinnerComponent TailwindCssHeightClass="h-24" TailwindCssWidthClass="w-24" />
30-
}
31-
else
32-
{
3333
<StandaloneDiffEditor @ref="_diffEditor"
3434
Id="diff-editor"
3535
ConstructionOptions="DiffEditorConstructionOptions"
3636
OnDidInit="EditorOnDidInit" />
37-
}
37+
38+
</div>

src/SvgHelpers/SvgHelpers/Components/SvgMoverComponent.razor.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public partial class SvgMoverComponent : ComponentBase
2222

2323
private const string DefaultSvgText =
2424
"""
25-
<svg xmlns="http://www.w3.org/2000/svg"
26-
xmlns:xlink="http://www.w3.org/1999/xlink">
27-
</svg>
25+
<rect x="1" y="1"></rect>
2826
""";
2927

3028
private StandaloneDiffEditor _diffEditor = null!;
@@ -35,8 +33,6 @@ public partial class SvgMoverComponent : ComponentBase
3533
private string XAmount { get; set; } = "0";
3634
private string YAmount { get; set; } = "0";
3735

38-
private bool IsMoving { get; set; }
39-
4036
private StandaloneDiffEditorConstructionOptions DiffEditorConstructionOptions(StandaloneDiffEditor editor)
4137
{
4238
return new StandaloneDiffEditorConstructionOptions
@@ -68,11 +64,20 @@ private async Task<TextModel> GetOrCreateTextModelAsync(string textModelName)
6864
return textValue;
6965
}
7066

71-
private async Task MoveSvgAsync()
67+
private async void HandleXAmountChangedAsync(ChangeEventArgs e)
7268
{
73-
IsMoving = true;
74-
await InvokeAsync(StateHasChanged);
69+
XAmount = e.Value?.ToString() ?? "0";
70+
await HandleInputChangedAsync();
71+
}
7572

73+
private async void HandleYAmountChangedAsync(ChangeEventArgs e)
74+
{
75+
YAmount = e.Value?.ToString() ?? "0";
76+
await HandleInputChangedAsync();
77+
}
78+
79+
private async Task HandleInputChangedAsync()
80+
{
7681
var originalModel = await GetOrCreateTextModelAsync(EditorOriginalTextModel);
7782
var modifiedModel = await GetOrCreateTextModelAsync(EditorModifiedTextModel);
7883

@@ -86,19 +91,16 @@ await _diffEditor.SetModel(new DiffEditorModel
8691
Original = originalModel,
8792
Modified = modifiedModel
8893
});
89-
90-
IsMoving = false;
91-
await InvokeAsync(StateHasChanged);
9294
}
9395

9496
private string MoveSvgElements(string svgText)
9597
{
96-
if (!int.TryParse(XAmount, out int xAmount))
98+
if (!long.TryParse(XAmount, out var xAmount))
9799
{
98100
xAmount = 0;
99101
}
100102

101-
if (!int.TryParse(YAmount, out int yAmount))
103+
if (!long.TryParse(YAmount, out var yAmount))
102104
{
103105
yAmount = 0;
104106
}

src/SvgHelpers/SvgHelpers/Components/TabComponent.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@foreach (var tabPage in Pages)
66
{
77
<button type="button"
8-
class="border p-2 @(tabPage == ActivePage ? ActivePageTabCss : InactivePageTabCss)"
8+
class="border @(tabPage == ActivePage ? ActivePageTabCss : InactivePageTabCss)"
99
@onclick=@(() => ActivatePage(tabPage))>
1010
@tabPage.Title
1111
</button>
@@ -18,8 +18,8 @@
1818
</CascadingValue>
1919

2020
@code {
21-
private const string ActivePageTabCss = "border-2 text-lg";
22-
private const string InactivePageTabCss = "text-base";
21+
private const string ActivePageTabCss = "p-4 border-4 text-xl";
22+
private const string InactivePageTabCss = "p-2 text-base";
2323

2424
// Next line is needed so we are able to add <TabPage> components inside
2525
[Parameter]

src/SvgHelpers/SvgHelpers/Pages/About.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@page "/about"
22

3-
<p>This site implements utilities to edit SVG files.</p>
3+
<p>This site implements utilities to help a person manually edit SVG files.</p>
44

55
<p>The source code is available at: <a href="https://github.com/ProgrammerAL/SvgHelpers" target="_blank">https://github.com/ProgrammerAL/SvgHelpers</a></p>
66

src/SvgHelpers/SvgHelpers/SvgModifyUtilities/SvgMoverUtil.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ namespace ProgrammerAl.SvgHelpers.SvgModifyUtilities;
1515
/// </summary>
1616
public class SvgHelpersUtil
1717
{
18-
private record AttributeModification(string AttributeName, int ModifyAmount);
18+
private record AttributeModification(string AttributeName, long ModifyAmount);
1919

2020
private readonly ImmutableDictionary<string, ImmutableArray<AttributeModification>> _simpleElementModifications;
2121

22-
public SvgHelpersUtil(string svgText, int xMove, int yMove, IModificationLogger logger)
22+
public SvgHelpersUtil(string svgText, long xMove, long yMove, IModificationLogger logger)
2323
{
2424
OriginalSvgText = svgText;
2525
XMove = xMove;
@@ -76,8 +76,8 @@ public SvgHelpersUtil(string svgText, int xMove, int yMove, IModificationLogger
7676
}
7777

7878
public string OriginalSvgText { get; }
79-
public int XMove { get; }
80-
public int YMove { get; }
79+
public long XMove { get; }
80+
public long YMove { get; }
8181
public IModificationLogger Logger { get; }
8282

8383
public string ModifiedSvgText { get; private set; } = string.Empty;

0 commit comments

Comments
 (0)