* UIFontImages: 重写字体图标编辑器,优化打开速度

This commit is contained in:
Sunny 2023-11-26 11:48:02 +08:00
parent 5c2068875e
commit 16494fe74f
4 changed files with 237 additions and 396 deletions

View File

@ -22,13 +22,9 @@
******************************************************************************/
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace Sunny.UI
@ -38,13 +34,14 @@ namespace Sunny.UI
/// </summary>
internal partial class UIFontImages : Form, ISymbol
{
private readonly ConcurrentQueue<Label> FontAwesomeV4Labels = new ConcurrentQueue<Label>();
private readonly ConcurrentQueue<Label> ElegantIconsLabels = new ConcurrentQueue<Label>();
private readonly ConcurrentQueue<Label> FontAwesomeV6SolidLabels = new ConcurrentQueue<Label>();
private readonly ConcurrentQueue<Label> FontAwesomeV6BrandsLabels = new ConcurrentQueue<Label>();
private readonly ConcurrentQueue<Label> FontAwesomeV6RegularLabels = new ConcurrentQueue<Label>();
private readonly ConcurrentQueue<Label> MaterialIconsLabels = new ConcurrentQueue<Label>();
private readonly ConcurrentQueue<Label> SearchLabels = new ConcurrentQueue<Label>();
private static UISymbolPanel customSymbolPanel;
private static UISymbolPanel fontAwesomeV4;
private static UISymbolPanel elegantIcons;
private static UISymbolPanel fontAweSomeV6Regular;
private static UISymbolPanel fontAweSomeV6Solid;
private static UISymbolPanel fontAweSomeV6Brands;
private static UISymbolPanel materialIcons;
private static UISymbolPanel searchSymbolPanel;
/// <summary>
/// 构造函数
@ -59,247 +56,141 @@ namespace Sunny.UI
lpV6Regular.DoubleBuffered();
lpV6Solid.DoubleBuffered();
lpMaterialIcons.DoubleBuffered();
customSymbolPanel = new UISymbolPanel();
fontAwesomeV4 = new UISymbolPanel(typeof(FontAwesomeIcons), UISymbolType.FontAwesomeV4);
elegantIcons = new UISymbolPanel(typeof(FontElegantIcons), UISymbolType.FontAwesomeV4);
fontAweSomeV6Regular = new UISymbolPanel(typeof(FontAweSomeV6Regular), UISymbolType.FontAwesomeV6Regular);
fontAweSomeV6Solid = new UISymbolPanel(typeof(FontAweSomeV6Solid), UISymbolType.FontAwesomeV6Solid);
fontAweSomeV6Brands = new UISymbolPanel(typeof(FontAweSomeV6Brands), UISymbolType.FontAwesomeV6Brands);
materialIcons = new UISymbolPanel(typeof(MaterialIcons), UISymbolType.MaterialIcons);
searchSymbolPanel = new UISymbolPanel();
customSymbolPanel.ValueChanged += CustomSymbolPanel_ValueChanged;
fontAwesomeV4.ValueChanged += CustomSymbolPanel_ValueChanged;
elegantIcons.ValueChanged += CustomSymbolPanel_ValueChanged;
fontAweSomeV6Brands.ValueChanged += CustomSymbolPanel_ValueChanged;
fontAweSomeV6Regular.ValueChanged += CustomSymbolPanel_ValueChanged;
fontAweSomeV6Solid.ValueChanged += CustomSymbolPanel_ValueChanged;
materialIcons.ValueChanged += CustomSymbolPanel_ValueChanged;
searchSymbolPanel.ValueChanged += CustomSymbolPanel_ValueChanged;
}
private void CustomSymbolPanel_ValueChanged(object sender, SymbolValue symbol)
{
SymbolType = symbol.SymbolType;
Symbol = ((int)symbol.SymbolType) * 100000 + symbol.Symbol;
DialogResult = DialogResult.OK;
Close();
}
private void UIFontImages_Load(object sender, EventArgs e)
{
AddHighFreqImage();
bg1.RunWorkerAsync();
bg2.RunWorkerAsync();
bg3.RunWorkerAsync();
bg4.RunWorkerAsync();
bg5.RunWorkerAsync();
bg6.RunWorkerAsync();
timer.Start();
}
private void timer_Tick(object sender, EventArgs e)
{
timer.Stop();
while (!FontAwesomeV4Labels.IsEmpty)
{
if (FontAwesomeV4Labels.TryDequeue(out Label lbl))
{
lpAwesome.Controls.Add(lbl);
SymbolValue symbol = (SymbolValue)lbl.Tag;
toolTip.SetToolTip(lbl, symbol.ToString());
}
}
while (!ElegantIconsLabels.IsEmpty)
{
if (ElegantIconsLabels.TryDequeue(out Label lbl))
{
lpElegant.Controls.Add(lbl);
SymbolValue symbol = (SymbolValue)lbl.Tag;
toolTip.SetToolTip(lbl, symbol.ToString());
}
}
while (!FontAwesomeV6SolidLabels.IsEmpty)
{
if (FontAwesomeV6SolidLabels.TryDequeue(out Label lbl))
{
lpV6Solid.Controls.Add(lbl);
SymbolValue symbol = (SymbolValue)lbl.Tag;
toolTip.SetToolTip(lbl, symbol.ToString());
}
}
while (!FontAwesomeV6RegularLabels.IsEmpty)
{
if (FontAwesomeV6RegularLabels.TryDequeue(out Label lbl))
{
lpV6Regular.Controls.Add(lbl);
SymbolValue symbol = (SymbolValue)lbl.Tag;
toolTip.SetToolTip(lbl, symbol.ToString());
}
}
while (!FontAwesomeV6BrandsLabels.IsEmpty)
{
if (FontAwesomeV6BrandsLabels.TryDequeue(out Label lbl))
{
lpV6Brands.Controls.Add(lbl);
SymbolValue symbol = (SymbolValue)lbl.Tag;
toolTip.SetToolTip(lbl, symbol.ToString());
}
}
while (!MaterialIconsLabels.IsEmpty)
{
if (MaterialIconsLabels.TryDequeue(out Label lbl))
{
lpMaterialIcons.Controls.Add(lbl);
SymbolValue symbol = (SymbolValue)lbl.Tag;
toolTip.SetToolTip(lbl, symbol.ToString());
}
}
timer.Start();
}
private void AddHighFreqImage()
{
AddLabel(FontAwesomeIcons.fa_check);
AddLabel(FontAwesomeIcons.fa_close);
customSymbolPanel.RowCount = 20;
AddLabel(FontAwesomeIcons.fa_check, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_close, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_ellipsis_h);
AddLabel(FontAwesomeIcons.fa_file);
AddLabel(FontAwesomeIcons.fa_file_o);
AddLabel(FontAwesomeIcons.fa_save);
AddLabel(FontAwesomeIcons.fa_folder);
AddLabel(FontAwesomeIcons.fa_folder_o);
AddLabel(FontAwesomeIcons.fa_folder_open);
AddLabel(FontAwesomeIcons.fa_folder_open_o);
AddLabel(FontAwesomeIcons.fa_ellipsis_h, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_file, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_file_o, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_save, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_folder, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_folder_o, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_folder_open, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_folder_open_o, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_plus);
AddLabel(FontAwesomeIcons.fa_edit);
AddLabel(FontAwesomeIcons.fa_minus);
AddLabel(FontAwesomeIcons.fa_refresh);
AddLabel(FontAwesomeIcons.fa_plus, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_edit, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_minus, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_refresh, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_exclamation);
AddLabel(FontAwesomeIcons.fa_exclamation_circle);
AddLabel(FontAwesomeIcons.fa_warning);
AddLabel(FontAwesomeIcons.fa_info);
AddLabel(FontAwesomeIcons.fa_exclamation, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_exclamation_circle, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_warning, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_info, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_info_circle);
AddLabel(FontAwesomeIcons.fa_check_circle);
AddLabel(FontAwesomeIcons.fa_check_circle_o);
AddLabel(FontAwesomeIcons.fa_times_circle);
AddLabel(FontAwesomeIcons.fa_times_circle_o);
AddLabel(FontAwesomeIcons.fa_question);
AddLabel(FontAwesomeIcons.fa_question_circle);
AddLabel(FontAwesomeIcons.fa_question_circle_o);
AddLabel(FontAwesomeIcons.fa_ban);
AddLabel(FontAwesomeIcons.fa_info_circle, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_check_circle, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_check_circle_o, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_times_circle, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_times_circle_o, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_question, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_question_circle, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_question_circle_o, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_ban, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_toggle_left);
AddLabel(FontAwesomeIcons.fa_toggle_right);
AddLabel(FontAwesomeIcons.fa_toggle_up);
AddLabel(FontAwesomeIcons.fa_toggle_down);
AddLabel(FontAwesomeIcons.fa_toggle_left, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_toggle_right, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_toggle_up, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_toggle_down, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_lock);
AddLabel(FontAwesomeIcons.fa_unlock);
AddLabel(FontAwesomeIcons.fa_unlock_alt);
AddLabel(FontAwesomeIcons.fa_lock, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_unlock, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_unlock_alt, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_cog);
AddLabel(FontAwesomeIcons.fa_cogs);
AddLabel(FontAwesomeIcons.fa_cog, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_cogs, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_window_minimize);
AddLabel(FontAwesomeIcons.fa_window_maximize);
AddLabel(FontAwesomeIcons.fa_window_restore);
AddLabel(FontAwesomeIcons.fa_window_close);
AddLabel(FontAwesomeIcons.fa_window_close_o);
AddLabel(FontAwesomeIcons.fa_window_minimize, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_window_maximize, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_window_restore, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_window_close, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_window_close_o, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_user);
AddLabel(FontAwesomeIcons.fa_user_o);
AddLabel(FontAwesomeIcons.fa_user_circle);
AddLabel(FontAwesomeIcons.fa_user_circle_o);
AddLabel(FontAwesomeIcons.fa_user_plus);
AddLabel(FontAwesomeIcons.fa_user_times);
AddLabel(FontAwesomeIcons.fa_user, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_user_o, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_user_circle, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_user_circle_o, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_user_plus, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_user_times, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_tag);
AddLabel(FontAwesomeIcons.fa_tags);
AddLabel(FontAwesomeIcons.fa_tag, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_tags, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_plus_circle);
AddLabel(FontAwesomeIcons.fa_plus_square);
AddLabel(FontAwesomeIcons.fa_plus_square_o);
AddLabel(FontAwesomeIcons.fa_plus_circle, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_plus_square, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_plus_square_o, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_minus_circle);
AddLabel(FontAwesomeIcons.fa_minus_square);
AddLabel(FontAwesomeIcons.fa_minus_square_o);
AddLabel(FontAwesomeIcons.fa_minus_circle, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_minus_square, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_minus_square_o, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_search);
AddLabel(FontAwesomeIcons.fa_search_minus);
AddLabel(FontAwesomeIcons.fa_search_plus);
AddLabel(FontAwesomeIcons.fa_search, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_search_minus, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_search_plus, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_bar_chart);
AddLabel(FontAwesomeIcons.fa_area_chart);
AddLabel(FontAwesomeIcons.fa_line_chart);
AddLabel(FontAwesomeIcons.fa_pie_chart);
AddLabel(FontAwesomeIcons.fa_photo);
AddLabel(FontAwesomeIcons.fa_bar_chart, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_area_chart, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_line_chart, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_pie_chart, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_photo, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_power_off);
AddLabel(FontAwesomeIcons.fa_print);
AddLabel(FontAwesomeIcons.fa_bars);
AddLabel(FontAwesomeIcons.fa_power_off, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_print, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_bars, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_sign_in);
AddLabel(FontAwesomeIcons.fa_sign_out);
AddLabel(FontAwesomeIcons.fa_sign_in, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_sign_out, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_play);
AddLabel(FontAwesomeIcons.fa_pause);
AddLabel(FontAwesomeIcons.fa_stop);
AddLabel(FontAwesomeIcons.fa_fast_backward);
AddLabel(FontAwesomeIcons.fa_backward);
AddLabel(FontAwesomeIcons.fa_forward);
AddLabel(FontAwesomeIcons.fa_fast_forward);
AddLabel(FontAwesomeIcons.fa_eject);
AddLabel(FontAwesomeIcons.fa_play, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_pause, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_stop, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_fast_backward, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_backward, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_forward, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_fast_forward, UISymbolType.FontAwesomeV4);
AddLabel(FontAwesomeIcons.fa_eject, UISymbolType.FontAwesomeV4);
customSymbolPanel.Invalidate();
}
private void AddLabel(int icon)
private void AddLabel(int icon, UISymbolType symbolType)
{
Label lbl = CreateLabel(icon, UISymbolType.FontAwesomeV4);
lpCustom.Controls.Add(lbl);
SymbolValue symbol = (SymbolValue)lbl.Tag;
toolTip.SetToolTip(lbl, symbol.ToString());
}
private Label CreateLabel(int icon, UISymbolType symbolType)
{
Label lbl = new Label
{
AutoSize = false,
Size = new Size(32, 32),
ForeColor = UIColor.Blue,
Image = FontImageHelper.CreateImage(icon + (int)symbolType * 100000, 28, UIFontColor.Primary),
ImageAlign = ContentAlignment.MiddleCenter,
TextAlign = ContentAlignment.MiddleLeft,
Margin = new Padding(2)
};
lbl.DoubleBuffered();
lbl.Click += lbl_DoubleClick;
lbl.MouseEnter += Lbl_MouseEnter;
lbl.MouseLeave += Lbl_MouseLeave;
lbl.Tag = new SymbolValue() { Symbol = icon, SymbolType = symbolType };
return lbl;
}
private Label CreateLabel(string name, int icon, UISymbolType symbolType)
{
Label lbl = new Label
{
AutoSize = false,
Size = new Size(32, 32),
ForeColor = UIColor.Blue,
Image = FontImageHelper.CreateImage(icon + (int)symbolType * 100000, 28, UIFontColor.Primary),
ImageAlign = ContentAlignment.MiddleCenter,
TextAlign = ContentAlignment.MiddleLeft,
Margin = new Padding(2)
};
lbl.Click += lbl_DoubleClick;
lbl.MouseEnter += Lbl_MouseEnter;
lbl.MouseLeave += Lbl_MouseLeave;
lbl.Tag = new SymbolValue() { Name = name.Replace("fa_", "").Replace("ma_", ""), Symbol = icon, SymbolType = symbolType };
return lbl;
}
private void Lbl_MouseLeave(object sender, EventArgs e)
{
Label lbl = (Label)sender;
SymbolValue symbol = (SymbolValue)lbl.Tag;
if (symbol.IsRed) return;
lbl.Image = FontImageHelper.CreateImage(symbol.Symbol + (int)symbol.SymbolType * 100000, 28, UIFontColor.Primary);
}
private void Lbl_MouseEnter(object sender, EventArgs e)
{
Label lbl = (Label)sender;
SymbolValue symbol = (SymbolValue)lbl.Tag;
if (symbol.IsRed) return;
lbl.Image = FontImageHelper.CreateImage(symbol.Symbol + (int)symbol.SymbolType * 100000, 28, UIColor.Blue);
customSymbolPanel.Add(new SymbolValue(icon, "", symbolType));
}
/// <summary>
@ -324,105 +215,74 @@ namespace Sunny.UI
/// </summary>
public int SymbolRotate { get; set; } = 0;
private void lbl_DoubleClick(object sender, EventArgs e)
{
if (sender is Label lbl)
{
SymbolValue symbol = (SymbolValue)lbl.Tag;
SymbolType = symbol.SymbolType;
Symbol = ((int)symbol.SymbolType) * 100000 + symbol.Symbol;
DialogResult = DialogResult.OK;
Close();
}
}
private void LoadLabels(Type type, ConcurrentQueue<Label> labels, UISymbolType symbolType, string filter = "")
{
ConcurrentDictionary<int, FieldInfo> dic = new ConcurrentDictionary<int, FieldInfo>();
foreach (var fieldInfo in type.GetFields())
{
var obj = fieldInfo.GetRawConstantValue();
if (obj is int value)
{
dic.TryAdd(value, fieldInfo);
}
}
List<int> list = dic.Keys.ToList();
list.Sort();
foreach (var value in list)
{
if (filter == "")
labels.Enqueue(CreateLabel(dic[value].Name, value, symbolType));
else if (dic[value].Name.ToUpper().Contains(filter.ToUpper()))
labels.Enqueue(CreateLabel(dic[value].Name, value, symbolType));
}
dic.Clear();
}
private void bg_DoWork(object sender, DoWorkEventArgs e)
{
//public const int FontAwesomeV4Count = 786;
LoadLabels(typeof(FontAwesomeIcons), FontAwesomeV4Labels, UISymbolType.FontAwesomeV4);
}
private void bg2_DoWork(object sender, DoWorkEventArgs e)
{
//public const int ElegantIconsCount = 360;
LoadLabels(typeof(FontElegantIcons), ElegantIconsLabels, UISymbolType.FontAwesomeV4);
}
private void bg3_DoWork(object sender, DoWorkEventArgs e)
{
LoadLabels(typeof(FontAweSomeV6Brands), FontAwesomeV6BrandsLabels, UISymbolType.FontAwesomeV6Brands);
}
private void bg4_DoWork(object sender, DoWorkEventArgs e)
{
LoadLabels(typeof(FontAweSomeV6Regular), FontAwesomeV6RegularLabels, UISymbolType.FontAwesomeV6Regular);
}
private void bg5_DoWork(object sender, DoWorkEventArgs e)
{
LoadLabels(typeof(FontAweSomeV6Solid), FontAwesomeV6SolidLabels, UISymbolType.FontAwesomeV6Solid);
}
private void bg6_DoWork(object sender, DoWorkEventArgs e)
{
LoadLabels(typeof(MaterialIcons), MaterialIconsLabels, UISymbolType.MaterialIcons);
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.IsNullOrEmpty()) return;
lblResult.Controls.Clear();
SearchLabels.Clear();
string filter = textBox1.Text.Trim();
fontAwesomeV4.Filter = filter;
elegantIcons.Filter = filter;
fontAweSomeV6Regular.Filter = filter;
fontAweSomeV6Solid.Filter = filter;
fontAweSomeV6Brands.Filter = filter;
materialIcons.Filter = filter;
searchSymbolPanel.Clear();
if (filter.IsNullOrEmpty()) return;
LoadLabels(typeof(FontAwesomeIcons), SearchLabels, UISymbolType.FontAwesomeV4, textBox1.Text);
LoadLabels(typeof(FontElegantIcons), SearchLabels, UISymbolType.FontAwesomeV4, textBox1.Text);
LoadLabels(typeof(FontAweSomeV6Brands), SearchLabels, UISymbolType.FontAwesomeV6Brands, textBox1.Text);
LoadLabels(typeof(FontAweSomeV6Regular), SearchLabels, UISymbolType.FontAwesomeV6Regular, textBox1.Text);
LoadLabels(typeof(FontAweSomeV6Solid), SearchLabels, UISymbolType.FontAwesomeV6Solid, textBox1.Text);
LoadLabels(typeof(MaterialIcons), SearchLabels, UISymbolType.MaterialIcons, textBox1.Text);
label1.Text = SearchLabels.Count + " results.";
while (!SearchLabels.IsEmpty)
for (int i = 0; i < fontAwesomeV4.SymbolCount; i++)
{
if (SearchLabels.TryDequeue(out Label lbl))
{
lblResult.Controls.Add(lbl);
SymbolValue symbol = (SymbolValue)lbl.Tag;
toolTip.SetToolTip(lbl, symbol.ToString());
}
var value = fontAwesomeV4.Get(i);
if (value.Name.ToUpper().Contains(filter.ToUpper()))
searchSymbolPanel.Add(value);
}
for (int i = 0; i < elegantIcons.SymbolCount; i++)
{
var value = elegantIcons.Get(i);
if (value.Name.ToUpper().Contains(filter.ToUpper()))
searchSymbolPanel.Add(value);
}
for (int i = 0; i < fontAweSomeV6Regular.SymbolCount; i++)
{
var value = fontAweSomeV6Regular.Get(i);
if (value.Name.ToUpper().Contains(filter.ToUpper()))
searchSymbolPanel.Add(value);
}
for (int i = 0; i < fontAweSomeV6Solid.SymbolCount; i++)
{
var value = fontAweSomeV6Solid.Get(i);
if (value.Name.ToUpper().Contains(filter.ToUpper()))
searchSymbolPanel.Add(value);
}
for (int i = 0; i < fontAweSomeV6Brands.SymbolCount; i++)
{
var value = fontAweSomeV6Brands.Get(i);
if (value.Name.ToUpper().Contains(filter.ToUpper()))
searchSymbolPanel.Add(value);
}
for (int i = 0; i < materialIcons.SymbolCount; i++)
{
var value = materialIcons.Get(i);
if (value.Name.ToUpper().Contains(filter.ToUpper()))
searchSymbolPanel.Add(value);
}
searchSymbolPanel.Invalidate();
tabControl1.SelectedTab = tabPage7;
}
private void UIFontImages_Shown(object sender, EventArgs e)
{
lpCustom.Controls.Add(customSymbolPanel);
lpV6Solid.Controls.Add(fontAweSomeV6Solid);
lpV6Regular.Controls.Add(fontAweSomeV6Regular);
lpV6Brands.Controls.Add(fontAweSomeV6Brands);
lpElegant.Controls.Add(elegantIcons);
lpMaterialIcons.Controls.Add(materialIcons);
lblResult.Controls.Add(searchSymbolPanel);
lpAwesome.Controls.Add(fontAwesomeV4);
textBox1.Focus();
}

