Nevron Open Vision provides support for drawing of vector based shapes called symbols. The advantage of such vector based shapes over regular raster images is that they do not blur and look nice at any size. This example demonstrates how to create and use Font Awesome symbols. Nevron Open Vision currently includes 1984 Font Awesome symbols. Use the radio buttons on the right to see the symbols at different sizes.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Globalization;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NFontAwesomeSymbolsExample";
// Create the NOV example and its controls
NWidget exampleContent = CreateExampleContent();
NWidget exampleControls = CreateExampleControls();
if (exampleControls != null)
{
exampleControls.PreferredWidth = 300;
}
// Place the example and its controls in a pair box
NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
pairBox.FillMode = ENStackFillMode.First;
pairBox.FitMode = ENStackFitMode.First;
pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);
// Host the example in the form
NNovWidgetHost host = new NNovWidgetHost(pairBox);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
#endregion
#region Example
public NWidget CreateExampleContent()
{
m_SymbolNames = NEnum.GetNames();
m_SymbolNamesSet = new NStringSet(false);
m_SymbolNamesSet.AddRange(m_SymbolNames);
m_TablePanel = new NTableFlowPanel();
m_TablePanel.BackgroundFill = new NColorFill(NColor.White);
m_TablePanel.HorizontalSpacing = NDesign.HorizontalSpacing * 3;
m_TablePanel.VerticalSpacing = NDesign.VerticalSpacing * 3;
m_TablePanel.Direction = ENHVDirection.LeftToRight;
m_TablePanel.MaxOrdinal = ColumnCount * 2;
m_TablePanel.Padding = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing,
NDesign.HorizontalSpacing * 6, NDesign.VerticalSpacing);
RecreateSymbols();
m_SearchBox = new NAutoCompleteBox();
m_SearchBox.PreferredWidth = 200;
m_SearchBox.HorizontalPlacement = ENHorizontalPlacement.Left;
m_SearchBox.Hint = $"Search {m_SymbolNames.Length} icons";
m_SearchBox.Image = Presentation.NResources.Image_Edit_Search_svg;
m_SearchBox.ImageBeforeText = true;
m_SearchBox.TextChanged += SearchBox_TextChanged;
NStylePropertyEx.SetRelativeFontSize(m_SearchBox, ENRelativeFontSize.Large);
NScrollContent scrollContent = new NScrollContent(m_TablePanel);
scrollContent.VScrollMode = ENScrollMode.Always;
scrollContent.HorizontalPlacement = ENHorizontalPlacement.Left;
NPairBox pairBox = new NPairBox(m_SearchBox, scrollContent, ENPairBoxRelation.Box1AboveBox2);
pairBox.FillMode = ENStackFillMode.Last;
pairBox.FitMode = ENStackFitMode.Last;
return pairBox;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
// Create the color box
m_ColorBox = new NColorBox();
m_ColorBox.SelectedColor = DefaultSymbolColor;
m_ColorBox.SelectedColorChanged += ColorBox_SelectedColorChanged;
stack.Add(NPairBox.Create("Color:", m_ColorBox));
// Create the size radio button group
NStackPanel radioStack = new NStackPanel();
double size = MinSymbolSize;
int selectedIndex = 0;
for (int i = 0; i < 4; i++)
{
if (size == DefaultSymbolSize)
{
selectedIndex = i;
}
string sizeStr = size.ToString(CultureInfo.InvariantCulture);
NRadioButton radioButton = new NRadioButton(sizeStr + "x" + sizeStr);
radioStack.Add(radioButton);
size *= 2;
}
m_RadioGroup = new NRadioButtonGroup(radioStack);
m_RadioGroup.SelectedIndex = 1;
m_RadioGroup.SelectedIndexChanged += RadioGroup_SelectedIndexChanged;
NPairBox pairBox = NPairBox.Create("Size:", m_RadioGroup);
pairBox.Box1.VerticalPlacement = ENVerticalPlacement.Top;
stack.Add(pairBox);
return new NUniSizeBoxGroup(stack);
}
public string GetExampleDescription()
{
return @"
Nevron Open Vision provides support for drawing of vector based shapes called symbols. The advantage of such vector
based shapes over regular raster images is that they do not blur and look nice at any size. This example demonstrates
how to create and use Font Awesome symbols. Nevron Open Vision currently includes " + NEnum.GetNames().Length + @"
Font Awesome symbols . Use the radio buttons on the right to see the symbols at different sizes.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Symbols", "https://www.nevron.com/docs/openvision/ui-symbols.html"),
("Widget Elements", "https://www.nevron.com/docs/openvision/ui-widget-elements.html"),
("Fonts", "https://www.nevron.com/docs/openvision/graphics-fonts.html"),
};
}
#endregion
#region Implementation
private void RecreateSymbols()
{
NColor color = m_ColorBox != null ? m_ColorBox.SelectedColor : DefaultSymbolColor;
double length = m_RadioGroup != null ? MinSymbolSize * Math.Pow(2, m_RadioGroup.SelectedIndex) : DefaultSymbolSize;
NSize size = new NSize(length, length);
INSet iconNamesSet = FilterNames(m_SearchBox?.Text);
m_TablePanel.Clear();
foreach (string iconName in iconNamesSet)
{
AddSymbolBox(iconName, size, color);
}
}
private NSymbolBox AddSymbolBox(string symbolName, NSize size, NColor color)
{
ENFontAwesomeSymbol fontAwesomeSymbol;
NEnum.TryParse(symbolName, out fontAwesomeSymbol);
NSymbolBox symbolBox = new NSymbolBox(NSymbol.Create(fontAwesomeSymbol, size, color));
m_TablePanel.Add(symbolBox);
NLabel label = new NLabel(NStringHelpers.InsertSpacesBeforeUppersAndDigits(symbolName));
label.VerticalPlacement = ENVerticalPlacement.Center;
m_TablePanel.Add(label);
return symbolBox;
}
private INSet FilterNames(string filter)
{
if (String.IsNullOrEmpty(filter))
return m_SymbolNamesSet;
else
return m_SymbolNamesSet.FindStrings(filter, ENStringMatchMode.StartsWith);
}
#endregion
#region Event Handlers
private void SearchBox_TextChanged(NValueChangeEventArgs arg)
{
RecreateSymbols();
}
private void ColorBox_SelectedColorChanged(NValueChangeEventArgs arg)
{
RecreateSymbols();
}
private void RadioGroup_SelectedIndexChanged(NValueChangeEventArgs arg)
{
RecreateSymbols();
}
#endregion
#region Fields
private NTableFlowPanel m_TablePanel;
private NColorBox m_ColorBox;
private NRadioButtonGroup m_RadioGroup;
private string[] m_SymbolNames;
private NStringSet m_SymbolNamesSet;
private NAutoCompleteBox m_SearchBox;
#endregion
#region Static Methods
#endregion
#region Constants
private const int ColumnCount = 5;
private const double MinSymbolSize = 16;
private const double DefaultSymbolSize = 32;
private static readonly NColor DefaultSymbolColor = NColor.MediumBlue;
#endregion
#region Nested Types
#endregion
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.DataStructures
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Imports System
Imports System.Globalization
Class MainWindow
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Title = "NOV WPF - NFontAwesomeSymbolsExample"
' Create the NOV example and its controls
Dim exampleContent As NWidget = CreateExampleContent()
Dim exampleControls As NWidget = CreateExampleControls()
If Not exampleControls Is Nothing Then
exampleControls.PreferredWidth = 300
End If
' Place the example and its controls in a pair box
Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
pairBox.FillMode = ENStackFillMode.First
pairBox.FitMode = ENStackFitMode.First
pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)
' Host the example in the form
Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
Content = host
End Sub
#End Region
#Region "Example"
Public Function CreateExampleContent() As NWidget
m_SymbolNames = NEnum.GetNames(Of ENFontAwesomeSymbol)()
m_SymbolNamesSet = New NStringSet(False)
m_SymbolNamesSet.AddRange(m_SymbolNames)
m_TablePanel = New NTableFlowPanel()
m_TablePanel.BackgroundFill = New NColorFill(NColor.White)
m_TablePanel.HorizontalSpacing = NDesign.HorizontalSpacing * 3
m_TablePanel.VerticalSpacing = NDesign.VerticalSpacing * 3
m_TablePanel.Direction = ENHVDirection.LeftToRight
m_TablePanel.MaxOrdinal = ColumnCount * 2
m_TablePanel.Padding = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing, NDesign.HorizontalSpacing * 6, NDesign.VerticalSpacing)
RecreateSymbols()
m_SearchBox = New NAutoCompleteBox()
m_SearchBox.PreferredWidth = 200
m_SearchBox.HorizontalPlacement = ENHorizontalPlacement.Left
m_SearchBox.Hint = $"Search {m_SymbolNames.Length} icons"
m_SearchBox.Image = Presentation.NResources.Image_Edit_Search_svg
m_SearchBox.ImageBeforeText = True
Me.m_SearchBox.TextChanged += AddressOf SearchBox_TextChanged
NStylePropertyEx.SetRelativeFontSize(m_SearchBox, ENRelativeFontSize.Large)
Dim scrollContent As NScrollContent = New NScrollContent(m_TablePanel)
scrollContent.VScrollMode = ENScrollMode.Always
scrollContent.HorizontalPlacement = ENHorizontalPlacement.Left
Dim pairBox As NPairBox = New NPairBox(m_SearchBox, scrollContent, ENPairBoxRelation.Box1AboveBox2)
pairBox.FillMode = ENStackFillMode.Last
pairBox.FitMode = ENStackFitMode.Last
Return pairBox
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
' Create the color box
m_ColorBox = New NColorBox()
m_ColorBox.SelectedColor = DefaultSymbolColor
Me.m_ColorBox.SelectedColorChanged += AddressOf ColorBox_SelectedColorChanged
stack.Add(NPairBox.Create("Color:", m_ColorBox))
' Create the size radio button group
Dim radioStack As NStackPanel = New NStackPanel()
Dim size = MinSymbolSize
Dim selectedIndex = 0
For i = 0 To 3
If size = DefaultSymbolSize Then
selectedIndex = i
End If
Dim sizeStr = size.ToString(CultureInfo.InvariantCulture)
Dim radioButton As NRadioButton = New NRadioButton(sizeStr & "x" & sizeStr)
radioStack.Add(radioButton)
size *= 2
Next
m_RadioGroup = New NRadioButtonGroup(radioStack)
m_RadioGroup.SelectedIndex = 1
Me.m_RadioGroup.SelectedIndexChanged += AddressOf RadioGroup_SelectedIndexChanged
Dim pairBox = NPairBox.Create("Size:", m_RadioGroup)
pairBox.Box1.VerticalPlacement = ENVerticalPlacement.Top
stack.Add(pairBox)
Return New NUniSizeBoxGroup(stack)
End Function
Public Function GetExampleDescription() As String
Return "
Nevron Open Vision provides support for drawing of vector based shapes called symbols. The advantage of such vector
based shapes over regular raster images is that they do not blur and look nice at any size. This example demonstrates
how to create and use Font Awesome symbols. Nevron Open Vision currently includes " & NEnum.GetNames(Of ENFontAwesomeSymbol)().Length.ToString().ToString() & "
Font Awesome symbols. Use the radio buttons on the right to see the symbols at different sizes.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Symbols", "https://www.nevron.com/docs/openvision/ui-symbols.html"), ("Widget Elements", "https://www.nevron.com/docs/openvision/ui-widget-elements.html"), ("Fonts", "https://www.nevron.com/docs/openvision/graphics-fonts.html")}
End Function
#End Region
#Region "Implementation"
Private Sub RecreateSymbols()
Dim color = If(m_ColorBox IsNot Nothing, m_ColorBox.SelectedColor, DefaultSymbolColor)
Dim length = If(m_RadioGroup IsNot Nothing, MinSymbolSize * Math.Pow(2, m_RadioGroup.SelectedIndex), DefaultSymbolSize)
Dim size As NSize = New NSize(length, length)
Dim iconNamesSet = FilterNames(m_SearchBox?.Text)
m_TablePanel.Clear()
For Each iconName As String In iconNamesSet
AddSymbolBox(iconName, size, color)
Next
End Sub
Private Function AddSymbolBox(symbolName As String, size As NSize, color As NColor) As NSymbolBox
Dim fontAwesomeSymbol As ENFontAwesomeSymbol
NEnum.TryParse(symbolName, fontAwesomeSymbol)
Dim symbolBox As NSymbolBox = New NSymbolBox(NSymbol.Create(fontAwesomeSymbol, size, color))
m_TablePanel.Add(symbolBox)
Dim label As NLabel = New NLabel(NStringHelpers.InsertSpacesBeforeUppersAndDigits(symbolName))
label.VerticalPlacement = ENVerticalPlacement.Center
m_TablePanel.Add(label)
Return symbolBox
End Function
Private Function FilterNames(filter As String) As INSet(Of String)
If String.IsNullOrEmpty(filter) Then
Return m_SymbolNamesSet
Else
Return m_SymbolNamesSet.FindStrings(filter, ENStringMatchMode.StartsWith)
End If
End Function
#End Region
#Region "Event Handlers"
Private Sub SearchBox_TextChanged(arg As NValueChangeEventArgs)
RecreateSymbols()
End Sub
Private Sub ColorBox_SelectedColorChanged(arg As NValueChangeEventArgs)
RecreateSymbols()
End Sub
Private Sub RadioGroup_SelectedIndexChanged(arg As NValueChangeEventArgs)
RecreateSymbols()
End Sub
#End Region
#Region "Fields"
Private m_TablePanel As NTableFlowPanel
Private m_ColorBox As NColorBox
Private m_RadioGroup As NRadioButtonGroup
Private m_SymbolNames As String()
Private m_SymbolNamesSet As NStringSet
Private m_SearchBox As NAutoCompleteBox
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
Private Const ColumnCount As Integer = 5
Private Const MinSymbolSize As Double = 16
Private Const DefaultSymbolSize As Double = 32
Private Shared ReadOnly DefaultSymbolColor As NColor = NColor.MediumBlue
#End Region
#Region "Nested Types"
#End Region
End Class