Fix window position and size issue in low resolution. 69/314269/1
authorMd. Farhan Mahtab/NC eXperience Group /SRBD/Engineer/Samsung Electronics <farhan.m1@samsung.com>
Tue, 9 Jul 2024 11:13:31 +0000 (17:13 +0600)
committerMd. Farhan Mahtab/NC eXperience Group /SRBD/Engineer/Samsung Electronics <farhan.m1@samsung.com>
Tue, 9 Jul 2024 11:14:51 +0000 (17:14 +0600)
[Problem] When opening in low resolution the window border is positioned on the left side not centered.

[Cause & Measure]
 Cause : Base NUIApplication window size and position is being initialized with default value due to Tizen.System.TryGetValue giving static resolution.
 Measure : NUIApplication is initialized with smaller initial window size and postion and later resized according to resolution in OnCreate.

Change-Id: I4125b19d10069edc605e1f7d034038ce8707700e
Signed-off-by: Md. Farhan Mahtab/NC eXperience Group /SRBD/Engineer/Samsung Electronics <farhan.m1@samsung.com>
SettingView/Common/DeviceInfo.cs [new file with mode: 0644]
SettingView/Core/WindowManager.cs [new file with mode: 0644]
SettingView/SettingView.cs
SettingView/SettingViewBorder.cs
packaging/org.tizen.cssettings-1.1.20.tpk

diff --git a/SettingView/Common/DeviceInfo.cs b/SettingView/Common/DeviceInfo.cs
new file mode 100644 (file)
index 0000000..9c68afc
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ *  Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+using Tizen.NUI;
+using Tizen.System;
+
+namespace SettingView.Common
+{
+    public static class DeviceInfo
+    {
+        private static int width;
+        private static int height;
+        private static Window.WindowOrientation orientation;
+
+        static DeviceInfo()
+        {
+            Size displaySize = NUIApplication.GetScreenSize();
+            width = (int)displaySize.Width;
+            height = (int)displaySize.Height;
+
+            orientation = Window.Instance.GetCurrentOrientation();
+            IsPortrait = orientation == Window.WindowOrientation.Portrait || orientation == Window.WindowOrientation.PortraitInverse;
+        }
+
+        public static void UpdateDeviceInfo()
+        {
+            Window.WindowOrientation currentOrientation = Window.Instance.GetCurrentOrientation();
+            if (orientation == Window.WindowOrientation.Portrait || orientation == Window.WindowOrientation.PortraitInverse)
+            {
+                if(currentOrientation == Window.WindowOrientation.Landscape || currentOrientation == Window.WindowOrientation.LandscapeInverse)
+                {
+                    ToggleOrientation();
+                }
+            }
+            else
+            {
+                if (currentOrientation == Window.WindowOrientation.Portrait || currentOrientation == Window.WindowOrientation.PortraitInverse)
+                {
+                    ToggleOrientation();
+                }
+            }
+            orientation = currentOrientation;
+        }
+
+        private static void ToggleOrientation()
+        {
+            (width, height) = (height, width);
+            IsPortrait = !IsPortrait;
+        }
+
+        public static bool IsPortrait { get; private set; }
+
+        public static int DisplayWidth => width;
+
+        public static int DisplayHeight => height;
+    }
+}
diff --git a/SettingView/Core/WindowManager.cs b/SettingView/Core/WindowManager.cs
new file mode 100644 (file)
index 0000000..33c8b40
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ *  Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+using SettingView.Common;
+using Tizen.NUI;
+using SettingCore;
+
+
+namespace SettingView.Core
+{
+    public static class WindowManager
+    {
+        private static Window window;
+
+        static WindowManager()
+        {
+            window = Window.Instance;
+        }
+
+        public static void UpdateWindowPositionSize()
+        {
+            DeviceInfo.UpdateDeviceInfo();
+
+            int positionX, positionY;
+            int width, height;
+
+            float bottomMargin = 0.1f;
+            float widthRatio = 0.45f;
+            float heightRatio = 0.5f;
+
+            width = (int)(DeviceInfo.DisplayWidth * widthRatio);
+            height = (int)(DeviceInfo.DisplayHeight * (1-bottomMargin) * heightRatio);
+
+            positionX = ((DeviceInfo.IsPortrait? DeviceInfo.DisplayHeight : DeviceInfo.DisplayWidth) - width) / 2;
+            positionY = ((DeviceInfo.IsPortrait? DeviceInfo.DisplayWidth : DeviceInfo.DisplayHeight) - height) / 2;
+            positionY -= (int)((DeviceInfo.IsPortrait ? DeviceInfo.DisplayWidth : DeviceInfo.DisplayHeight) * bottomMargin);
+
+            if (DeviceInfo.IsPortrait)
+            {
+                (width, height) = (height, width);
+                (positionX, positionY) = (positionY, positionX);
+            }
+
+            window.WindowPositionSize = new Rectangle(positionX, positionY, width, height);
+
+            Logger.Debug("width is: " + window.WindowSize.Width);
+            Logger.Debug("height is: " + window.WindowSize.Height);
+            Logger.Debug("position X is: " + window.WindowPosition.X);
+            Logger.Debug("position Y is: " + window.WindowPosition.Y);
+        }
+    }
+}
index 58c240bc452e4d665a8d653fe6a37514bdd4da04..e1589870ee613037af9d007145cf858ea767e83c 100644 (file)
@@ -16,6 +16,7 @@
 
 using SettingCore;
 using SettingCore.Views;
