Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
81 changes: 81 additions & 0 deletions src/Tizen.NET.MaterialComponents/Components/MList.cs
Original file line number Diff line number Diff line change
@@ -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<WeakReference> _realizedItems = new List<WeakReference>();
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);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Tizen.NET.MaterialComponents
{
public class MListTripleLineItemClass : MListDoubleLineItemClass
{
public MListTripleLineItemClass() : base(Styles.GenListItem.MaterialTripleLine)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 6 additions & 0 deletions src/Tizen.NET.MaterialComponents/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
122 changes: 122 additions & 0 deletions test/MaterialGallery/Gallery/MListPage.cs
Original file line number Diff line number Diff line change
@@ -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;
}

}
}