diff --git a/README.md b/README.md index c643e7e..9a06fc7 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,9 @@ Material Components for Tizen .NET help developers execute [Material Design](htt - **MFullScreenDialog** A full-screen dialogs group a series of tasks.([guideline](https://material.io/design/components/dialogs.html#full-screen-dialog)) +- **MLists** + A material Lists are continuous, vertical indexes of text or images. ([guideline](https://material.io/design/components/lists.html#)) + - **MMenus** A material menus display a list of choices on temporary surfaces. ([guideline](https://material.io/design/components/menus.html)) diff --git a/src/Tizen.NET.MaterialComponents/Components/MList.cs b/src/Tizen.NET.MaterialComponents/Components/MList.cs new file mode 100644 index 0000000..75400a5 --- /dev/null +++ b/src/Tizen.NET.MaterialComponents/Components/MList.cs @@ -0,0 +1,81 @@ +using ElmSharp; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Tizen.NET.MaterialComponents +{ + public class MList : GenList, IColorSchemeComponent + { + IList _realizedItems = new List(); + Color _oldDefaultBackgroundColor; + Color _oldDefaultTextColor; + + public MList(EvasObject parent) : base(parent) + { + MColors.AddColorSchemeComponent(this); + ItemRealized += OnItemRealized; + Deleted += OnDeleted; + } + + public void OnColorSchemeChanged(bool fromConstructor) + { + foreach (var obj in _realizedItems) + { + if (obj.Target is GenItem item) + { + UpdateItemColor(item, fromConstructor); + } + } + + _oldDefaultBackgroundColor = MColors.Current.SurfaceColor; + _oldDefaultTextColor = MColors.Current.OnSurfaceColor; + } + + protected void OnItemRealized(object sender, GenListItemEventArgs e) + { + if (!(_realizedItems.Any(i=>i.Target == e.Item))) + { + _realizedItems.Add(new WeakReference(e.Item)); + UpdateItemColor(e.Item, true); + } + } + + protected void OnDeleted(object sender, EventArgs e) + { + _realizedItems.Clear(); + } + + void UpdateItemColor(GenItem item, bool fromConstructor) + { + var defaultBackgroundColor = fromConstructor ? Color.Transparent : _oldDefaultBackgroundColor; + var defaultTextColor = fromConstructor ? Color.Transparent : _oldDefaultTextColor; + + var itemBackgroundColor = item.GetPartColor(Parts.Widget.Background); + var itemTextColor = item.GetPartColor(Parts.Widget.Text); + + if (itemBackgroundColor == defaultBackgroundColor) + { + item.SetPartColor(Parts.Widget.Background, MColors.Current.SurfaceColor); + item.SetPartColor(Parts.Widget.BackgroundPressed, MColors.Current.PrimaryColor.WithAlpha(0.12)); + item.SetPartColor(Parts.Widget.BackgroundDisabled, MColors.Current.SurfaceColor.WithAlpha(0.32)); + } + else + { + item.SetPartColor(Parts.Widget.BackgroundPressed, itemBackgroundColor.WithAlpha(0.12)); + item.SetPartColor(Parts.Widget.BackgroundDisabled, itemBackgroundColor.WithAlpha(0.32)); + } + + if (itemTextColor == defaultTextColor) + { + item.SetPartColor(Parts.Widget.Text, MColors.Current.OnSurfaceColor); + item.SetPartColor(Parts.Widget.TextPressed, MColors.Current.PrimaryColor); + } + else + { + item.SetPartColor(Parts.Widget.TextPressed, itemTextColor); + } + + } + } +} diff --git a/src/Tizen.NET.MaterialComponents/Components/MListDoubleLineItemClass.cs b/src/Tizen.NET.MaterialComponents/Components/MListDoubleLineItemClass.cs new file mode 100644 index 0000000..6c050b6 --- /dev/null +++ b/src/Tizen.NET.MaterialComponents/Components/MListDoubleLineItemClass.cs @@ -0,0 +1,31 @@ +namespace Tizen.NET.MaterialComponents +{ + public class MListDoubleLineItemClass : MListSingleLineItemClass + { + public new GetTextDelegate GetTextHandler { get; set; } + public GetTextDelegate GetSubTextHandler { get; set; } + + public MListDoubleLineItemClass() : this(Styles.GenListItem.MaterialDoubleLine) + { + } + + protected MListDoubleLineItemClass(string style) : base(style) + { + base.GetTextHandler = GetTextCallback; + } + + private string GetTextCallback(object data, string part) + { + if (part == Parts.GenListItem.Text) + { + return GetTextHandler?.Invoke(data, part); + } + else if (part == Parts.GenListItem.SubText) + { + return GetSubTextHandler?.Invoke(data, part); + } + + return null; + } + } +} diff --git a/src/Tizen.NET.MaterialComponents/Components/MListSingleLineItemClass.cs b/src/Tizen.NET.MaterialComponents/Components/MListSingleLineItemClass.cs new file mode 100644 index 0000000..32d63d6 --- /dev/null +++ b/src/Tizen.NET.MaterialComponents/Components/MListSingleLineItemClass.cs @@ -0,0 +1,34 @@ +using ElmSharp; + +namespace Tizen.NET.MaterialComponents +{ + public class MListSingleLineItemClass : GenItemClass + { + public GetContentDelegate GetIconHandler { get; set; } + public GetContentDelegate GetMetaControlHandler { get; set; } + public new GetContentDelegate GetContentHandler { get; set; } + + public MListSingleLineItemClass() : this(Styles.GenListItem.MaterialSingleLine) + { + } + + protected MListSingleLineItemClass(string style) : base(style) + { + base.GetContentHandler = GetContentCallback; + } + + private EvasObject GetContentCallback(object data, string part) + { + if (part == Parts.GenListItem.Icon) + { + return GetIconHandler?.Invoke(data, part); + } + else if (part == Parts.GenListItem.MetaControl) + { + return GetMetaControlHandler?.Invoke(data, part); + } + + return GetContentHandler?.Invoke(data, part); + } + } +} diff --git a/src/Tizen.NET.MaterialComponents/Components/MListTripleLineItemClass.cs b/src/Tizen.NET.MaterialComponents/Components/MListTripleLineItemClass.cs new file mode 100644 index 0000000..d51db1f --- /dev/null +++ b/src/Tizen.NET.MaterialComponents/Components/MListTripleLineItemClass.cs @@ -0,0 +1,9 @@ +namespace Tizen.NET.MaterialComponents +{ + public class MListTripleLineItemClass : MListDoubleLineItemClass + { + public MListTripleLineItemClass() : base(Styles.GenListItem.MaterialTripleLine) + { + } + } +} diff --git a/src/Tizen.NET.MaterialComponents/Components/MaterialColors.cs b/src/Tizen.NET.MaterialComponents/Components/MaterialColors.cs index eab6791..ad1f05a 100644 --- a/src/Tizen.NET.MaterialComponents/Components/MaterialColors.cs +++ b/src/Tizen.NET.MaterialComponents/Components/MaterialColors.cs @@ -99,7 +99,7 @@ class DarkMColors : MColors public override Color BackgroundColor { get; } = Color.FromHex("#141414"); public override Color OnBackgroundColor { get; } = Color.FromHex("#FFFFFF"); - public override Color SurfaceColor { get; } = Color.FromHex("#282828"); + public override Color SurfaceColor { get; } = Color.FromHex("#484848"); public override Color OnSurfaceColor { get; } = Color.FromHex("#FFFFFF"); public override Color ErrorColor { get; } = Color.FromHex("#C26C7A"); public override Color OnErrorColor { get; } = Color.FromHex("#FFFFFF"); diff --git a/src/Tizen.NET.MaterialComponents/Constants.cs b/src/Tizen.NET.MaterialComponents/Constants.cs index d0ab67a..97a63ec 100644 --- a/src/Tizen.NET.MaterialComponents/Constants.cs +++ b/src/Tizen.NET.MaterialComponents/Constants.cs @@ -37,6 +37,9 @@ public class GenListItem public static readonly string MaterialNavigation = "material_navigation"; public static readonly string MaterialNavigationSubtitle = "material_navigation_subtitle"; public static readonly string MaterialNavigationDivider = "material_navigation_divider"; + public static readonly string MaterialSingleLine = "material_1line"; + public static readonly string MaterialDoubleLine = "material_2line"; + public static readonly string MaterialTripleLine = "material_3line"; } public class Popup @@ -121,6 +124,9 @@ public class GenListItem { public static readonly string BackgroundActivated = "active_bg"; public static readonly string Icon = "elm.swallow.icon"; + public static readonly string Text = "elm.text"; + public static readonly string SubText = "elm.text.sub"; + public static readonly string MetaControl = "elm.swallow.end"; } public class ProgressBar diff --git a/test/MaterialGallery/Gallery/MListPage.cs b/test/MaterialGallery/Gallery/MListPage.cs new file mode 100644 index 0000000..e112c30 --- /dev/null +++ b/test/MaterialGallery/Gallery/MListPage.cs @@ -0,0 +1,122 @@ +using ElmSharp; +using System; +using System.IO; +using Tizen.NET.MaterialComponents; + +namespace MaterialGallery +{ + class MListPage : BaseGalleryPage + { + public override string Name => "MListPage Gallery"; + + public override EvasObject CreateContent(EvasObject parent) + { + Box box = new ColoredBox(parent); + box.Show(); + + var list = new MList(parent) + { + WeightX = 1, + WeightY = 1, + AlignmentX = -1, + AlignmentY = -1 + }; + list.Show(); + + var singleItemClass = new MListSingleLineItemClass + { + GetTextHandler = (obj, part) => + { + return obj.ToString(); + }, + GetIconHandler = (obj, part) => + { + var icon = new Image(parent) + { + MinimumHeight = 80, + MinimumWidth = 80 + }; + icon.Load(Path.Combine(MaterialGallery.ResourceDir, "image.png")); + return icon; + }, + GetMetaControlHandler = (obj, part) => + { + return new MCheckBox(parent); + }, + }; + + var doubleItemClass = new MListDoubleLineItemClass + { + GetTextHandler = (obj, part) => + { + return obj.ToString(); + }, + GetSubTextHandler = (obj, part) => + { + return "sub text"; + }, + GetIconHandler = (obj, part) => + { + var icon = new Image(parent) + { + MinimumHeight = 80, + MinimumWidth = 80 + }; + icon.Load(Path.Combine(MaterialGallery.ResourceDir, "image.png")); + return icon; + }, + GetMetaControlHandler = (obj, part) => + { + return new MCheckBox(parent); + }, + }; + + var tripleItemClass = new MListTripleLineItemClass + { + GetTextHandler = (obj, part) => + { + return obj.ToString(); + }, + GetSubTextHandler = (obj, part) => + { + return "sub text and a too loooooooooooooooooooooooooooong text"; + }, + GetIconHandler = (obj, part) => + { + var icon = new Image(parent) + { + MinimumHeight = 80, + MinimumWidth = 80 + }; + icon.Load(Path.Combine(MaterialGallery.ResourceDir, "image.png")); + return icon; + }, + GetMetaControlHandler = (obj, part) => + { + return new MCheckBox(parent); + }, + }; + + + for (int i = 0; i < 20; i ++) + { + if (i % 3 == 0) + { + list.Append(singleItemClass, String.Format("Item_{0}", i)); + } + else if (i % 3 == 1) + { + list.Append(doubleItemClass, String.Format("Item_{0}", i)); + } + else if (i % 3 == 2) + { + list.Append(tripleItemClass, String.Format("Item_{0}", i)); + } + } + + box.PackEnd(list); + return box; + } + + } +}