[NUI] Add border resizing policy and add api to show/hide border when OverlayMode...
authorjoogab.yun <joogab.yun@samsung.com>
Sun, 29 May 2022 02:13:20 +0000 (11:13 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 2 Jun 2022 09:14:59 +0000 (18:14 +0900)
1. It can be proportionally resized or fixed according to the border resizing policy.
2. If OverlayMode is true, you can show/hide the border through api.
   Through this, you can show/hide the border by touch or specific key event.

src/Tizen.NUI/src/public/Window/BorderWindow.cs
src/Tizen.NUI/src/public/Window/DefaultBorder.cs
src/Tizen.NUI/src/public/Window/IBorderInterface.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/BorderWindowTest.cs

index a0ad263..8222e6f 100755 (executable)
@@ -36,9 +36,7 @@ namespace Tizen.NUI
         private Layer borderWindowRootLayer = null;
         private Layer borderWindowBottomLayer = null;
         private bool isBorderWindow = false;
-        private bool isInterceptTouch = false;
 
-        private Timer overlayTimer;
         private Color overlayBackgroundColor;
 
         // for border area
@@ -84,6 +82,26 @@ namespace Tizen.NUI
             BottomRight = ResizeDirection.BottomRight,
             Move,
         }
+
+        /// <summary>
+        /// This enum is the policy when resizing the border window. 
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public enum BorderResizePolicyType
+        {
+          /// <summary>
+          /// The window can be resized freely.
+          /// </summary>
+          Free = 0,
+          /// <summary>
+          /// The window is resized according to the ratio.
+          /// </summary>
+          KeepRatio = 1,
+          /// <summary>
+          /// The window is not resized and is fixed.
+          /// </summary>
+          Fixed = 2,
+        }
         #endregion //Enums
 
         #region Interfaces
@@ -169,9 +187,10 @@ namespace Tizen.NUI
                     WindowSize += new Size2D((int)borderInterface.BorderLineThickness * 2, (int)(borderHeight + borderInterface.BorderLineThickness * 2));
                 }
 
-                if (borderInterface.OverlayMode == true)
+                // If it is BorderResizePolicyType.KeepRatio type, it will be resized according to the ratio.
+                if (borderInterface.ResizePolicy == BorderResizePolicyType.KeepRatio)
                 {
-                    rootView.InterceptTouchEvent += OverlayInterceptTouch;
+                    AddAuxiliaryHint("wm.policy.win.resize_aspect_ratio", "1");
                 }
 
                 // Add a view to the border layer.
@@ -317,62 +336,12 @@ namespace Tizen.NUI
             return direction;
         }
 
