+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * 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 System;
-using System.Collections.Generic;
-using Tizen.NUI;
-using Tizen.NUI.BaseComponents;
-using Tizen.NUI.Components;
-
-namespace Oobe.Controls
-{
- /// <summary>
- /// ViewStack implemenents stack based navigation in which all child views are stacked over each other
- /// and only the most recent child added is visible.
- /// </summary>
- public class ViewStack : View
- {
- private List<View> views = new List<View>();
- private List<View> viewsToRemove = new List<View>();
-
- private Animation pageEnterAnimation;
- private Animation pageLeaveAnimation;
- private Animation opacityEffectAnimation;
-
- public ViewStack()
- : base()
- {
- ClippingMode = ClippingModeType.ClipToBoundingBox;
- pageEnterAnimation = new Animation();
- pageLeaveAnimation = new Animation();
- opacityEffectAnimation = new Animation();
- pageEnterAnimation.Finished += OnPageEntered;
- pageLeaveAnimation.Finished += OnPageLeave;
- }
-
- /// <summary>
- /// Informs about transition animation end
- /// </summary>
- public event EventHandler TransitionFinished;
-
- /// <summary>
- /// Number of pixels between stack right boundary and newly pushed child view left boundary,
- /// which will be applied before starting page entering animation.
- /// </summary>
- /// <value></value>
- public int PagesRightPadding { get; set; } = 0;
-
- /// <summary>
- /// Number of pixels between stack right boundary and current top child view left boundary,
- /// which will be applied after finishing page leaving animation
- /// </summary>
- public int PagesLeftPadding { get; set; } = 0;
-
- /// <summary>
- /// Duration of page entering and page leaving animations
- /// </summary>
- public int ScrollDuration { get; set; } = 125;
-
- /// <summary>
- /// Get view currently stacked on Top of ViewStack
- /// </summary>
- public View Current
- {
- get
- {
- return views.Count > 0 ? views[views.Count - 1] : null;
- }
- }
-
- /// <summary>
- /// Get view currently stacked under Current
- /// </summary>
- public View Previous
- {
- get
- {
- return views.Count > 1 ? views[views.Count - 2] : null;
- }
- }
-
- /// <summary>
- /// Pop Current view with animation
- /// </summary>
- public void Pop()
- {
- if (Current != null)
- {
- FinishAnimations();
- RemoveAllDelayedViews();
- StartPageLeaveAnimation(Previous, Current);
- StartShowAnimation(Previous);
- AddViewToDelayRemove(Current);
- views.Remove(Current);
- }
- }
-
- /// <summary>
- /// Pushed new view on stack with animation.
- /// </summary>
- public void Push(View view)
- {
- FinishAnimations();
- RemoveAllDelayedViews();
- Add(view);
- views.Add(view);
- StartPageEnterAnimation(Previous, Current);
- StartHideAnimation(Previous);
- }
-
- protected override void Dispose(Tizen.NUI.DisposeTypes type)
- {
- if (disposed)
- {
- return;
- }
-
- if (type == DisposeTypes.Explicit)
- {
- pageEnterAnimation.Dispose();
- pageLeaveAnimation.Dispose();
- }
-
- base.Dispose(type);
- }
-
- private static void FinishAnimation(Animation anim)
- {
- if (anim != null)
- {
- if (anim.State == Animation.States.Playing)
- {
- anim.Stop(Animation.EndActions.StopFinal);
- }
-
- anim.Clear();
- }
- }
-
- private void AddViewToDelayRemove(View view)
- {
- if (view)
- {
- viewsToRemove.Add(view);
- }
- }
-
- private void RemoveAllDelayedViews()
- {
- foreach (View view in viewsToRemove)
- {
- // hide view to resolve issue with rendering artifacts
- view.Hide();
- Remove(view);
- view.Dispose();
- }
-
- viewsToRemove.Clear();
- }
-
- private void FinishAnimations()
- {
- FinishAnimation(pageLeaveAnimation);
- FinishAnimation(pageEnterAnimation);
- FinishAnimation(opacityEffectAnimation);
- }
-
- private void StartPageLeaveAnimation(View back, View front)
- {
- pageLeaveAnimation.Duration = ScrollDuration;
- pageLeaveAnimation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine);
-
- if (back != null)
- {
- // place 'back' out of viewport (should be already there)
- // run animation to place 'back' in viewport
- pageLeaveAnimation.AnimateTo(back, "PositionX", 0, null);
- }
-
- if (front != null)
- {
- // place 'front' in viewport (should be already there)
- // run animation to place 'front' out of viewport
- pageLeaveAnimation.AnimateTo(front, "PositionX", Size2D.Width + PagesRightPadding);
- }
-
- pageLeaveAnimation.Play();
- }
-
- private void StartPageEnterAnimation(View back, View front)
- {
- pageEnterAnimation.Duration = ScrollDuration;
- pageEnterAnimation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOutSine);
-
- if (back != null)
- {
- // place back in viewport (should be already there)
- // run anim to place 'back' out of viewport
- int diff = Position2D.X - PagesLeftPadding;
- pageEnterAnimation.AnimateTo(back, "PositionX", diff);
- }
-
- if (front != null)
- {
- // place 'front' out of viewport
- front.Position2D.X = Size2D.Width + PagesRightPadding;
-
- // run anim to place 'front' on viewport
- pageEnterAnimation.AnimateTo(front, "PositionX", 0, null);
- }
-
- pageEnterAnimation.Play();
- }
-
- private void OnPageEntered(object sender, EventArgs args)
- {
- TransitionFinished?.Invoke(this, new EventArgs());
- }
-
- private void OnPageLeave(object sender, EventArgs args)
- {
- RemoveAllDelayedViews();
- TransitionFinished?.Invoke(this, new EventArgs());
- }
-
- private void StartHideAnimation(View view)
- {
- StartOpacityAnimation(view, 1.0f, 0.0f);
- }
-
- private void StartShowAnimation(View view)
- {
- StartOpacityAnimation(view, 0.0f, 1.0f);
- }
-
- private void StartOpacityAnimation(View view, float from, float to)
- {
- if (view != null)
- {
- opacityEffectAnimation.Duration = ScrollDuration;
- view.Opacity = from;
- opacityEffectAnimation.AnimateTo(view, "Opacity", to);
- opacityEffectAnimation.Play();
- }
- }
-
- private class ViewStackBaseCustomLayout : LayoutGroup
- {
- protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
- {
- ViewStack stack = this.Owner as ViewStack;
-
- if (!stack)
- {
- return;
- }
-
- int totalWidth = stack.Size2D.Width;
- int totalHeight = stack.Size2D.Height;
-
- SetMeasuredDimensions(
- ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, MeasuredSize.StateType.MeasuredSizeOK),
- ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, MeasuredSize.StateType.MeasuredSizeOK));
- }
-
- protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
- {
- ViewStack stack = this.Owner as ViewStack;
-
- if (!changed || !stack)
- {
- return;
- }
-
- int totalWidth = stack.Size2D.Width;
- int totalHeight = stack.Size2D.Height;
-
- foreach (LayoutItem childLayout in LayoutChildren)
- {
- if (childLayout.Owner == stack.Current)
- {
- childLayout.Layout(
- new LayoutLength(0),
- new LayoutLength(0),
- new LayoutLength(totalWidth),
- new LayoutLength(totalHeight));
- }
- else
- {
- childLayout.Layout(
- new LayoutLength(-stack.PagesLeftPadding),
- new LayoutLength(0),
- new LayoutLength(totalWidth - stack.PagesLeftPadding),
- new LayoutLength(totalHeight));
- }
- }
- }
- }
- }
-}
public class OrientationalView : Tizen.NUI.BaseComponents.View
{
public enum Mode
- {
+ {
Stacking,
Splitting,
};
private async void AddStacking(View child)
{
- Push(child);
- //int width = Size2D.Width - (Padding.Start + Padding.End);
- //int height = Size2D.Height - (Padding.Top + Padding.Bottom);
-
- //if (ChildCount > 1)
- //{
- // var prev = Children.Skip(Children.Count - 2).First();
-
- // // fade out current item
- // await Animation.AnimateTo(prev, "Opacity", 0.0f);
- // prev.Hide();
- //}
-
- //// show next item behind the screen
- //child.Size2D = new Size2D(width, height);
- //child.Position2D = new Position2D(Size2D.Width, Padding.Top);
- //child.Show();
-
- //// animate next item to correct position
- //await Animation.AnimateTo(child, "PositionX", (int)Padding.Start);
+ FinishAnimations();
+ RemoveAllDelayedViews();
+ base.Add(child);
+ views.Add(child);
+ StartPageEnterAnimation(Previous, Current);
+ StartHideAnimation(Previous);
}
private async Task RemoveStacking(View child)
{
- Pop();
- //var last = Children.Last();
- //await Animation.AnimateTo(last, "PositionX", Size2D.Width);
- //last.Hide();
-
- //var prev = Children.Skip(Children.Count - 2).First();
- //if (prev != null)
- //{
- // prev.Show();
- // await Animation.AnimateTo(prev, "Opacity", 1.0f);
- //}
+ if (Current == child)
+ {
+ FinishAnimations();
+ RemoveAllDelayedViews();
+ StartPageLeaveAnimation(Previous, Current);
+ StartShowAnimation(Previous);
+ AddViewToDelayRemove(Current);
+ views.Remove(Current);
+
+ }
+ else
+ {
+ views.Remove(child);
+ }
+
}
private List<View> views = new List<View>();
}
}
- /// <summary>
- /// Pop Current view with animation
- /// </summary>
- public void Pop()
- {
- if (Current != null)
- {
- FinishAnimations();
- RemoveAllDelayedViews();
- StartPageLeaveAnimation(Previous, Current);
- StartShowAnimation(Previous);
- AddViewToDelayRemove(Current);
- views.Remove(Current);
- }
- }
-
- /// <summary>
- /// Pushed new view on stack with animation.
- /// </summary>
- public void Push(View view)
- {
- FinishAnimations();
- RemoveAllDelayedViews();
- Add(view);
- views.Add(view);
- StartPageEnterAnimation(Previous, Current);
- StartHideAnimation(Previous);
- }
-
protected override void Dispose(Tizen.NUI.DisposeTypes type)
{
if (disposed)
{
// hide view to resolve issue with rendering artifacts
view.Hide();
- Remove(view);
+ base.Remove(view);
view.Dispose();
}
opacityEffectAnimation.Play();
}
}
-
- //private class ViewStackBaseCustomLayout : LayoutGroup
- //{
- // protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
- // {
- // OrientationalView stack = this.Owner as OrientationalView;
-
- // if (!stack)
- // {
- // return;
- // }
-
- // int totalWidth = stack.Size2D.Width;
- // int totalHeight = stack.Size2D.Height;
-
- // SetMeasuredDimensions(
- // ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, MeasuredSize.StateType.MeasuredSizeOK),
- // ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, MeasuredSize.StateType.MeasuredSizeOK));
- // }
-
- // protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
- // {
- // OrientationalView stack = this.Owner as OrientationalView;
-
- // if (!changed || !stack)
- // {
- // return;
- // }
-
- // int totalWidth = stack.Size2D.Width;
- // int totalHeight = stack.Size2D.Height;
-
- // foreach (LayoutItem childLayout in LayoutChildren)
- // {
- // if (childLayout.Owner == stack.Current)
- // {
- // childLayout.Layout(
- // new LayoutLength(0),
- // new LayoutLength(0),
- // new LayoutLength(totalWidth),
- // new LayoutLength(totalHeight));
- // }
- // else
- // {
- // childLayout.Layout(
- // new LayoutLength(-stack.PagesLeftPadding),
- // new LayoutLength(0),
- // new LayoutLength(totalWidth - stack.PagesLeftPadding),
- // new LayoutLength(totalHeight));
- // }
- // }
- // }
- //}
}
}
*/
using System;
-using Oobe.Controls;
using Tizen.NUI;
using Tizen.NUI.BaseComponents;
using Tizen.NUI.Components;
{
private const int TransitionTime = 750;
private readonly Extents stackMargin = new Extents(48, 48, 48, 48);
- //private ViewStack stack;
private ScalableUI.OrientationalView orientational;
private Pagination pagination;
+ private bool firstPushed = false;
public MainView(Window win)
: base()
{
- Size2D stackSize = new Size2D(
- win.WindowSize.Width - stackMargin.Start - stackMargin.End,
- win.WindowSize.Height - stackMargin.Top - stackMargin.Bottom);
-
BackgroundImage = NUIApplication.Current.DirectoryInfo.Resource + "0_BG_dark.png";
MaxMargin = 0.25f;
+ //Padding = stackMargin;
+
+ Size2D orientationalSize = new Size2D(
+ (int)(this.Size.Width - stackMargin.Start - stackMargin.End),
+ (int)(this.Size.Height - stackMargin.Top - stackMargin.Bottom));
- /* For testing other resolutions
- stackSize.Width = 1280 - stackMargin.Start - stackMargin.End;
- stackSize.Height = 720 - stackMargin.Top - stackMargin.Bottom;
- */
-
- //stack = new ViewStack()
- //{
- // ScrollDuration = TransitionTime,
- // Position2D = new Position2D(stackMargin.Start, stackMargin.Top),
- // Size2D = stackSize,
- // PagesRightPadding = stackMargin.Start,
- // PagesLeftPadding = (int)(0.5f * stackSize.Width),
- // ClippingMode = ClippingModeType.Disabled,
- //};
+ Tizen.Log.Debug("oobe", $"OrientationalSize: {orientationalSize.Width} {orientationalSize.Height}");
+ Tizen.Log.Debug("oobe", $"this.Size: {this.Size.Width} {this.Size.Height}");
orientational = new ScalableUI.OrientationalView
{
LandscapeMode = ScalableUI.OrientationalView.Mode.Stacking,
- PositionUsesPivotPoint = true,
- ParentOrigin = Position.ParentOriginCenter,
- PivotPoint = Position.PivotPointCenter,
- //Position2D = new Position2D(0, 0),
- Padding = stackMargin,
- Size2D = this.Size
+ Size = orientationalSize,
+ Position2D = new Position2D(0, 0),
};
Add(orientational);
};
pagination.IndicatorSpacing = 12;
- //Add(stack);
Add(pagination);
}
view.HeightResizePolicy = ResizePolicyType.FillToParent;
view.WidthResizePolicy = ResizePolicyType.FillToParent;
- pagination.SelectedIndex = pagination.SelectedIndex + 1;
+ if (firstPushed)
+ {
+ pagination.SelectedIndex = pagination.SelectedIndex + 1;
+ }
+ firstPushed = true;
orientational.Add(view);
- //stack.Push(view);
}
public void Pop()
{
pagination.SelectedIndex = pagination.SelectedIndex - 1;
orientational.RemoveLastAdded();
- //stack.Pop();
}
protected override void Dispose(DisposeTypes type)
if (type == DisposeTypes.Explicit)
{
- //stack.Dispose();
pagination.Dispose();
orientational.Dispose();
}