Add live translations on Language view
authorLukasz Stanislawski <lukasz.stanislawski@gmail.com>
Thu, 2 Apr 2020 08:27:47 +0000 (10:27 +0200)
committerLukasz Stanislawski <lukasz.stanislawski@gmail.com>
Thu, 2 Apr 2020 08:27:47 +0000 (10:27 +0200)
Now when scrolling picke the title and button label
should change accordingly.

Oobe/OobeCommon/Controls/CarouselPicker.cs
Oobe/OobeCommon/Controls/ScrollableBase.cs
Oobe/OobeLanguage/LanguageStep.cs

index 203185fddfc0f9e05e79ab78374dd23553ea2dd6..1e2c0959ab003460f468535d8da73285233ea352 100644 (file)
@@ -48,18 +48,20 @@ namespace Oobe.Common.Controls
             itemsListView.Children.RemoveAt(index);
         }
 
+        private int selectedItemIndex = 0;
         public int SelectedItemIndex
         {
             get
             {
-                return scrollableBase.CurrentPage;
+                return selectedItemIndex;
             }
             set
             {
-                if (scrollableBase.CurrentPage != value)
+                if (selectedItemIndex != value)
                 {
                     scrollableBase.ScrollToIndex(value);
                     SelectedItemChanged?.Invoke(this, null);
+                    selectedItemIndex = value;
                 }
             }
         }
@@ -125,6 +127,14 @@ namespace Oobe.Common.Controls
                 {
                     UpdateItems();
                 };
+                scrollableBase.ScrollAnimationEndEvent += (sender, args) =>
+                {
+                    if (selectedItemIndex != scrollableBase.CurrentPage)
+                    {
+                        selectedItemIndex = scrollableBase.CurrentPage;
+                        SelectedItemChanged?.Invoke(this, null);
+                    }
+                };
 
                 if (upperLine != null)
                 {
index d3ffe3f6a482894ef2fa21facf79ce43f99388b9..0e73f7edd45052dddf9182aa6fb8b6114999341b 100755 (executable)
@@ -122,6 +122,7 @@ namespace Oobe.Common.Controls
 
             protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
             {
+                ScrollableBase scrollableBase = this.Owner as ScrollableBase;
                 foreach( LayoutItem childLayout in LayoutChildren )
                 {
                     if( childLayout != null )
@@ -139,6 +140,9 @@ namespace Oobe.Common.Controls
                         childLayout.Layout( childLeft, childTop, childLeft + childWidth, childTop + childHeight );
                     }
                 }
+                // workaround issue with ScrollableBase not properly scrolling
+                // to index when ScrollToIndex is used before layouting
+                scrollableBase.ScrollToIndex(scrollableBase.CurrentPage);
             }
         } //  ScrollableBaseCustomLayout
 
@@ -457,10 +461,16 @@ namespace Oobe.Common.Controls
                 CurrentPage = index;
             }
 
-            maxScrollDistance = CalculateMaximumScrollDistance();
+            float destinationX;
+            if (ScrollingDirection == Direction.Horizontal)
+            {
+                destinationX = -(mScrollingChild.Children[CurrentPage].Position.X + mScrollingChild.Children[CurrentPage].CurrentSize.Width/2 - CurrentSize.Width/2); // set to middle of current page
+            } else
+            {
+                destinationX = -(mScrollingChild.Children[CurrentPage].Position.Y + mScrollingChild.Children[CurrentPage].CurrentSize.Height/2 - CurrentSize.Height/2); // set to middle of current page
+            }
 
-            float targetPosition = Math.Min(ScrollingDirection == Direction.Vertical ? mScrollingChild.Children[index].Position.Y : mScrollingChild.Children[index].Position.X, maxScrollDistance);
-            AnimateChildTo(ScrollDuration, -targetPosition);
+            AnimateChildTo(ScrollDuration, destinationX);
         }
 
         private void OnScrollDragStart()
index 5ad340cdeb88614c0b601de1701076db4e4e0f1c..4fdfaf91faf88c7a4deb24d17ef87f37dbb167ba 100644 (file)
@@ -7,11 +7,14 @@ using Oobe.Language.Model;
 using Oobe.Common.Controls;\r
 using Oobe.Common.Utils;\r
 using OobeCommon.Resources;\r
+using System.Linq;\r
+using System.Globalization;\r
+using System;\r
 \r
 namespace Oobe.Language\r
 {\r
-     public class LanguageStep : ProcessStep\r
-     {\r
+    public class LanguageStep : ProcessStep\r
+    {\r
         private LanguageManger manager;\r
 \r
         public LanguageStep() : base()\r
@@ -31,7 +34,7 @@ namespace Oobe.Language
             title.TranslatableText = "CHOOSE_LANGUAGE";\r
             title.Position2D = new Position2D(410, 160);\r
             title.Size2D = new Size2D(364, 58);\r
-            title.TextColor = new Color(0, 20.0f/255.0f, 71.0f/255.0f, 1.0f);\r
+            title.TextColor = new Color(0, 20.0f / 255.0f, 71.0f / 255.0f, 1.0f);\r
             title.HorizontalAlignment = HorizontalAlignment.Center;\r
             title.Ellipsis = false;\r
             title.PixelSize = 48.0f;\r
@@ -48,10 +51,13 @@ namespace Oobe.Language
                 item.Text = info.LocalName;\r
                 carousel.AddItem(item);\r
             }\r
+            int currentIndex = manager.Languages.FindIndex(x => x == manager.CurrentLanguage);\r
+            carousel.SelectedItemIndex = currentIndex;\r
 \r
             Button btn = new Button(ButtonStyles.Next);\r
             btn.Position2D = new Position2D(888, 512);\r
-            btn.ClickEvent += (obj, args) => {\r
+            btn.ClickEvent += (obj, args) =>\r
+            {\r
                 if (carousel.SelectedItemIndex >= 0 && carousel.SelectedItemIndex < manager.Languages.Count)\r
                 {\r
                     var lang = manager.Languages[carousel.SelectedItemIndex];\r
@@ -60,11 +66,22 @@ namespace Oobe.Language
                 nav.Next();\r
             };\r
 \r
+            carousel.SelectedItemChanged += (sender, args) =>\r
+            {\r
+                if (carousel.SelectedItemIndex >= 0 && carousel.SelectedItemIndex < manager.Languages.Count)\r
+                {\r
+                    string language = manager.Languages[carousel.SelectedItemIndex].Code.Replace("_", "-");\r
+                    var culture = CultureInfo.CreateSpecificCulture(language);\r
+                    title.Text = Translations.ResourceManager.GetString("CHOOSE_LANGUAGE", culture);\r
+                    btn.Text = Translations.ResourceManager.GetString("CONTINUE", culture);\r
+                }\r
+            };\r
+\r
             container.Add(title);\r
             container.Add(btn);\r
             container.Add(carousel);\r
 \r
             return container;\r
-         }\r
-     }\r
+        }\r
+    }\r
 }\r