unvestigate
Topic Author
Posts: 32
Joined: 17 Jan 2018, 09:55

Best way to include button symbols in text?

23 May 2019, 08:05

Hi,

What is the best (or at least a good) way to include button symbols in a text field? Say I want to show the text "Press X to use" on the HUD of my game. If the player is using a gamepad the X could be something like the symbol for the Xbox gamepad A button, while if the player is using mouse/kb it would be something like the E key on the keyboard.

I do support key rebinding so the symbols wont be static, and I also want the text to update immediately when the player switches to another input device (such as from mouse/kb to gamepad).

Do I need to include the symbols in the font somehow or can a text field show a certain symbol with a different font? Or do I include the symbols as images? Finally, is there a sample that shows how to do this?

Thanks!
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Best way to include button symbols in text?

23 May 2019, 15:25

Hi, you can use an InlineUIContainer in a TextBlock to insert images or vector art along with the text.

For example, you can have the following xaml to insert an image:
<TextBlock>
  <Run>Press </Run><InlineUIContainer><Image Source="{Binding UseButtonImg}"/></InlineUIContainer><Run> to use</Run>
</TextBlock>
 
unvestigate
Topic Author
Posts: 32
Joined: 17 Jan 2018, 09:55

Re: Best way to include button symbols in text?

23 May 2019, 16:28

Awesome, I'll try that. Thanks!
 
unvestigate
Topic Author
Posts: 32
Joined: 17 Jan 2018, 09:55

Re: Best way to include button symbols in text?

23 May 2019, 18:02

According to the MS docs and other resources I found on the internet the TextBlock does not support InlineUIContainers, only RichTextBoxes:

https://docs.microsoft.com/en-us/uwp/ap ... icontainer
https://social.msdn.microsoft.com/Forum ... withcsharp

Should I just assume that the TextBlock class found in Noesis differs from MS's TextBlock in this regard?

Also, could you show me how to set the previous text containing the image from code? I don't think I can put it into xaml like that as the position of the image can differ between languages. Because of this I would like to set the contents completely from C++.

Thanks!
 
unvestigate
Topic Author
Posts: 32
Joined: 17 Jan 2018, 09:55

Re: Best way to include button symbols in text?

23 May 2019, 19:26

Nevermind, I figured it out.

For the record, I did something like this:
Noesis::Ptr<Noesis::Run> run1 = *new Noesis::Run();
run1->SetText("Run1");

Noesis::Ptr<Noesis::Run> run2 = *new Noesis::Run();
run2->SetText("Run2");

Noesis::Ptr<Noesis::BitmapImage> bm = *new Noesis::BitmapImage();
bm->SetUriSource("game/ui/input_symbols/x360/360_x.tex");

Noesis::Ptr<Noesis::Image> img = *new Noesis::Image();
img->SetSource(bm);
	
img->SetWidth(32);
img->SetHeight(32);
img->SetStretch(Noesis::Stretch_Fill);

Noesis::Ptr<Noesis::InlineUIContainer> iuc = *new Noesis::InlineUIContainer();
iuc->SetChild(img);

mTextBlock->GetInlines()->Clear();
mTextBlock->GetInlines()->Add(run1);
mTextBlock->GetInlines()->Add(iuc);
mTextBlock->GetInlines()->Add(run2);
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Best way to include button symbols in text?

25 May 2019, 10:29

According to the MS docs and other resources I found on the internet the TextBlock does not support InlineUIContainers, only RichTextBoxes:
Should I just assume that the TextBlock class found in Noesis differs from MS's TextBlock in this regard?
InlineUIContainers do work inside TextBlock in WPF also. I just double checked that.

Who is online

Users browsing this forum: Google [Bot] and 73 guests