View File

@ -46,19 +46,12 @@
lpMaterialIcons = new System.Windows.Forms.FlowLayoutPanel();
tabPage7 = new System.Windows.Forms.TabPage();
lblResult = new System.Windows.Forms.FlowLayoutPanel();
bg1 = new System.ComponentModel.BackgroundWorker();
timer = new System.Windows.Forms.Timer(components);
toolTip = new System.Windows.Forms.ToolTip(components);
bg2 = new System.ComponentModel.BackgroundWorker();
bg3 = new System.ComponentModel.BackgroundWorker();
bg4 = new System.ComponentModel.BackgroundWorker();
bg5 = new System.ComponentModel.BackgroundWorker();
panel1 = new System.Windows.Forms.Panel();
label2 = new System.Windows.Forms.Label();
label1 = new System.Windows.Forms.Label();
button1 = new System.Windows.Forms.Button();
textBox1 = new System.Windows.Forms.TextBox();
bg6 = new System.ComponentModel.BackgroundWorker();
tabControl1.SuspendLayout();
tabPage1.SuspendLayout();
tabPage5.SuspendLayout();
@ -86,7 +79,7 @@
tabControl1.Location = new System.Drawing.Point(0, 81);
tabControl1.Name = "tabControl1";
tabControl1.SelectedIndex = 0;
tabControl1.Size = new System.Drawing.Size(900, 610);
tabControl1.Size = new System.Drawing.Size(820, 600);
tabControl1.TabIndex = 0;
//
// tabPage1
@ -95,7 +88,7 @@
tabPage1.Location = new System.Drawing.Point(4, 28);
tabPage1.Name = "tabPage1";
tabPage1.Padding = new System.Windows.Forms.Padding(3);
tabPage1.Size = new System.Drawing.Size(892, 578);
tabPage1.Size = new System.Drawing.Size(812, 568);
tabPage1.TabIndex = 0;
tabPage1.Text = "Custom";
tabPage1.UseVisualStyleBackColor = true;
@ -106,7 +99,7 @@
lpCustom.Dock = System.Windows.Forms.DockStyle.Fill;
lpCustom.Location = new System.Drawing.Point(3, 3);
lpCustom.Name = "lpCustom";
lpCustom.Size = new System.Drawing.Size(886, 572);
lpCustom.Size = new System.Drawing.Size(806, 562);
lpCustom.TabIndex = 1;
//
// tabPage5
@ -115,7 +108,7 @@
tabPage5.Location = new System.Drawing.Point(4, 28);
tabPage5.Name = "tabPage5";
tabPage5.Padding = new System.Windows.Forms.Padding(3);
tabPage5.Size = new System.Drawing.Size(892, 578);
tabPage5.Size = new System.Drawing.Size(806, 568);
tabPage5.TabIndex = 4;
tabPage5.Text = "FontAwesome V6 Solid";
tabPage5.UseVisualStyleBackColor = true;
@ -127,7 +120,7 @@
lpV6Solid.ForeColor = System.Drawing.Color.FromArgb(64, 158, 255);
lpV6Solid.Location = new System.Drawing.Point(3, 3);
lpV6Solid.Name = "lpV6Solid";
lpV6Solid.Size = new System.Drawing.Size(886, 572);
lpV6Solid.Size = new System.Drawing.Size(800, 562);
lpV6Solid.TabIndex = 3;
//
// tabPage6
@ -136,7 +129,7 @@
tabPage6.Location = new System.Drawing.Point(4, 28);
tabPage6.Name = "tabPage6";
tabPage6.Padding = new System.Windows.Forms.Padding(3);
tabPage6.Size = new System.Drawing.Size(892, 578);
tabPage6.Size = new System.Drawing.Size(806, 568);
tabPage6.TabIndex = 5;
tabPage6.Text = "V6 Regular";
tabPage6.UseVisualStyleBackColor = true;
@ -148,7 +141,7 @@
lpV6Regular.ForeColor = System.Drawing.Color.FromArgb(64, 158, 255);
lpV6Regular.Location = new System.Drawing.Point(3, 3);
lpV6Regular.Name = "lpV6Regular";
lpV6Regular.Size = new System.Drawing.Size(886, 572);
lpV6Regular.Size = new System.Drawing.Size(800, 562);
lpV6Regular.TabIndex = 3;
//
// tabPage4
@ -157,7 +150,7 @@
tabPage4.Location = new System.Drawing.Point(4, 28);
tabPage4.Name = "tabPage4";
tabPage4.Padding = new System.Windows.Forms.Padding(3);
tabPage4.Size = new System.Drawing.Size(892, 578);
tabPage4.Size = new System.Drawing.Size(806, 568);
tabPage4.TabIndex = 3;
tabPage4.Text = "V6 Brands";
tabPage4.UseVisualStyleBackColor = true;
@ -169,7 +162,7 @@
lpV6Brands.ForeColor = System.Drawing.Color.FromArgb(64, 158, 255);
lpV6Brands.Location = new System.Drawing.Point(3, 3);
lpV6Brands.Name = "lpV6Brands";
lpV6Brands.Size = new System.Drawing.Size(886, 572);
lpV6Brands.Size = new System.Drawing.Size(800, 562);
lpV6Brands.TabIndex = 3;
//
// tabPage2
@ -178,7 +171,7 @@
tabPage2.Location = new System.Drawing.Point(4, 28);
tabPage2.Name = "tabPage2";
tabPage2.Padding = new System.Windows.Forms.Padding(3);
tabPage2.Size = new System.Drawing.Size(892, 578);
tabPage2.Size = new System.Drawing.Size(806, 568);
tabPage2.TabIndex = 1;
tabPage2.Text = "FontAwesome V4";
tabPage2.UseVisualStyleBackColor = true;
@ -190,7 +183,7 @@
lpAwesome.ForeColor = System.Drawing.Color.FromArgb(64, 158, 255);
lpAwesome.Location = new System.Drawing.Point(3, 3);
lpAwesome.Name = "lpAwesome";
lpAwesome.Size = new System.Drawing.Size(886, 572);
lpAwesome.Size = new System.Drawing.Size(800, 562);
lpAwesome.TabIndex = 1;
//
// tabPage3
@ -199,7 +192,7 @@
tabPage3.Location = new System.Drawing.Point(4, 28);
tabPage3.Name = "tabPage3";
tabPage3.Padding = new System.Windows.Forms.Padding(3);
tabPage3.Size = new System.Drawing.Size(892, 578);
tabPage3.Size = new System.Drawing.Size(806, 568);
tabPage3.TabIndex = 2;
tabPage3.Text = "ElegantIcons";
tabPage3.UseVisualStyleBackColor = true;
@ -211,7 +204,7 @@
lpElegant.ForeColor = System.Drawing.Color.FromArgb(64, 158, 255);
lpElegant.Location = new System.Drawing.Point(3, 3);
lpElegant.Name = "lpElegant";
lpElegant.Size = new System.Drawing.Size(886, 572);
lpElegant.Size = new System.Drawing.Size(800, 562);
lpElegant.TabIndex = 2;
//
// tsMaterialIcons
@ -220,7 +213,7 @@
tsMaterialIcons.Location = new System.Drawing.Point(4, 28);
tsMaterialIcons.Name = "tsMaterialIcons";
tsMaterialIcons.Padding = new System.Windows.Forms.Padding(3);
tsMaterialIcons.Size = new System.Drawing.Size(892, 578);
tsMaterialIcons.Size = new System.Drawing.Size(806, 568);
tsMaterialIcons.TabIndex = 7;
tsMaterialIcons.Text = "MaterialIcons";
tsMaterialIcons.UseVisualStyleBackColor = true;
@ -232,7 +225,7 @@
lpMaterialIcons.ForeColor = System.Drawing.Color.FromArgb(64, 158, 255);
lpMaterialIcons.Location = new System.Drawing.Point(3, 3);
lpMaterialIcons.Name = "lpMaterialIcons";
lpMaterialIcons.Size = new System.Drawing.Size(886, 572);
lpMaterialIcons.Size = new System.Drawing.Size(800, 562);
lpMaterialIcons.TabIndex = 3;
//
// tabPage7
@ -241,7 +234,7 @@
tabPage7.Location = new System.Drawing.Point(4, 28);
tabPage7.Name = "tabPage7";
tabPage7.Padding = new System.Windows.Forms.Padding(3);
tabPage7.Size = new System.Drawing.Size(892, 578);
tabPage7.Size = new System.Drawing.Size(806, 568);
tabPage7.TabIndex = 6;
tabPage7.Text = "Search result";
tabPage7.UseVisualStyleBackColor = true;
@ -253,33 +246,9 @@
lblResult.ForeColor = System.Drawing.Color.FromArgb(64, 158, 255);
lblResult.Location = new System.Drawing.Point(3, 3);
lblResult.Name = "lblResult";
lblResult.Size = new System.Drawing.Size(886, 572);
lblResult.Size = new System.Drawing.Size(800, 562);
lblResult.TabIndex = 3;
//
// bg1
//
bg1.DoWork += bg_DoWork;
//
// timer
//
timer.Tick += timer_Tick;
//
// bg2
//
bg2.DoWork += bg2_DoWork;
//
// bg3
//
bg3.DoWork += bg3_DoWork;
//
// bg4
//
bg4.DoWork += bg4_DoWork;
//
// bg5
//
bg5.DoWork += bg5_DoWork;
//
// panel1
//
panel1.Controls.Add(label2);
@ -289,7 +258,7 @@
panel1.Dock = System.Windows.Forms.DockStyle.Top;
panel1.Location = new System.Drawing.Point(0, 0);
panel1.Name = "panel1";
panel1.Size = new System.Drawing.Size(900, 81);
panel1.Size = new System.Drawing.Size(820, 81);
panel1.TabIndex = 0;
//
// label2
@ -334,14 +303,10 @@
textBox1.TabIndex = 0;
textBox1.KeyDown += textBox1_KeyDown;
//
// bg6
//
bg6.DoWork += bg6_DoWork;
//
// UIFontImages
//
AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
ClientSize = new System.Drawing.Size(900, 691);
ClientSize = new System.Drawing.Size(820, 681);
Controls.Add(tabControl1);
Controls.Add(panel1);
Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
@ -373,8 +338,6 @@
private System.Windows.Forms.FlowLayoutPanel lpAwesome;
private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.FlowLayoutPanel lpElegant;
private System.ComponentModel.BackgroundWorker bg1;
private System.Windows.Forms.Timer timer;
private System.Windows.Forms.ToolTip toolTip;
private System.Windows.Forms.TabPage tabPage4;
private System.Windows.Forms.TabPage tabPage5;
@ -382,10 +345,6 @@
private System.Windows.Forms.FlowLayoutPanel lpV6Brands;
private System.Windows.Forms.FlowLayoutPanel lpV6Solid;
private System.Windows.Forms.FlowLayoutPanel lpV6Regular;
private System.ComponentModel.BackgroundWorker bg2;
private System.ComponentModel.BackgroundWorker bg3;
private System.ComponentModel.BackgroundWorker bg4;
private System.ComponentModel.BackgroundWorker bg5;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
@ -423,6 +382,5 @@
*/
private System.Windows.Forms.TabPage tsMaterialIcons;
private System.Windows.Forms.FlowLayoutPanel lpMaterialIcons;
private System.ComponentModel.BackgroundWorker bg6;
}
}

