Put the RBC number text below border on the main image.
authorGreg Burri <greg.burri@gmail.com>
Sun, 21 Mar 2021 21:25:54 +0000 (22:25 +0100)
committerGreg Burri <greg.burri@gmail.com>
Sun, 21 Mar 2021 21:25:54 +0000 (22:25 +0100)
Parasitemia/Parasitemia.sln
Parasitemia/ParasitemiaUI/GUI.fs
Parasitemia/ParasitemiaUIControls/RBCFrame.xaml
Parasitemia/ParasitemiaUIControls/RBCFrame.xaml.cs

index 8102b58..0a0bad4 100644 (file)
@@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.30804.86
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "ParasitemiaUI", "ParasitemiaUI\ParasitemiaUI.fsproj", "{70838E65-F211-44FC-B28F-0ED1CA6E850F}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPF", "WPF\WPF.csproj", "{314FD78E-870E-4794-BB16-EA4586F2ABDB}"
-EndProject
 Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Logger", "Logger\Logger.fsproj", "{A4F183AE-562A-4BAD-88E6-658B4CE15DC3}"
 EndProject
 Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "ParasitemiaCore", "ParasitemiaCore\ParasitemiaCore.fsproj", "{0F8A85F4-9328-40C3-B8FF-44FB39CEB01F}"
@@ -27,10 +25,6 @@ Global
                {70838E65-F211-44FC-B28F-0ED1CA6E850F}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {70838E65-F211-44FC-B28F-0ED1CA6E850F}.Release|Any CPU.ActiveCfg = Release|Any CPU
                {70838E65-F211-44FC-B28F-0ED1CA6E850F}.Release|Any CPU.Build.0 = Release|Any CPU