+using SettingView.Core;
 using SettingView.TextResources;
 using System;
 using System.Collections.Generic;
@@ -123,7 +124,8 @@ namespace SettingView
             GetDefaultWindow().AddAvailableOrientation(Window.WindowOrientation.Landscape);
             GetDefaultWindow().AddAvailableOrientation(Window.WindowOrientation.PortraitInverse);
             GetDefaultWindow().AddAvailableOrientation(Window.WindowOrientation.LandscapeInverse);
-
+            WindowManager.UpdateWindowPositionSize();
+            appCustomBorder.UpdateMinSize(GetScreenSize());
             LogScalableInfoAsync();
 
             Logger.Performance($"ONCREATE end");
@@ -426,37 +428,8 @@ namespace SettingView
         static void Main(string[] args)
         {
             Logger.Performance($"MAIN start");
-
-            // window size adjustments
-            float bottomMargin = 0.1f;
-            float widthRatio = 0.45f;
-            float heightRatio = 0.5f;
-
-            _ = Information.TryGetValue("http://tizen.org/feature/screen.width", out int screenWidth);
-            _ = Information.TryGetValue("http://tizen.org/feature/screen.height", out int screenHeight);
-
-
-            Logger.Debug("screen width : " + screenWidth);
-            Logger.Debug("screen height : "+ screenHeight);
-
-            int width = (int)(screenWidth * widthRatio);
-            int height = (int)(screenHeight * (1 - bottomMargin) * heightRatio);
-
-            Logger.Debug("Window width : " + width);
-            Logger.Debug("Window height : " + height);
-
-            // INFO: it looks like size of custom border is not included in total window size
-            Size2D size = new Size2D(width, height);
-            Position2D position = new Position2D((screenWidth - width) / 2, (screenHeight - height) / 2 - (int)(bottomMargin * screenHeight));
-
-            Logger.Debug("Window position X: " + position.X);
-            Logger.Debug("Window position Y: " + position.Y);
-
-            appCustomBorder = new SettingViewBorder(new Size2D(screenWidth, screenHeight));
-
-            Logger.Performance($"MAIN border");
-
-            var app = new Program(size, position, ThemeOptions.PlatformThemeEnabled, appCustomBorder);
+            appCustomBorder =  new SettingViewBorder(new Size2D(800, 480));
+            var app = new Program(new Size(10, 10), new Position2D(0,0), ThemeOptions.PlatformThemeEnabled, appCustomBorder);
 
             app.Run(args);
         }
index 1e78cb06010983bb27a78fde457ee3f52892bad4..e3affc300b82de3c4c8a328b9e42a1e6fef8c632 100644 (file)
@@ -65,6 +65,15 @@ namespace SettingView
             ThemeManager.ThemeChanged += ThemeManager_ThemeChanged;
         }
 
+        public void UpdateMinSize(Size2D screenSize)
+        {
+            float minWidthRatio = 712.0f / 1920;
+            float minHeightRatio = 488.0f / 1080;
+            int minWidth = (int)(screenSize.Width * minWidthRatio);
+            int minHeight = (int)(screenSize.Height * minHeightRatio);
+            MinSize = new Size2D(minWidth, minHeight);
+        }
+
         private void ThemeManager_ThemeChanged(object sender, ThemeChangedEventArgs e)
         {
             if (borderView == null)
index 17f458e297e0ac4318ef14875c0e3bbac3a51183..e292f79b979f61d445b0955851a80af8a816f2d2 100644 (file)
Binary files a/packaging/org.tizen.cssettings-1.1.20.tpk and b/packaging/org.tizen.cssettings-1.1.20.tpk differ