From: Md. Farhan Mahtab/NC eXperience Group /SRBD/Engineer/Samsung Electronics Date: Tue, 9 Jul 2024 11:13:31 +0000 (+0600) Subject: Fix window position and size issue in low resolution. X-Git-Tag: accepted/tizen/unified/20240715.155409~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=78f3ed9238743cc65c4bbe6054e13d02e83f446a;p=profile%2Fiot%2Fapps%2Fdotnet%2Fsettings.git Fix window position and size issue in low resolution. [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 --- diff --git a/SettingView/Common/DeviceInfo.cs b/SettingView/Common/DeviceInfo.cs new file mode 100644 index 0000000..9c68afc --- /dev/null +++ b/SettingView/Common/DeviceInfo.cs @@ -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 index 0000000..33c8b40 --- /dev/null +++ b/SettingView/Core/WindowManager.cs @@ -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); + } + } +} diff --git a/SettingView/SettingView.cs b/SettingView/SettingView.cs index 58c240b..e158987 100644 --- a/SettingView/SettingView.cs +++ b/SettingView/SettingView.cs @@ -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); } diff --git a/SettingView/SettingViewBorder.cs b/SettingView/SettingViewBorder.cs index 1e78cb0..e3affc3 100644 --- a/SettingView/SettingViewBorder.cs +++ b/SettingView/SettingViewBorder.cs @@ -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) diff --git a/packaging/org.tizen.cssettings-1.1.20.tpk b/packaging/org.tizen.cssettings-1.1.20.tpk index 17f458e..e292f79 100644 Binary files a/packaging/org.tizen.cssettings-1.1.20.tpk and b/packaging/org.tizen.cssettings-1.1.20.tpk differ