-               {314FD78E-870E-4794-BB16-EA4586F2ABDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-               {314FD78E-870E-4794-BB16-EA4586F2ABDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
-               {314FD78E-870E-4794-BB16-EA4586F2ABDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
-               {314FD78E-870E-4794-BB16-EA4586F2ABDB}.Release|Any CPU.Build.0 = Release|Any CPU
                {A4F183AE-562A-4BAD-88E6-658B4CE15DC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                {A4F183AE-562A-4BAD-88E6-658B4CE15DC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {A4F183AE-562A-4BAD-88E6-658B4CE15DC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
index 83e54c2..89f38e3 100644 (file)
@@ -54,13 +54,14 @@ let run (defaultConfig : Config) (fileToOpen : string option) =
         max 1. (averageRBCSize / 60.)
 
     let frameFontSize (averageRBCSize : float) =
-        max 1. (averageRBCSize / 8.)
+        max 1. (averageRBCSize / 6.)
 
-    let createRBCFrameFromExisting (srcImg : SourceImage) (rbc : RBC) (frame : RBCFrame) (frameThickness : float) (fontSize : float) : RBCFrame =
+    let createRBCFrameFromExisting (srcImg : SourceImage) (rbc : RBC) (frame : RBCFrame) (frameThickness : float) (fontSize : float) (isTextBelow : bool) : RBCFrame =
         frame.Visibility <- Visibility.Visible
         frame.Width <- rbc.size.Width
         frame.Height <- rbc.size.Height
         frame.Tag <- rbc
+        frame.IsTextBelow <- isTextBelow
         setRBCFrameStyle srcImg rbc frame
         frame.border.StrokeThickness <- frameThickness
         frame.txtRBCNumber.Text <- string rbc.num
@@ -179,8 +180,8 @@ let run (defaultConfig : Config) (fileToOpen : string option) =
         updateCurrentImageInformation ()
         updateGlobalParasitemia ()
 
-    and createRBCFrame (srcImg : SourceImage) (rbc : RBC) (frameThickness : float) (fontSize : float) : RBCFrame =
-        let frame = createRBCFrameFromExisting srcImg rbc (RBCFrame ()) frameThickness fontSize
+    and createRBCFrame (srcImg : SourceImage) (rbc : RBC) (frameThickness : float) (fontSize : float) (isTextBelow : bool) : RBCFrame =
+        let frame = createRBCFrameFromExisting srcImg rbc (RBCFrame ()) frameThickness fontSize isTextBelow
         frame.SetValue (Panel.ZIndexProperty, Int32.MaxValue - rbc.num) // To be sure the
         frame.menuRBCSetAsHealthy.Click.AddHandler (fun obj args -> setAsInfected srcImg (frame.Tag :?> RBC) false)
         frame.menuRBCSetAsInfected.Click.AddHandler (fun obj args -> setAsInfected srcImg (frame.Tag :?> RBC) true)
@@ -205,9 +206,9 @@ let run (defaultConfig : Config) (fileToOpen : string option) =
             for rbc in srcImg.RBCs |> List.filter (fun rbc -> displayHealthy || rbc.infected) do
                 let previewInfected =
                     if currentPreview < win.stackRBC.Children.Count then
-                        createRBCFrameFromExisting srcImg rbc (win.stackRBC.Children.[currentPreview] :?> RBCFrame) 1. 12.
+                        createRBCFrameFromExisting srcImg rbc (win.stackRBC.Children.[currentPreview] :?> RBCFrame) 1. 12. false
                     else
-                        let f = createRBCFrame srcImg rbc 1. 12.
+                        let f = createRBCFrame srcImg rbc 1. 12. false
                         f.MouseLeftButtonUp.AddHandler (fun obj args -> zoomToRBC (f.Tag :?> RBC))
                         win.stackRBC.Children.Add f |> ignore
                         f
@@ -232,9 +233,9 @@ let run (defaultConfig : Config) (fileToOpen : string option) =
             for rbc in srcImg.RBCs do
                 let frame =
                     if currentCanvas < win.canvasCurrentImage.Children.Count then
-                        createRBCFrameFromExisting srcImg rbc (win.canvasCurrentImage.Children.[currentCanvas] :?> RBCFrame) strokeThickness fontSize
+                        createRBCFrameFromExisting srcImg rbc (win.canvasCurrentImage.Children.[currentCanvas] :?> RBCFrame) strokeThickness fontSize true
                     else
-                        let f = createRBCFrame srcImg rbc strokeThickness fontSize
+                        let f = createRBCFrame srcImg rbc strokeThickness fontSize true
                         win.canvasCurrentImage.Children.Add f |> ignore
                         f
 
index 52fb2f8..26a1369 100644 (file)
@@ -16,7 +16,7 @@
         </Grid.ContextMenu>
         <Rectangle x:Name="border" x:FieldModifier="public" Fill="#00000000" />
         <Polygon x:Name="manuallyAdded" x:FieldModifier="public" Points="0,0 12,0, 12,12" Fill="Black" HorizontalAlignment="Right" VerticalAlignment="Top" />
-        <Border HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,3,3" Background="#66000000" CornerRadius="5">
+        <Border x:Name="borderRBCNumber" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,3,3" Background="#66000000" CornerRadius="5">
             <TextBlock x:Name="txtRBCNumber" x:FieldModifier="public" Padding="2" Text="42" Foreground="White" FontSize="12" />
         </Border>
     </Grid>
index 5843111..be023b9 100644 (file)
@@ -4,9 +4,45 @@ namespace ParasitemiaUIControls
 {
     public partial class RBCFrame : UserControl
     {
+        bool isTextBelow = false;
+
         public RBCFrame()
         {
             this.InitializeComponent();
+            this.borderRBCNumber.SizeChanged += BorderRBCNumber_SizeChanged;
+        }
+
+        public bool IsTextBelow
+        {
+            get => this.isTextBelow;
+            set
+            {
+                if (value != this.isTextBelow)
+                {
+                    this.isTextBelow = value;
+                    this.UpdateRBCNumberPosition();
+                }
+            }
+        }
+
+        void BorderRBCNumber_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
+        {
+            this.UpdateRBCNumberPosition();
+
+            //this.UpdateLayout();
+            //System.Diagnostics.Debug.WriteLine($"ActuaSize: {this.borderRBCNumber.ActualHeight}");
+        }
+
+        void UpdateRBCNumberPosition()
+        {
+            var m = this.borderRBCNumber.Margin;
+
+            m.Bottom =
+                this.isTextBelow
+                    ? - this.borderRBCNumber.ActualHeight - 0.05 * this.borderRBCNumber.ActualHeight
+                    : 0.05 * this.borderRBCNumber.ActualHeight;
+
+            this.borderRBCNumber.Margin = m;
         }
     }
 }