Browse Source

Added better text formatting

Krzysztof Krysiński 3 months ago
parent
commit
4a4ac033e3

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 8bf655ed21046c4a534c3f7f08fdaa01a9ab34d8
+Subproject commit 9a9a3814a43945c70badcfafc9e936d18943df7c

+ 37 - 0
src/PixiEditor/Helpers/Converters/ComputedValueToStringConverter.cs

@@ -0,0 +1,37 @@
+using System.Globalization;
+using Drawie.Numerics;
+
+namespace PixiEditor.Helpers.Converters;
+
+internal class ComputedValueToStringConverter : SingleInstanceConverter<ComputedValueToStringConverter>
+{
+    public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+    {
+        if (value is double d)
+        {
+            return $"{d:0.##}";
+        }
+
+        if (value is float f)
+        {
+            return $"{f:0.##}";
+        }
+
+        if(value is VecD vecD)
+        {
+            return $"{vecD.X:0.##}, {vecD.Y:0.##}";
+        }
+
+        if (value is VecF vecI)
+        {
+            return $"{vecI.X:0.##}, {vecI.Y:0.##}";
+        }
+
+        if (value is VecI vec)
+        {
+            return $"{vec.X}, {vec.Y}";
+        }
+
+        return value?.ToString() ?? "null";
+    }
+}

+ 4 - 3
src/PixiEditor/Styles/Templates/NodeSocket.axaml

@@ -1,19 +1,20 @@
 <ResourceDictionary xmlns="https://github.com/avaloniaui"
 <ResourceDictionary xmlns="https://github.com/avaloniaui"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-                    xmlns:properties="clr-namespace:PixiEditor.Views.Nodes.Properties">
+                    xmlns:properties="clr-namespace:PixiEditor.Views.Nodes.Properties"
+                    xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters">
     <ControlTheme TargetType="properties:NodeSocket" x:Key="{x:Type properties:NodeSocket}">
     <ControlTheme TargetType="properties:NodeSocket" x:Key="{x:Type properties:NodeSocket}">
         <Setter Property="Template">
         <Setter Property="Template">
             <ControlTemplate>
             <ControlTemplate>
                 <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                 <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                     <Grid Name="PART_ConnectPort">
                     <Grid Name="PART_ConnectPort">
                         <Panel Width="20" Height="20" Margin="-5, 0" Background="Transparent"
                         <Panel Width="20" Height="20" Margin="-5, 0" Background="Transparent"
-                               ToolTip.ShowDelay="0" ToolTip.ShowOnDisabled="True" ToolTip.Tip="{Binding Property.ComputedValue, RelativeSource={RelativeSource TemplatedParent}}"
+                               ToolTip.ShowDelay="0" ToolTip.ShowOnDisabled="True" ToolTip.Tip="{Binding Property.ComputedValue, RelativeSource={RelativeSource TemplatedParent}, Converter={converters:ComputedValueToStringConverter}}"
                                IsVisible="{Binding !IsFunc, RelativeSource={RelativeSource TemplatedParent}}">
                                IsVisible="{Binding !IsFunc, RelativeSource={RelativeSource TemplatedParent}}">
                             <Ellipse Width="10" Height="10" RenderTransform="rotate(90deg)"
                             <Ellipse Width="10" Height="10" RenderTransform="rotate(90deg)"
                                      Fill="{TemplateBinding SocketBrush}" />
                                      Fill="{TemplateBinding SocketBrush}" />
                         </Panel>
                         </Panel>
                         <Panel Margin="-5, 0" Width="20" Height="20" Background="Transparent"
                         <Panel Margin="-5, 0" Width="20" Height="20" Background="Transparent"
-                               ToolTip.ShowDelay="0" ToolTip.ShowOnDisabled="True" ToolTip.Tip="{Binding Property.ComputedValue, RelativeSource={RelativeSource TemplatedParent}}"
+                               ToolTip.ShowDelay="0" ToolTip.ShowOnDisabled="True" ToolTip.Tip="{Binding Property.ComputedValue, RelativeSource={RelativeSource TemplatedParent}, Converter={converters:ComputedValueToStringConverter}}"
                                IsVisible="{Binding IsFunc, RelativeSource={RelativeSource TemplatedParent}}">
                                IsVisible="{Binding IsFunc, RelativeSource={RelativeSource TemplatedParent}}">
                             <Rectangle Width="10" Height="10"
                             <Rectangle Width="10" Height="10"
                                        RadiusX="2" RadiusY="2"
                                        RadiusX="2" RadiusY="2"