Andreas Schooll
Topic Author
Posts: 25
Joined: 30 Sep 2013, 16:58

Changing FontFamily independently for ComboboxItems

06 Feb 2014, 15:40

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
 
User avatar
sfernandez
Site Admin
Posts: 3001
Joined: 22 Dec 2011, 19:20

Re: Changing FontFamily independently for ComboboxItems

07 Feb 2014, 11:45

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:
TextBlock tb = new TextBlock("Hello World");
tb.SetFontFamily("Unity/Unity/NoesisGUI/Samples/ControlGallery/Samples/Fonts/Let Me Ride.font");
 
golgepapaz
Posts: 43
Joined: 01 Aug 2013, 01:59

Re: Changing FontFamily independently for ComboboxItems

27 May 2015, 15:52

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
			
panel = this.GetComponent<NoesisGUIPanel> ();
Root = panel.GetRoot<Noesis.UserControl>();
Root.SetFontFamily("Unity/Unity/Views/Open Sans/Opensans.font");
which I converted to
panel = this.GetComponent<NoesisGUIPanel> ();
Root = panel.GetContent() as Noesis.UserControl;
Root.FontFamily = new Noesis.FontFamily("Unity/Unity/Views/Open Sans/OpenSans.font");
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.
 
User avatar
sfernandez
Site Admin
Posts: 3001
Joined: 22 Dec 2011, 19:20

Re: Changing FontFamily independently for ComboboxItems

27 May 2015, 20:42

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
<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: 01 Aug 2013, 01:59

Re: Changing FontFamily independently for ComboboxItems

27 May 2015, 21:27

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

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot] and 4 guests