From: joogab.yun Date: Sun, 29 May 2022 02:13:20 +0000 (+0900) Subject: [NUI] Add border resizing policy and add api to show/hide border when OverlayMode... X-Git-Tag: accepted/tizen/unified/20231205.024657~924 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0c1a8a123a5091f877a45bd6c9e350432af22032;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Add border resizing policy and add api to show/hide border when OverlayMode is true. 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. --- diff --git a/src/Tizen.NUI/src/public/Window/BorderWindow.cs b/src/Tizen.NUI/src/public/Window/BorderWindow.cs index a0ad263..8222e6f 100755 --- a/src/Tizen.NUI/src/public/Window/BorderWindow.cs +++ b/src/Tizen.NUI/src/public/Window/BorderWindow.cs @@ -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, } + + /// + /// This enum is the policy when resizing the border window. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public enum BorderResizePolicyType + { + /// + /// The window can be resized freely. + /// + Free = 0, + /// + /// The window is resized according to the ratio. + /// + KeepRatio = 1, + /// + /// The window is not resized and is fixed. + /// + 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) { diff --git a/src/Tizen.NUI/src/public/Window/DefaultBorder.cs b/src/Tizen.NUI/src/public/Window/DefaultBorder.cs index dbfee78..ce39b6e 100755 --- a/src/Tizen.NUI/src/public/Window/DefaultBorder.cs +++ b/src/Tizen.NUI/src/public/Window/DefaultBorder.cs @@ -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;} + /// + /// Set the window resizing policy. + /// Default value is BorderResizePolicyType.Free; + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Window.BorderResizePolicyType ResizePolicy {get; set;} + /// /// Creates a default border @@ -148,6 +156,7 @@ namespace Tizen.NUI BorderHeight = DefaultHeight; MinSize = DefaultMinSize; OverlayMode = false; + ResizePolicy = Window.BorderResizePolicyType.Free; } /// @@ -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; } /// @@ -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; } /// @@ -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; } /// @@ -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; } /// @@ -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(); } + /// + /// Show the border when OverlayMode is true and the window is now Maximize. + /// + /// Time(ms) for borders to disappear again + /// True if border became show, false otherwise + [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; + } + + /// + /// Hide the border when OverlayMode is true and the window is now Maximize. + /// + /// True if border became hide, false otherwise + [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(); } diff --git a/src/Tizen.NUI/src/public/Window/IBorderInterface.cs b/src/Tizen.NUI/src/public/Window/IBorderInterface.cs index 16e3d4f..b95ef36 100755 --- a/src/Tizen.NUI/src/public/Window/IBorderInterface.cs +++ b/src/Tizen.NUI/src/public/Window/IBorderInterface.cs @@ -73,6 +73,12 @@ namespace Tizen.NUI public bool OverlayMode {get;} /// + /// Set the window resizing policy. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Window.BorderResizePolicyType ResizePolicy {get;} + + /// /// Create top border UI. User can override this method to draw top border UI. /// /// The top view on which the border. diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/BorderWindowTest.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/BorderWindowTest.cs index e26bb3b..79fd2f7 100755 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/BorderWindowTest.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/BorderWindowTest.cs @@ -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()