Save All is now working.

Size is now a relative value in Line.
This commit is contained in:
Creeper Lv
2026-01-01 23:02:12 +11:00
parent 2eb59564b4
commit c1e4c71985
12 changed files with 73 additions and 31 deletions

View File

@@ -77,7 +77,7 @@ namespace Progrart.Core.Graphics
new SKPaint() new SKPaint()
{ {
ColorF = Color, ColorF = Color,
StrokeWidth = Size, StrokeWidth = context.TranslateSize(Size),
Shader = shader Shader = shader
} }
); );

View File

@@ -6,7 +6,7 @@ using System.Diagnostics;
namespace Progrart.Core.Graphics namespace Progrart.Core.Graphics
{ {
public class Rectangle : BaseElement public class Rectangle : BaseElement
{ {
float StrokeWidth; float StrokeWidth;
@@ -78,7 +78,7 @@ namespace Progrart.Core.Graphics
new SKPaint() new SKPaint()
{ {
ColorF = Color, ColorF = Color,
StrokeWidth = StrokeWidth, StrokeWidth = context.TranslateSize(StrokeWidth),
Shader = shader Shader = shader
} }
); );

View File

@@ -82,7 +82,11 @@ namespace Progrart.Core.JSExecution
{ {
height = (float)(js_height.AsNumber()); height = (float)(js_height.AsNumber());
} }
RenderContext renderContext = new RenderContext((int)(width * Scale), (int)(width * Scale)); RenderContext renderContext = new RenderContext((int)(width * Scale), (int)(width * Scale))
{
LogicalW = width,
LogicalH = height
};
ImageRoot imageRoot = new ImageRoot(); ImageRoot imageRoot = new ImageRoot();
var img = engine.Engine.Call("main"); var img = engine.Engine.Call("main");

View File

@@ -8,6 +8,8 @@ namespace Progrart.Core
public PrimitiveDrawingCore DrawingCore { get; } public PrimitiveDrawingCore DrawingCore { get; }
public SKCanvas canvas { get => DrawingCore.canvas; } public SKCanvas canvas { get => DrawingCore.canvas; }
public float LogicalW;
public float LogicalH;
public RenderContext(PrimitiveDrawingCore core) public RenderContext(PrimitiveDrawingCore core)
{ {
this.DrawingCore = core; this.DrawingCore = core;
@@ -20,6 +22,10 @@ namespace Progrart.Core
{ {
return TranslatePoint(point.X, point.Y); return TranslatePoint(point.X, point.Y);
} }
public float TranslateSize(float s)
{
return (float)(s * Math.Sqrt(DrawingCore.Width * DrawingCore.Width + DrawingCore.Height * DrawingCore.Height)/ Math.Sqrt(LogicalH * LogicalH + LogicalW * LogicalW));
}
public RenderContext(int W, int H) public RenderContext(int W, int H)
{ {
DrawingCore = new PrimitiveDrawingCore(W, H); DrawingCore = new PrimitiveDrawingCore(W, H);

View File

@@ -6,6 +6,7 @@ using AvaloniaEdit;
using AvaloniaEdit.TextMate; using AvaloniaEdit.TextMate;
using Progrart.Commands; using Progrart.Commands;
using System; using System;
using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using TextMateSharp.Grammars; using TextMateSharp.Grammars;
@@ -20,7 +21,7 @@ public partial class BaseEditor : UserControl
get => CodeEditBox.Text; get => CodeEditBox.Text;
set => CodeEditBox.Text = value; set => CodeEditBox.Text = value;
} }
public Action? onSaveCmd; public Func<Task>? onSaveCmd;
public BaseEditor() public BaseEditor()
{ {
InitializeComponent(); InitializeComponent();
@@ -35,14 +36,15 @@ public partial class BaseEditor : UserControl
var saveBinding = new KeyBinding var saveBinding = new KeyBinding
{ {
Gesture = new KeyGesture(Key.S, KeyModifiers.Control), Gesture = new KeyGesture(Key.S, KeyModifiers.Control),
Command = new GenericCommand() { onExecute = (_) => Save() } Command = new GenericCommand() { onExecute = (_) => Task.Run(Save) }
}; };
CodeEditBox.KeyBindings.Add(saveBinding); CodeEditBox.KeyBindings.Add(saveBinding);
} }
void Save() async Task Save()
{ {
onSaveCmd?.Invoke(); if (onSaveCmd is not null)
await onSaveCmd.Invoke();
} }
public void SetGrammerByExtension(string extension_name) public void SetGrammerByExtension(string extension_name)
{ {

View File

@@ -3,6 +3,8 @@ using Avalonia.Controls;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
using Progrart.Pages; using Progrart.Pages;
using System;
using System.Threading.Tasks;
namespace Progrart.Controls.TabSystem; namespace Progrart.Controls.TabSystem;
@@ -43,6 +45,16 @@ public partial class TabHost : UserControl
} }
return null; return null;
} }
public async Task Foreach(Func<ITabPage, Task<bool>> handler)
{
foreach (var item in PageContainer.Children)
{
if (item is ITabPage page)
{
if (await handler(page)) break;
}
}
}
public void SelectButton(TabButton button) public void SelectButton(TabButton button)
{ {
foreach (var item in TabContainer.Children) foreach (var item in TabContainer.Children)

View File

@@ -21,7 +21,6 @@ public partial class EditorPage : UserControl, ITabPage, IEditorPage
public EditorPage() public EditorPage()
{ {
InitializeComponent(); InitializeComponent();
} }
public bool IsSameFile(IStorageFile file) public bool IsSameFile(IStorageFile file)
@@ -78,7 +77,7 @@ public partial class EditorPage : UserControl, ITabPage, IEditorPage
}); });
} }
public void Save() public async Task Save()
{ {
} }

