Skip to content

Commit

Permalink
Merge branch 'main' of github.sec.samsung.net:dotnet/Tizen.UIExtensio…
Browse files Browse the repository at this point in the history
…ns into main
  • Loading branch information
rookiejava committed Apr 22, 2021
2 parents b47bed1 + 3c70ec5 commit 065bf7c
Show file tree
Hide file tree
Showing 39 changed files with 3,765 additions and 27 deletions.
25 changes: 25 additions & 0 deletions src/Tizen.UIExtensions.Common/DateChangedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace Tizen.UIExtensions.Common
{
/// <summary>
/// DateChangedEventArgs event arguments.
/// </summary>
public class DateChangedEventArgs : EventArgs
{
/// <summary>
/// The date that the user entered.
/// </summary>
public DateTime NewDate { get; }

/// <summary>
/// Creates a new <see cref="DateChangedEventArgs"/> object that represents a change from <paramref name="oldDate"/> to <paramref name="newDate"/>.
/// </summary>
/// <param name="oldDate">Old date of <see cref="DatePicker"/>.</param>
/// <param name="newDate">Current date of <see cref="DatePicker"/>.</param>
public DateChangedEventArgs(DateTime newDate)
{
NewDate = newDate;
}
}
}
31 changes: 31 additions & 0 deletions src/Tizen.UIExtensions.Common/TextChangedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;

