jedashford
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2016
01:23 PM
Can text be centered in a Scene Graph Button?
See image below. The button node doesn't seem to allow me to center the text. Even when I add empty spaces " " they are trimmed away. The first two buttons have spaces and a period so I can test my trimming theory. Am I looking passed something simple?

9 REPLIES 9
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2016
02:39 PM
Re: Can text be centered in a Scene Graph Button?
I have a ButtonGroup with buttons that are centered. I'm not sure if there's an easier way:
buttons="["   Play   ","   Stop   "]"
jedashford
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2016
11:52 AM
Re: Can text be centered in a Scene Graph Button?
Thank you. I'll give this a try. I'm worried a solution like this wont scale well with different screen resolutions. We'll find out...
joetesta
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2016
01:21 PM
Re: Can text be centered in a Scene Graph Button?
"jedashford" wrote:
Thank you. I'll give this a try. I'm worried a solution like this wont scale well with different screen resolutions. We'll find out...
I think I got this to work by having a Label that's a child element of the button, (and the same width) and the label text can be centered with;
<Label id="itemLabel" horizAlign="center" />
aspiring
jedashford
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2016
08:41 PM
Re: Can text be centered in a Scene Graph Button?
"joetesta" wrote:
I think I got this to work by having a Label that's a child element of the button, (and the same width) and the label text can be centered with;<Label id="itemLabel" horizAlign="center" />
Thats the key. Works like a charm.
nmaves
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2017
05:25 PM
Re: Can text be centered in a Scene Graph Button?
Can I ask how you created this horizontal button group? I am having a heck of a time creating something very simular to this.
WSJTim
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2020
05:22 AM
Re: Can text be centered in a Scene Graph Button?
If anyone else stumbles on this, this solution would've required a lot more work for me, dealing with changing the color of the Label when the button gains and loses focus. While hokey, this little utility function fixed the problem for me:
sub centerButtonLabel(button as object) for i = 0 to button.getChildCount() - 1 child = button.getChild(i) if child.subtype() = "Label" child.horizAlign = "center" end if end for end sub
I just call this in the onVisible for my screen. Works like a charm. Should Roku just support this as a property on the stock Button? Yes.
WSJTim
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2020
08:08 AM
Re: Can text be centered in a Scene Graph Button?
Ok here's a better solution since horizAlign appears to get reverted when the button text is changed. Use this component instead:
<component name="CenteredButton" extends="Button"> <script type="text/brightscript"> <![CDATA[ sub init() ' Find the label for i = 0 to m.top.getChildCount() - 1 child = m.top.getChild(i) if child.subtype() = "Label" child.horizAlign = "center" child.observeField("horizAlign", "onHorizAlignChanged") exit for end if end for end sub sub onHorizAlignChanged(msg as object) label = msg.getRoSGNode() if label.horizAlign <> "center" label.horizAlign = "center" end if end sub ]]> </script> </component>
bishalseth
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2021
02:21 PM
Re: Can text be centered in a Scene Graph Button?
You can use below xml to make it center
<Button id="searchClick"
text=" "
height="100"
translation="[90,820]"
minWidth="570"
maxWidth="570">
<Label id="itemLabel" height="100" width="570" text="Search" vertAlign="center" horizAlign="center" />
</Button>
WSJTim
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2021
06:54 AM
Re: Can text be centered in a Scene Graph Button?
With that method it looks fine until the button gets focus. Once that happens the label text color doesn't invert so I get an all white button where you can't see the label.