您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
195 行
5.7 KiB
195 行
5.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Unity.UIWidgets.foundation;
|
|
using Unity.UIWidgets.widgets;
|
|
|
|
namespace UIWidgetsGallery.gallery
|
|
{
|
|
public class GalleryDemoCategory
|
|
{
|
|
public GalleryDemoCategory(
|
|
string name,
|
|
IconData icon)
|
|
{
|
|
this.name = name;
|
|
this.icon = icon;
|
|
}
|
|
|
|
public readonly string name;
|
|
public readonly IconData icon;
|
|
|
|
public bool Equals(GalleryDemoCategory other)
|
|
{
|
|
if (ReferenceEquals(this, other))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (ReferenceEquals(other, null))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return this.icon.Equals(other.icon) && this.name == other.name;
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (ReferenceEquals(this, obj))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (ReferenceEquals(obj, null))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (obj.GetType() != GetType())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return Equals((GalleryDemoCategory)obj);
|
|
}
|
|
|
|
public static bool operator==(GalleryDemoCategory left, GalleryDemoCategory right)
|
|
{
|
|
return Equals(left, right);
|
|
}
|
|
|
|
public static bool operator !=(GalleryDemoCategory left, GalleryDemoCategory right)
|
|
{
|
|
return !Equals(left, right);
|
|
}
|
|
|
|
public override int GetHashCode() {
|
|
unchecked {
|
|
return ((icon?.GetHashCode() ?? 0) * 397) ^ (name?.GetHashCode() ?? 0);
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{GetType()}{name}";
|
|
}
|
|
|
|
public static readonly GalleryDemoCategory _kDemos = new GalleryDemoCategory(
|
|
name: "Studies",
|
|
icon: GalleryIcons.animation
|
|
);
|
|
|
|
public static readonly GalleryDemoCategory _kStyle = new GalleryDemoCategory(
|
|
name: "Style",
|
|
icon: GalleryIcons.custom_typography
|
|
);
|
|
|
|
public static readonly GalleryDemoCategory _kMaterialComponents = new GalleryDemoCategory(
|
|
name: "Material",
|
|
icon: GalleryIcons.category_mdc
|
|
);
|
|
|
|
public static readonly GalleryDemoCategory _kCupertinoComponents = new GalleryDemoCategory(
|
|
name: "Cupertino",
|
|
icon: GalleryIcons.phone_iphone
|
|
);
|
|
|
|
public static readonly GalleryDemoCategory _kMedia = new GalleryDemoCategory(
|
|
name: "Media",
|
|
icon: GalleryIcons.drive_video
|
|
);
|
|
}
|
|
|
|
class GalleryDemo {
|
|
public GalleryDemo(
|
|
string title = null,
|
|
IconData icon = null,
|
|
string subtitle = null,
|
|
GalleryDemoCategory category = null,
|
|
string routeName = null,
|
|
string documentationUrl = null,
|
|
WidgetBuilder buildRoute = null
|
|
)
|
|
{
|
|
D.assert(title != null);
|
|
D.assert(category != null);
|
|
D.assert(routeName != null);
|
|
D.assert(buildRoute != null);
|
|
|
|
this.title = title;
|
|
this.icon = icon;
|
|
this.subtitle = subtitle;
|
|
this.category = category;
|
|
this.routeName = routeName;
|
|
this.documentationUrl = documentationUrl;
|
|
this.buildRoute = buildRoute;
|
|
}
|
|
|
|
public readonly string title;
|
|
public readonly IconData icon;
|
|
public readonly string subtitle;
|
|
public readonly GalleryDemoCategory category;
|
|
public readonly string routeName;
|
|
public readonly WidgetBuilder buildRoute;
|
|
public readonly string documentationUrl;
|
|
|
|
public override string ToString() {
|
|
return $"{GetType()}({title} {routeName})";
|
|
}
|
|
|
|
public static List<GalleryDemo> _buildGalleryDemos()
|
|
{
|
|
List<GalleryDemo> galleryDemos = new List<GalleryDemo>
|
|
{
|
|
|
|
};
|
|
|
|
return galleryDemos;
|
|
}
|
|
|
|
public static readonly List<GalleryDemo> kAllGalleryDemos = _buildGalleryDemos();
|
|
|
|
public static readonly List<GalleryDemoCategory> kAllGalleryDemoCategories =
|
|
kAllGalleryDemos.Select<GalleryDemo, GalleryDemoCategory>((GalleryDemo demo) => demo.category).ToList();
|
|
|
|
|
|
static Dictionary<GalleryDemoCategory, List<GalleryDemo>> _generateCategoryToDemos()
|
|
{
|
|
Dictionary<GalleryDemoCategory, List<GalleryDemo>> result =
|
|
new Dictionary<GalleryDemoCategory, List<GalleryDemo>>();
|
|
|
|
foreach (var category in kAllGalleryDemoCategories)
|
|
{
|
|
result.Add(category, kAllGalleryDemos.Where((GalleryDemo demo) =>
|
|
{
|
|
return demo.category == category;
|
|
}).ToList());
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public static readonly Dictionary<GalleryDemoCategory, List<GalleryDemo>> kGalleryCategoryToDemos =
|
|
_generateCategoryToDemos();
|
|
|
|
static Dictionary<string, string> _generateDemoDocumentationUrls()
|
|
{
|
|
Dictionary<string, string> result = new Dictionary<string, string>();
|
|
|
|
foreach (var demo in kAllGalleryDemos)
|
|
{
|
|
if (demo.documentationUrl != null)
|
|
{
|
|
result.Add(demo.routeName, demo.documentationUrl);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public static readonly Dictionary<string, string> kDemoDocumentationUrl = _generateDemoDocumentationUrls();
|
|
}
|
|
|
|
|
|
}
|