add Pilz.UI & Pilz.UI.Gtk

This commit is contained in:
2025-06-16 12:19:28 +02:00
parent 299867a910
commit 6f7bb5d92c
14 changed files with 175 additions and 32 deletions

View File

@@ -0,0 +1,23 @@
using Gtk;
namespace Pilz.UI.Gtk.Dialogs;
public static class MessageBox
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Nicht verwendete Parameter entfernen", Justification = "Can be used for easier migration from WinForms. However, the title get ignored as Gtk has no title parameter.")]
public static ResponseType Show(Window window, string message, string title, ButtonsType buttons, MessageType type)
{
var msgBox = new MessageDialog(window, DialogFlags.DestroyWithParent, type, buttons, message);
var result = msgBox.Run();
msgBox.Destroy();
return (ResponseType)result;
}
public static ResponseType Show(Window window, ButtonsType buttons, MessageType type, string format, params object[] args)
{
var msgBox = new MessageDialog(window, DialogFlags.DestroyWithParent, type, buttons, format, args);
var result = msgBox.Run();
msgBox.Destroy();
return (ResponseType)result;
}
}

View File

@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup>
<Version>1.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GtkSharp" Version="3.24.24.95" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Pilz.UI\Pilz.UI.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,35 @@
using Gdk;
using Gtk;
using Pilz.UI.Symbols;
using Size = System.Drawing.Size;
namespace Pilz.UI.Gtk.Symbols;
public abstract class GtkSymbolFactory<TSymbols> : BaseSymbolFactory<TSymbols>, IGtkSymbolFactory<TSymbols>
{
public virtual Image? GetImage(TSymbols svgImage, SymbolSize size)
{
return GetImage(svgImage, ResolveCommonSize(size));
}
public virtual Image? GetImage(TSymbols svgImage, Size size)
{
using var stream = GetImageRessourceStream(svgImage);
if (stream is null)
return null;
Pixbuf pixbuf;
if (size.IsEmpty)
pixbuf = new(stream);
else
pixbuf = new(stream, size.Width, size.Height);
return GetImageFromPixbuf(pixbuf);
}
public virtual Image GetImageFromPixbuf(Pixbuf pixbuf)
{
return new Image(pixbuf);
}
}

View File

@@ -0,0 +1,12 @@
using Gtk;
using Pilz.UI.Symbols;
using System.Drawing;
namespace Pilz.UI.Gtk.Symbols;
public interface IGtkSymbolFactory<TSymbols> : IBaseSymbolFactory<TSymbols>
{
Image? GetImage(TSymbols svgImage, Size size);
Image? GetImage(TSymbols svgImage, SymbolSize size);
Image GetImageFromPixbuf(Gdk.Pixbuf pixbuf);
}