namespace Tizen.UIExtensions.Common
{
/// <summary>
/// TextChangedEventArgs event arguments.
/// </summary>
public class TextChangedEventArgs : EventArgs
{
/// <summary>
/// Creates a new <see cref="TextChangedEventArgs"/> object that represents a change from <paramref name="oldTextValue"/> to <paramref name="newTextValue"/>.
/// </summary>
/// <param name="oldTextValue">Old text value of <see cref="Entry"/>.</param>
/// <param name="newTextValue">New text value of <see cref="Entry"/>.</param>
public TextChangedEventArgs(string oldTextValue, string newTextValue)
{
OldTextValue = oldTextValue;
NewTextValue = newTextValue;
}

/// <summary>
/// The new text
/// </summary>
public string NewTextValue { get; private set; }

/// <summary>
/// The old text
/// </summary>
public string OldTextValue { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<Compile Include="$(MSBuildThisFileDirectory)BatchableExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Color.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ConsoleLogger.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TextChangedEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DateChangedEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DeviceOrientation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DlogLogger.cs" />
<Compile Include="..\Tizen.UIExtensions.Common\DrawerHeaderBehavior.cs" />
Expand Down
200 changes: 200 additions & 0 deletions src/Tizen.UIExtensions.ElmSharp/CarouselPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
using ElmSharp;
using System;
using System.Collections.Generic;
using EBox = Tizen.UIExtensions.ElmSharp.Box;

namespace Tizen.UIExtensions.ElmSharp
{
/// <summary>
/// The native box that provides CarouselPage features.
/// </summary>
public class CarouselPage : EBox
{
const int ItemMaxCount = 20;

Index _index;
List<IndexItem> _items = new List<IndexItem>();

int _childCount = 0;

EBox _innerContainer;
Scroller _scroller;

Size _layoutBound;

List<EvasObject> _childrenList = new List<EvasObject>();

/// <summary>
/// Initializes a new instance of the CarouselPage class.
/// </summary>
public CarouselPage(EvasObject parent) : base(parent)
{
AlignmentX = -1;
AlignmentY = -1;
WeightX = 1;
WeightY = 1;
Show();

_scroller = new Scroller(parent)
{
HorizontalScrollBarVisiblePolicy = ScrollBarVisiblePolicy.Invisible,
VerticalScrollBarVisiblePolicy = ScrollBarVisiblePolicy.Invisible,
HorizontalPageScrollLimit = 1,
HorizontalRelativePageSize = 1.0,
AlignmentX = -1,
AlignmentY = -1,
WeightX = 1,
WeightY = 1,
};
_scroller.PageScrolled += OnPageScrolled;
_scroller.Show();

_innerContainer = new EBox(parent)
{
AlignmentX = -1,
AlignmentY = -1,
WeightX = 1,
WeightY = 1,
};
_innerContainer.SetLayoutCallback(OnInnerLayoutUpdate);
_innerContainer.Show();
_scroller.SetContent(_innerContainer);

_index = new Index(parent)
{
IsHorizontal = true,
AutoHide = false,
AlignmentX = -1,
AlignmentY = -1,
WeightX = 1,
WeightY = 1,
};
_index.Changed += OnIndexChanged;
_index.Show();

SetLayoutCallback(OnOutterLayoutUpdate);
PackEnd(_scroller);
PackEnd(_index);
}

/// <summary>
/// Raised when the page has been scrolled.
/// </summary>
public event EventHandler<PageScrolledEventArgs> PageScrolled;

/// <summary>
/// The current index of the displayed page.
/// </summary>
public int CurrentPageIndex { get; set; }

/// <summary>
/// Add a child box to the CarouselPage.
/// </summary>
public void AddChildrenList(EvasObject box)
{
_childrenList.Add(box);
_innerContainer.PackEnd(box);
}

/// <summary>
/// Resets the child box list.
/// </summary>
public void ResetChildrenList()
{
_innerContainer.UnPackAll();
_childrenList.Clear();
_layoutBound = new Size(0, 0);
}

/// <summary>
/// Scroll to pages.
/// </summary>
/// <param name="index">The index of horizontal page to scroll.</param>
/// <param name="animated">Whether or not to animate the scroll.</param>
public void ScrollTo(int index, bool animated)
{
_scroller.ScrollTo(index, 0, animated);
}

/// <summary>
/// Updates the index item.
/// </summary>
public void UpdateIndexItem()
{
_index.SetStyledIndex();
_index.Clear();
_items.Clear();

var indexCount = _childrenList.Count;
if (indexCount > ItemMaxCount)
indexCount = ItemMaxCount;
for (int i = 0; i < indexCount; i++)
{
var item = _index.Append(i.ToString());
_items.Add(item);
}
_index.Update(0);
OnSelect(CurrentPageIndex);
}

void OnSelect(int selectIndex)
{
if (selectIndex >= ItemMaxCount)
selectIndex = ItemMaxCount - 1;
if (selectIndex > -1)
_items[selectIndex].Select(true);
}

void OnIndexChanged(object sender, EventArgs e)
{
var changedIndex = _items.IndexOf(_index.SelectedItem);
if (changedIndex != CurrentPageIndex)
ScrollTo(changedIndex, true);
}

void OnInnerLayoutUpdate()
{
if (_layoutBound == _innerContainer.Geometry.Size && _childCount == _childrenList.Count)
return;

_layoutBound = _innerContainer.Geometry.Size;
_childCount = _childrenList.Count;

int baseX = _innerContainer.Geometry.X;
Rect bound = _scroller.Geometry;
int index = 0;

foreach (var nativeView in _childrenList)
{
bound.X = baseX + index * bound.Width;
nativeView.Geometry = bound;
index++;
}

var widthRequest = _childCount * bound.Width;
_innerContainer.MinimumWidth = widthRequest;
if (_innerContainer.Geometry.Width == widthRequest && _scroller.HorizontalPageIndex != CurrentPageIndex)
ScrollTo(CurrentPageIndex, true);
}

void OnOutterLayoutUpdate()
{
_scroller.Geometry = Geometry;
var newGeometry = Geometry;
newGeometry.Height = (int)(Geometry.Height * 0.1);
newGeometry.Y += (int)(Geometry.Height * 0.9);
_index.Geometry = newGeometry;
}

void OnPageScrolled(object sender, EventArgs e)
{
int previousPageIndex = CurrentPageIndex;
CurrentPageIndex = _scroller.HorizontalPageIndex;
if (previousPageIndex != CurrentPageIndex)
{
PageScrolled?.Invoke(this, new PageScrolledEventArgs(previousPageIndex, CurrentPageIndex));
OnSelect(CurrentPageIndex);
}
}
}
}
58 changes: 58 additions & 0 deletions src/Tizen.UIExtensions.ElmSharp/DateTimePicker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using ElmSharp;

namespace Tizen.UIExtensions.ElmSharp
{
public enum DateTimePickerMode
{
Date,
Time
}

public class DateTimePicker : DateTimeSelector
{
const string TimeFormat = "%d/%b/%Y %I:%M %p";
const string TimeLayoutStyle = "time_layout";

const string DateFormat = "%d/%b/%Y";
const string DateLayoutStyle = "date_layout";

DateTimePickerMode _mode = DateTimePickerMode.Date;

public DateTimePicker(EvasObject parent) : base(parent)
{
UpdateMode();
}

protected DateTimePicker() : base()
{
}

public DateTimePickerMode Mode
{
get { return _mode; }
set
{
if (_mode != value)
{
_mode = value;
UpdateMode();
}
}
}

protected virtual void UpdateMode()
{
if (Mode == DateTimePickerMode.Date)
{
Style = DateLayoutStyle;
Format = DateFormat;
}
else
{
Style = TimeLayoutStyle;
Format = TimeFormat;
}
}
}
}
Loading

0 comments on commit 065bf7c

Please sign in to comment.