[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>
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
using SettingCore;
using SettingCore.Views;
+using SettingView.Core;
using SettingView.TextResources;
using System;
using System.Collections.Generic;
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");
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);
}
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)