About Monkey 2 › Forums › Monkey 2 Programming Help › MojoX : How to change the font?
Tagged: font mojox style change
This topic contains 6 replies, has 2 voices, and was last updated by 
 Ratchet 7 months, 1 week ago.
- 
		AuthorPosts
 - 
		
			
				
September 7, 2018 at 7:01 am #15384
I simply want to change the font of a TextView at runtime. But it doesn’t work.
Monkey12345678910111213141516171819202122232425262728293031323334353637#import "<std>"#import "<mojo>"#import "<mojox>"#Import "calibri.ttf"Using std..Using mojo..Using mojox..Class TestApp Extends WindowMethod New()Super.New("TestApp", 640, 480, WindowFlags.Resizable)Local inputView := New TextView("Hello World!")' CHANGING THE FONTinputView.Style.Font.Load("asset::calibri.ttf", 20)inputView.ValidateStyle()inputView.RequestRender()ContentView = inputViewinputView.MakeKeyView()EndEndFunction Main()New AppInstanceNew TestAppApp.Run()EndSeptember 8, 2018 at 12:15 pm #15398You didn’t assign loaded font, so it didn’t changed.
Correct way:
inputView.Style.Font = Font.Load("asset::calibri.ttf", 20)
September 11, 2018 at 6:39 am #15410This loads the font but it’s messed up. Also the input caret is on the wrong position. Seems like the TextView has to be updated or something…

EDIT: Ok, InvalidateStyle does the trick.
Monkey12inputView.Style.Font = Font.Load("asset::calibri.ttf", 20)inputView.InvalidateStyle()September 11, 2018 at 6:44 am #15411You can use theme file to setup fonts and other views related stuff in json format, similar to css, look at assets/themes/ folder of you compiled app to see what theme file is, default.json.
But you need to create and set your own theme file based on that default given from mojox.
Your screen looks like there are two intersected labels.
September 11, 2018 at 6:46 am #15412No, it’s really just the one TextView messed up the font. Solution in my post above.
Btw: I just want to change the font of one TextView to a very special font. So the theme file won’t work because it changes all of them
September 11, 2018 at 6:49 am #15413Good.
Also note, that all your TextView now will have such font.
To separate them, use inputView.Style = inputView.Style.Copy().
September 11, 2018 at 7:14 am #15414Great, thanks.
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.