-
-        private bool OverlayInterceptTouch(object sender, View.TouchEventArgs e)
-        {
-            if (e.Touch.GetState(0) == PointStateType.Down)
-            {
-                if (isInterceptTouch == true && overlayTimer != null)
-                {
-                    overlayTimer.Start();
-                }
-            }
-            return false;
-        }
-
-        private bool OnTick(object o, Timer.TickEventArgs e)
-        {
-            GetBorderWindowBottomLayer().LowerToBottom();
-            if (borderView != null)
-            {
-                borderView.Hide();
-            }
-            isInterceptTouch = false;
-
-            overlayTimer.Stop();
-            overlayTimer.Dispose();
-            overlayTimer = null;
-            return false;
-        }
-
-        // Intercept touch on window.
-        private bool OnWinInterceptTouch(object sender, Window.TouchEventArgs e)
-        {
-            if (e.Touch.GetState(0) == PointStateType.Up)
-            {
-                if (isInterceptTouch == false && overlayTimer == null)
-                {
-                    overlayTimer = new Timer(3000);
-                    overlayTimer.Tick += OnTick;
-                    overlayTimer.Start();
-                    GetBorderWindowBottomLayer().RaiseToTop();
-                    if (borderView != null)
-                    {
-                        borderView.Show();
-                    }
-                    isInterceptTouch = true;
-                }
-            }
-            return false;
-        }
-
         private void OverlayMode(bool enable)
         {
             if (borderInterface.OverlayMode == true)
             {
                 if (enable == true)
                 {
-                    InterceptTouchEvent += OnWinInterceptTouch;
                     if (borderView != null)
                     {
                         overlayBackgroundColor = new Color(borderView.BackgroundColor);
@@ -382,14 +351,6 @@ namespace Tizen.NUI
                 }
                 else
                 {
-                    if (overlayTimer != null)
-                    {
-                        overlayTimer.Stop();
-                        overlayTimer.Dispose();
-                        overlayTimer = null;
-                    }
-                    isInterceptTouch = false;
-                    InterceptTouchEvent -= OnWinInterceptTouch;
                     GetBorderWindowBottomLayer().LowerToBottom();
                     if (borderView != null)
                     {
index dbfee78..ce39b6e 100755 (executable)
@@ -67,6 +67,7 @@ namespace Tizen.NUI
         private View windowView = null;
         private bool isWinGestures = false;
         private Timer timer;
+        private Timer overlayTimer;
 
         private CurrentGesture currentGesture = CurrentGesture.None;
         private bool disposed = false;
@@ -136,6 +137,13 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public bool OverlayMode {get; set;}
 
+        /// <summary>
+        /// Set the window resizing policy.
+        /// Default value is BorderResizePolicyType.Free;
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Window.BorderResizePolicyType ResizePolicy {get; set;}
+
 
         /// <summary>
         /// Creates a default border
@@ -148,6 +156,7 @@ namespace Tizen.NUI
             BorderHeight = DefaultHeight;
             MinSize = DefaultMinSize;
             OverlayMode = false;
+            ResizePolicy = Window.BorderResizePolicyType.Free;
         }
 
         /// <summary>
@@ -353,7 +362,7 @@ namespace Tizen.NUI
                         BorderWindow.RequestMoveToServer();
                     }
                 }
-                else if (direction != Window.BorderDirection.None)
+                else if (direction != Window.BorderDirection.None && ResizePolicy != Window.BorderResizePolicyType.Fixed)
                 {
                     OnRequestResize();
                     BorderWindow.RequestResizeToServer((Window.ResizeDirection)direction);
@@ -372,17 +381,16 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public virtual bool OnLeftTopCornerIconTouched(object sender, View.TouchEventArgs e)
         {
-            if (e == null)
-            {
-                return false;
-            }
-            if (e.Touch.GetState(0) == PointStateType.Down)
+            if (e != null && e.Touch.GetState(0) == PointStateType.Down)
             {
               ClearWindowGesture();
-              OnRequestResize();
-              BorderWindow.RequestResizeToServer(Window.ResizeDirection.TopLeft);
+              if (ResizePolicy != Window.BorderResizePolicyType.Fixed)
+              {
+                OnRequestResize();
+                BorderWindow.RequestResizeToServer(Window.ResizeDirection.TopLeft);
+              }
             }
-            return true;
+            return false;
         }
 
         /// <summary>
@@ -391,17 +399,16 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public virtual bool OnRightTopCornerIconTouched(object sender, View.TouchEventArgs e)
         {
-            if (e == null)
-            {
-                return false;
-            }
-            if (e.Touch.GetState(0) == PointStateType.Down)
+            if (e != null && e.Touch.GetState(0) == PointStateType.Down)
             {
               ClearWindowGesture();
-              OnRequestResize();
-              BorderWindow.RequestResizeToServer(Window.ResizeDirection.TopRight);
+              if (ResizePolicy != Window.BorderResizePolicyType.Fixed)
+              {
+                OnRequestResize();
+                BorderWindow.RequestResizeToServer(Window.ResizeDirection.TopRight);
+              }
             }
-            return true;
+            return false;
         }
 
 
@@ -411,17 +418,16 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public virtual bool OnLeftBottomCornerIconTouched(object sender, View.TouchEventArgs e)
         {
-            if (e == null)
-            {
-                return false;
-            }
-            if (e.Touch.GetState(0) == PointStateType.Down)
+            if (e != null && e.Touch.GetState(0) == PointStateType.Down)
             {
               ClearWindowGesture();
-              OnRequestResize();
-              BorderWindow.RequestResizeToServer(Window.ResizeDirection.BottomLeft);
+              if (ResizePolicy != Window.BorderResizePolicyType.Fixed)
+              {
+                OnRequestResize();
+                BorderWindow.RequestResizeToServer(Window.ResizeDirection.BottomLeft);
+              }
             }
-            return true;
+            return false;
         }
 
         /// <summary>
@@ -430,17 +436,16 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public virtual bool OnRightBottomCornerIconTouched(object sender, View.TouchEventArgs e)
         {
-            if (e == null)
-            {
-                return false;
-            }
-            if (e.Touch.GetState(0) == PointStateType.Down)
+            if (e != null && e.Touch.GetState(0) == PointStateType.Down)
             {
               ClearWindowGesture();
-              OnRequestResize();
-              BorderWindow.RequestResizeToServer(Window.ResizeDirection.BottomRight);
+              if (ResizePolicy != Window.BorderResizePolicyType.Fixed)
+              {
+                OnRequestResize();
+                BorderWindow.RequestResizeToServer(Window.ResizeDirection.BottomRight);
+              }
             }
-            return true;
+            return false;
         }
 
 
@@ -461,15 +466,11 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public virtual bool OnMinimizeIconTouched(object sender, View.TouchEventArgs e)
         {
-            if (e == null)
-            {
-                return false;
-            }
-            if (e.Touch.GetState(0) == PointStateType.Up)
+            if (e != null && e.Touch.GetState(0) == PointStateType.Up)
             {
                 MinimizeBorderWindow();
             }
-            return true;
+            return false;
         }
 
         /// <summary>
@@ -497,15 +498,11 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public virtual bool OnMaximizeIconTouched(object sender, View.TouchEventArgs e)
         {
-            if (e == null)
-            {
-                return false;
-            }
-            if (e.Touch.GetState(0) == PointStateType.Up)
+            if (e != null && e.Touch.GetState(0) == PointStateType.Up)
             {
                 MaximizeBorderWindow();
             }
-            return true;
+            return false;
         }
 
         /// <summary>
@@ -528,12 +525,11 @@ namespace Tizen.NUI
             {
                 return false;
             }
-            if (e.Touch.GetState(0) == PointStateType.Up)
+            if (e != null && e.Touch.GetState(0) == PointStateType.Up)
             {
-                BorderWindow.Destroy();
-                BorderWindow = null;
+                CloseBorderWindow();
             }
-            return true;
+            return false;
         }
 
 
@@ -608,6 +604,7 @@ namespace Tizen.NUI
             {
                 return;
             }
+            this.borderView = borderView;
             // Register to resize and move through pan gestures.
             borderPanGestureDetector = new PanGestureDetector();
             borderPanGestureDetector.Attach(borderView);
@@ -788,6 +785,14 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public virtual void OnResized(int width, int height)
         {
+            if (overlayTimer != null)
+            {
+                overlayTimer.Stop();
+                overlayTimer.Dispose();
+                overlayTimer = null;
+                BorderWindow?.GetBorderWindowBottomLayer().LowerToBottom();
+                borderView?.Show();
+            }
             UpdateIcons();
         }
 
@@ -811,6 +816,56 @@ namespace Tizen.NUI
             UpdateIcons();
         }
 
+        /// <summary>
+        /// Show the border when OverlayMode is true and the window is now Maximize.
+        /// </summary>
+        /// <param name="time">Time(ms) for borders to disappear again</param>
+        /// <returns>True if border became show, false otherwise</returns>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public virtual bool OverlayBorderShow(uint time = 3000)
+        {
+            if (BorderWindow != null && BorderWindow.IsMaximized())
+            {
+                if (overlayTimer == null)
+                {
+                    overlayTimer = new Timer(time);
+                    overlayTimer.Tick += (s, e) =>
+                    {
+                        BorderWindow.GetBorderWindowBottomLayer().LowerToBottom();
+                        borderView?.Hide();
+                        overlayTimer?.Stop();
+                        overlayTimer?.Dispose();
+                        overlayTimer = null;
+                        return false;
+                    };
+                    overlayTimer.Start();
+                    BorderWindow.GetBorderWindowBottomLayer().RaiseToTop();
+                    borderView?.Show();
+                }
+                else
+                {
+                    overlayTimer.Start();
+                }
+                return true;
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// Hide the border when OverlayMode is true and the window is now Maximize.
+        /// </summary>
+        /// <returns>True if border became hide, false otherwise</returns>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public virtual bool OverlayBorderHide()
+        {
+            if (BorderWindow != null && BorderWindow.IsMaximized())
+            {
+                borderView?.Hide();
+                return true;
+            }
+            return false;
+        }
+
         [EditorBrowsable(EditorBrowsableState.Never)]
         protected virtual void Dispose(bool disposing)
         {
@@ -836,6 +891,7 @@ namespace Tizen.NUI
                 leftCornerIcon?.Dispose();
                 rightCornerIcon?.Dispose();
                 timer?.Dispose();
+                overlayTimer?.Dispose();
                 windowView?.Dispose();
                 borderView?.Dispose();
             }
index 16e3d4f..b95ef36 100755 (executable)
@@ -73,6 +73,12 @@ namespace Tizen.NUI
         public bool OverlayMode {get;}
 
         /// <summary>
+        /// Set the window resizing policy.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Window.BorderResizePolicyType ResizePolicy {get;}
+
+        /// <summary>
         /// Create top border UI. User can override this method to draw top border UI.
         /// </summary>
         /// <param name="topView">The top view on which the border.</param>
index e26bb3b..79fd2f7 100755 (executable)
@@ -306,9 +306,17 @@ namespace Tizen.NUI.Samples
     {
       if (subWindowTwo == null)
       {
-        IBorderInterface customBorder = new CustomBorder();
+        CustomBorder customBorder = new CustomBorder();
         subWindowTwo = new Window("subwin1", customBorder, new Rectangle(60, 20, 800, 800), false);
-        subWindowTwo.EnableFloatingMode(true);
+        subWindowTwo.InterceptTouchEvent += (s, e) => 
+        {
+            Tizen.Log.Error("NUI", $"subWindowTwo.InterceptTouchEvent\n");
+            if (e.Touch.GetState(0) == PointStateType.Down)
+            {
+              customBorder.OverlayBorderShow();
+            }
+            return false;
+        };
 
         var root = new View(){
           Layout = new LinearLayout()