Is there a tutorial for using a WidgetText?

Apr 10, 2012 at 4:02 PM

Was scrolling through the docs going "yeah...cool...got it...cool... okay....neat....okay" until I got to Widgets : TODO

 

Doh.

 

Are there any other tutorials anywhere for specific widgets?  I am trying to get a WidgetText working and I can't even get it to appear on screen thus far, much less figure out how to get a text string from the user in it.

This is what I have so far, but when I run, I don't see any widget:

WidgetText t = new WidgetText();
t.Position = new Vector3(200.0f, 200.0f, 0.0f);
t.Size = new Vector3(100.0f, 100.0f, 0.0f);
t.ColorBase = Color.Gray;
t.Align = E_Align.MiddleCentre;
t.AddTexture("null", 0.0f, 0.0f, 1.0f, 1.0f);
            
Add(t);

I am rendering the correct screen in my Draw Method.  Thanks in advance.

Coordinator
Apr 10, 2012 at 5:13 PM

"Doh" indeed ... I really need to get round to adding more documentation, but the game I'm currently working on is taking up most of my time (excuses, sorry!).

There are some examples of how to use the Text widget in the Example project that is included in the download. What you're missing is the string itself and the font style (that describes what font to use and it's render passes etc).

So, in the Example project, if you look in UI/Layer.cs, lines 42-54 you'll see how I add in some common font styles. Then, in say UI/Screens/Options.cs, lines 56-65 give you an example of setting the string and font style. Something like ...

t.FontStyleName = "Default";
t.String = "Your String Here";
Hope this helps!

Apr 10, 2012 at 6:12 PM
Edited Apr 10, 2012 at 6:12 PM

So is t.String both get/set?  Like when my OK button or whatever is clicked, I can get whatever the user typed in?

Coordinator
Apr 10, 2012 at 6:15 PM

You can both get/set the string, yes. Feel free to browse the source code. =)

Jul 26, 2012 at 1:42 AM

I suspect MonkRocker was looking for a text box that was editable by the end user, not a more label like widget

Coordinator
Aug 7, 2012 at 11:12 AM
nekosune wrote:

I suspect MonkRocker was looking for a text box that was editable by the end user, not a more label like widget

Oh ... in that case then, no, XUI doesn't currently support that on PC. The main focus is Xbox at the moment, where you could just use the hardware keyboard to get text from the user.

Nov 8, 2012 at 10:28 PM

I'm having issues too, I can only get WidgetGraphics to show up, when I try adding a WidgetText to the screen it doesn't show up. I have set up a font (Arial) and even tried just using 'Default' instead of 'Arial', and have set the String property to 'Hello World'. Nothing works.

Nov 8, 2012 at 11:12 PM
Edited Nov 8, 2012 at 11:16 PM

I think I finally found it, you actually have to set up the font style as well as just adding the font files. For example, assuming your font Arial.fnt / Arial.tga is located under content project / Fonts /:

_UI.Fonts.Add( "Fonts\\", "Arial" );

//The documentation skips this part o.O

UI.FontStyle fontStyle = new UI.FontStyle( "Arial" );

fontStyle.AddRenderPass( new UI.FontStyleRenderPass() );

_UI.Store.FontStyle.Add( "Arial", fontStyle );

And now my text shows up, although for some strange reason it's wrapping my text between 'Hello' and 'World'.... is there a way to control it or turn it off altogether?

EDIT: NVM, finally solved it. Apparently the text sort of does a 'scale to fit' with the provided size while maintaining aspect ratio... that's pretty cool.

Coordinator
Nov 9, 2012 at 1:03 PM

"The documentation skips this part o.0" ... yeah ... I know, I know ... the documentation needs a serious update. The Example project should cover the basics though, which includes setting a FontStyle when using the text widget (it's also mentioned in my first post above).

As for the text wrapping, that is controlled with Size.X. Setting it to zero will disable wrapping.

Dec 8, 2012 at 10:18 PM
Edited Dec 8, 2012 at 10:39 PM
Wiffledude wrote:

I think I finally found it, you actually have to set up the font style as well as just adding the font files. For example, assuming your font Arial.fnt / Arial.tga is located under content project / Fonts /:

I have got a problem here: XNA Content Importer don't want to import my "SegoeUI.fnt" (same file in Example project)

What I'm supposed to do ?

 

Edit: I've solved my problem. Thanks.