-
- Andreas Schooll
- Posts: 25
- Joined:
Changing FontFamily independently for ComboboxItems
Hey,
first of all: we are using Noesis for Unity
In our options menu we have a language selection combobox. In this combobox the language are displayed as text in their according languages.
To be able to display the texts properly we need to change the font family via databinding:
<ComboBox x:Name="combobox" width="1024">
<ComboBox.ItemTemplate>
<DataTemplate>
<ComboBoxItem>
<TextBlock Text="{Binding LanguageText}" FontFamily="{Binding FontFamily}"/>
</ComboBoxItem>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Unfortunately if we set the FontFamily data string to a font that we want to use, for example:
element.FontFamily = "../Fonts/#DroidSans";
it will produce an exception while rendering:
Exception: ../Fonts/#DroidSans resource not found
Noesis.Error.Check () (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisError.cs:49)
Noesis.UIRenderer.Noesis_MouseButtonUp (Int32 rendererId, Single x, Single y, Int32 button) (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisUIRendererImports.cs:168)
Noesis.UIRenderer.ProcessEvent (UnityEngine.Event ev, Boolean enableKeyboard, Boolean enableMouse) (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisUIRenderer.cs:210)
NoesisGUIPanel.OnGUI () (at Assets/Plugins/NoesisGUI/Scripts/NoesisGUIPanel.cs:136)
However it will work with:
element.FontFamily = "Gui/Core/Roboto.font";
Do we have to use another syntax to access our fonts?
element.FontFamily = "../Fonts/DroidSans.font";
did not work either.
Any help or suggestions how to achieve this kind of font binding is appreciated.
best regards,
Andreas
first of all: we are using Noesis for Unity

In our options menu we have a language selection combobox. In this combobox the language are displayed as text in their according languages.
To be able to display the texts properly we need to change the font family via databinding:
<ComboBox x:Name="combobox" width="1024">
<ComboBox.ItemTemplate>
<DataTemplate>
<ComboBoxItem>
<TextBlock Text="{Binding LanguageText}" FontFamily="{Binding FontFamily}"/>
</ComboBoxItem>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Unfortunately if we set the FontFamily data string to a font that we want to use, for example:
element.FontFamily = "../Fonts/#DroidSans";
it will produce an exception while rendering:
Exception: ../Fonts/#DroidSans resource not found
Noesis.Error.Check () (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisError.cs:49)
Noesis.UIRenderer.Noesis_MouseButtonUp (Int32 rendererId, Single x, Single y, Int32 button) (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisUIRendererImports.cs:168)
Noesis.UIRenderer.ProcessEvent (UnityEngine.Event ev, Boolean enableKeyboard, Boolean enableMouse) (at Assets/Plugins/NoesisGUI/Scripts/Core/NoesisUIRenderer.cs:210)
NoesisGUIPanel.OnGUI () (at Assets/Plugins/NoesisGUI/Scripts/NoesisGUIPanel.cs:136)
However it will work with:
element.FontFamily = "Gui/Core/Roboto.font";
Do we have to use another syntax to access our fonts?
element.FontFamily = "../Fonts/DroidSans.font";
did not work either.
Any help or suggestions how to achieve this kind of font binding is appreciated.
best regards,
Andreas
-
-
sfernandez
Site Admin
- Posts: 3238
- Joined:
Re: Changing FontFamily independently for ComboboxItems
Hi,
The FontFamily property, when it is set from code, expects the path to a NoesisGUI font resource. This probably should be wrapped to hide our internal resource paths, and offer to the user the possibility to set the font family as it is set in the xaml.
Meanwhile you have to build a path following this structure:
"Unity/Unity/" + "PathInsideAssets/" + "FontName.font"
For example, to set the TextBlock.FontFamily property in code to one of the fonts used by our Time sample, you should write the following:
The FontFamily property, when it is set from code, expects the path to a NoesisGUI font resource. This probably should be wrapped to hide our internal resource paths, and offer to the user the possibility to set the font family as it is set in the xaml.
Meanwhile you have to build a path following this structure:
"Unity/Unity/" + "PathInsideAssets/" + "FontName.font"
For example, to set the TextBlock.FontFamily property in code to one of the fonts used by our Time sample, you should write the following:
Code: Select all
TextBlock tb = new TextBlock("Hello World");
tb.SetFontFamily("Unity/Unity/NoesisGUI/Samples/ControlGallery/Samples/Fonts/Let Me Ride.font");
-
- golgepapaz
- Posts: 43
- Joined:
Re: Changing FontFamily independently for ComboboxItems
I am upgrading a piece of code written for Noesis 1.13 to 1.23 with unity 5
The part that gives me problem is
which I converted to
Noesis complains about not finding the FontFamily in that case.
Using the full path "Assets/Views/Open Sans/OpenSans.font" or the
notation "Open Sans/#Open Sans" with respect to xaml also does not work.
Changing it in the xaml itself works though. What should be the right path in that case.
The part that gives me problem is
Code: Select all
panel = this.GetComponent<NoesisGUIPanel> ();
Root = panel.GetRoot<Noesis.UserControl>();
Root.SetFontFamily("Unity/Unity/Views/Open Sans/Opensans.font");
Code: Select all
panel = this.GetComponent<NoesisGUIPanel> ();
Root = panel.GetContent() as Noesis.UserControl;
Root.FontFamily = new Noesis.FontFamily("Unity/Unity/Views/Open Sans/OpenSans.font");
Using the full path "Assets/Views/Open Sans/OpenSans.font" or the
notation "Open Sans/#Open Sans" with respect to xaml also does not work.
Changing it in the xaml itself works though. What should be the right path in that case.
-
-
sfernandez
Site Admin
- Posts: 3238
- Joined:
Re: Changing FontFamily independently for ComboboxItems
With the new API, you have to specified the path to the font asset inside the Unity project (in the form of "Assets/<PATH>/<FONT_FAMILY_NAME>"). In your case I guess it would be: "Assets/Views/Open Sans/OpenSans".
But before you can use that font, there must be at least 1 xaml referencing it, so we can process it and create the correspondence between font family names and the ttf files (and placing the result in StreamingAssets). I will recommend to create a ResourceDictionary xaml with all the fonts you want to use in your application:
Assets/GUI/Fonts.xaml
But before you can use that font, there must be at least 1 xaml referencing it, so we can process it and create the correspondence between font family names and the ttf files (and placing the result in StreamingAssets). I will recommend to create a ResourceDictionary xaml with all the fonts you want to use in your application:
Assets/GUI/Fonts.xaml
Code: Select all
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<FontFamily x:Key="font1">Fonts/#OpenSans</FontFamily>
<FontFamily x:Key="font2">Fonts/#Arial</FontFamily>
<FontFamily x:Key="font3">Fonts/#Times New Roman</FontFamily>
</ResourceDictionary>
-
- golgepapaz
- Posts: 43
- Joined:
Re: Changing FontFamily independently for ComboboxItems
Yes I've noticed earlier the files with .nsb and .nsf extensions were not created with the new api
by comparing it with streaming assets folder from the earlier version.Setting it in the xaml file
triggers the creation after rebuilding. I've had thought you'd done with the .make files and streaming
assets after the new api. I now believe it's partly true.Cheers anyway, it works fine now
by comparing it with streaming assets folder from the earlier version.Setting it in the xaml file
triggers the creation after rebuilding. I've had thought you'd done with the .make files and streaming
assets after the new api. I now believe it's partly true.Cheers anyway, it works fine now
Who is online
Users browsing this forum: Ahrefs [Bot] and 35 guests