Skip to content

Commit

Permalink
[NUI] Register OrientationChanged for BorderWindow.
Browse files Browse the repository at this point in the history
Because if the window is rotated, we need to resize the window by recalculating the border area.
  • Loading branch information
JoogabYun committed Jul 11, 2023
1 parent 3c2ffc6 commit 44d24a5
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/Tizen.NUI/src/public/Window/BorderWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public partial class Window
private IBorderInterface borderInterface = null;
private Layer borderWindowRootLayer = null;
private Layer borderWindowBottomLayer = null;
private WindowOrientation currentOrientation;

// for border area
private View rootView = null;
Expand Down Expand Up @@ -186,14 +187,14 @@ internal void UpdateProperty()
SetMimimumSize(mimimumSize);
minSize = borderInterface.MinSize;
}

if (maxSize != borderInterface.MaxSize || (borderInterface.MaxSize != null && isNeedResizeByLine == true))
{
using Size2D maximumSize = new Size2D((borderInterface.MaxSize?.Width + (int)borderLineThickness * 2 ?? 0), (borderInterface.MaxSize?.Height ?? 0) + (int)(borderHeight + borderLineThickness * 2));
SetMaximumSize(maximumSize);
maxSize = borderInterface.MaxSize;
}

if (borderResizePolicy != borderInterface.ResizePolicy)
{
AddAuxiliaryHint("wm.policy.win.resize_aspect_ratio", "0");
Expand All @@ -203,7 +204,7 @@ internal void UpdateProperty()
AddAuxiliaryHint("wm.policy.win.resize_aspect_ratio", "1");
}
}

}
}
/// <summary>
Expand Down Expand Up @@ -261,6 +262,10 @@ internal bool EnableBorder(IBorderInterface borderInterface, BorderCloseDelegate

if (CreateBorder() == true)
{
Tizen.Log.Info("NUI", $"currentOrientation {currentOrientation}\n");
currentOrientation = GetCurrentOrientation();
currentOrientation = (currentOrientation == WindowOrientation.Portrait || currentOrientation == WindowOrientation.PortraitInverse) ? WindowOrientation.Portrait : WindowOrientation.Landscape;

using var realWindowSize = new Size2D(WindowSize.Width, WindowSize.Height);

isBorderWindow = true;
Expand All @@ -269,6 +274,8 @@ internal bool EnableBorder(IBorderInterface borderInterface, BorderCloseDelegate

Moved += OnBorderWindowMoved;

OrientationChanged += OnBorderWindowOrientationChanged;

borderInterface.OnCreated(borderView);

// Increase the window size as much as the border area.
Expand Down Expand Up @@ -536,6 +543,22 @@ private void OnBorderWindowMoved(object sender, WindowMovedEventArgs e)
borderInterface.OnMoved(e.WindowPosition.X, e.WindowPosition.X);
}

private void OnBorderWindowOrientationChanged(object sender, WindowOrientationChangedEventArgs e)
{
WindowOrientation orientation = e.WindowOrientation;
orientation = (orientation == WindowOrientation.Portrait || orientation == WindowOrientation.PortraitInverse) ? WindowOrientation.Portrait : WindowOrientation.Landscape;
if (currentOrientation != orientation)
{
if (isEnabledOverlayMode == false && IsFloatingModeEnabled() == false)
{
using var val = new Uint16Pair(Interop.Window.GetSize(SwigCPtr), true);
Tizen.Log.Info("NUI", $"OnBorderWindowOrientationChanged {e.WindowOrientation} {val.GetWidth()},{val.GetHeight()}\n");
uint borderLine = borderLineThickness * 2;
WindowSize = new Size2D((int)(val.GetWidth() - borderHeight - borderLine), (int)(val.GetHeight() - borderLine));
}
}
currentOrientation = orientation;
}

// Called when the window size has changed.
private void OnBorderWindowResized(object sender, Window.ResizedEventArgs e)
Expand Down Expand Up @@ -625,6 +648,8 @@ internal void DisposeBorder()
{
Resized -= OnBorderWindowResized;
FocusChanged -= OnWindowFocusChanged;
Moved -= OnBorderWindowMoved;
OrientationChanged -= OnBorderWindowOrientationChanged;
borderInterface.Dispose();
GetBorderWindowBottomLayer().Dispose();
}
Expand Down

0 comments on commit 44d24a5

Please sign in to comment.