View File

@@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Text; using System.Text;
using System.Threading.Tasks;
namespace Progrart.Pages namespace Progrart.Pages
{ {
@@ -63,7 +64,7 @@ namespace Progrart.Pages
public interface IEditorPage public interface IEditorPage
{ {
void LoadDocument(IStorageFile file); void LoadDocument(IStorageFile file);
void Save(); Task Save();
bool IsSameFile(IStorageFile file); bool IsSameFile(IStorageFile file);
void Execute(ExecuteArguments? args = null); void Execute(ExecuteArguments? args = null);
} }

View File

@@ -47,7 +47,7 @@ public partial class ImageViewPage : UserControl, ITabPage, IEditorPage
}); });
} }
public void Save() public async Task Save()
{ {
} }

View File

@@ -109,12 +109,13 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
}); });
} }
public void Save() public async Task Save()
{ {
if (file is not null) if (file is not null)
{ {
string content = CodeEditor.Text; string content = "";
Task.Run(async () => await Dispatcher.UIThread.InvokeAsync(() => { content = CodeEditor.Text; });
await Task.Run(async () =>
{ {
using var stream = await file.OpenWriteAsync(); using var stream = await file.OpenWriteAsync();
stream.SetLength(0); stream.SetLength(0);

View File

@@ -44,7 +44,8 @@
<MenuItem Header="_Open"> <MenuItem Header="_Open">
<MenuItem Header="_Project" Name="OpenProjectMenuItem"/> <MenuItem Header="_Project" Name="OpenProjectMenuItem"/>
</MenuItem> </MenuItem>
<MenuItem Header="_Save"/> <MenuItem Header="_Save" Click="MenuItem_Save_Click"/>
<MenuItem Header="Save A_ll" Click="MenuItem_SaveAll_Click"/>
<MenuItem Header="Save _As"/> <MenuItem Header="Save _As"/>
</MenuItem> </MenuItem>
<MenuItem Header="_Tools"> <MenuItem Header="_Tools">

View File

@@ -9,6 +9,7 @@ using Progrart.Core.JSExecution;
using Progrart.Pages; using Progrart.Pages;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading.Tasks;
namespace Progrart.Views; namespace Progrart.Views;
@@ -108,23 +109,23 @@ public partial class MainView : UserControl
}; };
LeftPanelToggle.IsChecked = true; LeftPanelToggle.IsChecked = true;
RunButton.Click += (_, _) => RunButton.Click += (_, _) =>
{ {
Execute(); Execute();
}; };
} }
private void Execute() private void Execute()
{ {
if (MainTabHost.GetCurrentPage() is IEditorPage editor) if (MainTabHost.GetCurrentPage() is IEditorPage editor)
{ {
ExecuteArguments args = new ExecuteArguments(); ExecuteArguments args = new ExecuteArguments();
args.data["Scale"] = $"{SizeBox.Value}"; args.data["Scale"] = $"{SizeBox.Value}";
args.data["Debug"] = $"{IsDebugBox.IsChecked ?? false}".ToLower(); args.data["Debug"] = $"{IsDebugBox.IsChecked ?? false}".ToLower();
editor.Execute(args); editor.Execute(args);
} }
} }
private void OutputClear_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) private void OutputClear_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{ {
Output.Text = ""; Output.Text = "";
} }
@@ -161,4 +162,19 @@ public partial class MainView : UserControl
editor.Save(); editor.Save();
} }
} }
private void MenuItem_Save_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
if (MainTabHost.GetCurrentPage() is IEditorPage editor) Task.Run(async () => await editor.Save());
}
private void MenuItem_SaveAll_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
Task.Run(async () => await MainTabHost.Foreach(async (page) =>
{
if (page is IEditorPage editor)
await editor.Save();
return false;
}));
}
} }