- unvestigate
- Posts: 32
- Joined:
Best way to include button symbols in text?
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!
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!
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: Best way to include button symbols in text?
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:
For example, you can have the following xaml to insert an image:
Code: Select all
<TextBlock>
<Run>Press </Run><InlineUIContainer><Image Source="{Binding UseButtonImg}"/></InlineUIContainer><Run> to use</Run>
</TextBlock>
- unvestigate
- Posts: 32
- Joined:
Re: Best way to include button symbols in text?
Awesome, I'll try that. Thanks!
- unvestigate
- Posts: 32
- Joined:
Re: Best way to include button symbols in text?
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!
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
- Posts: 32
- Joined:
Re: Best way to include button symbols in text?
Nevermind, I figured it out.
For the record, I did something like this:
For the record, I did something like this:
Code: Select all
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);
Re: Best way to include button symbols in text?
InlineUIContainers do work inside TextBlock in WPF also. I just double checked that.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?
Who is online
Users browsing this forum: Google [Bot] and 73 guests