View File

@ -117,28 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="bg1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>384, 17</value>
</metadata>
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>467, 17</value>
</metadata>
<metadata name="bg2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>84, 17</value>
</metadata>
<metadata name="bg3.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>159, 17</value>
</metadata>
<metadata name="bg4.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>234, 17</value>
</metadata>
<metadata name="bg5.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>644, 26</value>
</metadata>
<metadata name="bg6.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>772, 17</value>
</metadata>
</root>

View File

@ -1,7 +1,10 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace Sunny.UI
@ -14,6 +17,38 @@ namespace Sunny.UI
SetStyleFlags();
}
public UISymbolPanel(Type fonttype, UISymbolType symbolType, int columnCount = 24)
{
SetStyleFlags();
LoadFont(fonttype, symbolType, columnCount);
}
public void LoadFont(Type fonttype, UISymbolType symbolType, int columnCount = 24)
{
ColumnCount = columnCount;
ConcurrentDictionary<int, FieldInfo> dic = new ConcurrentDictionary<int, FieldInfo>();
foreach (var fieldInfo in fonttype.GetFields())
{
var obj = fieldInfo.GetRawConstantValue();
if (obj is int value)
{
dic.TryAdd(value, fieldInfo);
}
}
RowCount = dic.Count / ColumnCount + 1;
List<int> list = dic.Keys.ToList();
list.Sort();
for (int i = 0; i < GridCount; i++)
{
if (i >= list.Count) break;
Add(new SymbolValue(list[i], dic[list[i]].Name.Replace("fa_", "").Replace("ma_", ""), symbolType));
}
dic.Clear();
}
protected void SetStyleFlags(bool supportTransparent = true, bool selectable = true, bool resizeRedraw = false)
{
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
@ -86,7 +121,7 @@ namespace Sunny.UI
Rectangle rect = new Rectangle(ic * symbolSize, ir * symbolSize, symbolSize, symbolSize);
SymbolValue symbol = Symbols[i];
Color color = Color.Black;
if (Filter.IsValid() && symbol.Name.Contains(Filter)) color = Color.Purple;
if (Filter.IsValid() && symbol.Name.ToUpper().Contains(Filter.ToUpper())) color = Color.Purple;
if (i == SelectedIndex) color = Color.Red;
e.Graphics.DrawFontImage(symbol.Value, 28, color, rect);
}
@ -122,6 +157,13 @@ namespace Sunny.UI
private readonly List<SymbolValue> Symbols = new List<SymbolValue>();
public int SymbolCount => Symbols.Count;
public SymbolValue Get(int index)
{
return Symbols[index];
}
public void Clear()
{
Symbols.Clear();
@ -129,7 +171,8 @@ namespace Sunny.UI
public void Add(SymbolValue symbol)
{
if (Symbols.Count >= GridCount) return;
if (Symbols.Count >= GridCount)
RowCount++;
Symbols.Add(symbol);
}
@ -164,7 +207,8 @@ namespace Sunny.UI
public event OnSymbolValueChanged ValueChanged;
public string Filter { get; set; }
private string filter = "";
public string Filter { get => filter; set { filter = value; Invalidate(); } }
}
public delegate void OnSymbolValueChanged(object sender, SymbolValue value);