Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label alignment not centred when setting a requisition on the label #27

Open
Jamie-Booth opened this issue Nov 4, 2015 · 2 comments
Open
Labels

Comments

@Jamie-Booth
Copy link

When setting a fixed width for a label using SetRequisition, the label will not be centered, but will be left justified.

Brew code snippet from Label.cpp:

22  if( !label->GetLineWrap() ) { 
23      // Calculate alignment when word wrap is disabled. 
24      sf::Vector2f avail_space( label->GetAllocation().width - label->GetRequisition().x, label->GetAllocation().height - label->GetRequisition().y ); 
25      sf::Vector2f position( avail_space.x * label->GetAlignment().x, avail_space.y * label->GetAlignment().y ); 
26 
27      vis_label.setPosition( position.x, position.y ); 
28  } 

This issue is I believe is line 24 where the GetRequisition.x is the same size as GetAllocation.width, as your available space will be 0. It doesn't matter what Alignment you assign, it will always be 0 if this is the case (Left Justified).

Sample code snippet, I have modified the alignment of 'File' to be the far right of the label for demonstration.

        m_boSingleFileHeader = sfg::Box::Create(sfg::Box::Orientation::HORIZONTAL, 0.0f);
        m_lSingleName = sfg::Label::Create("File");
        m_lSingleName->SetRequisition(sf::Vector2f(633.0f, 0.0f));
        m_lSingleName->SetAlignment(sf::Vector2f(1.0f, 0.5f));
        m_lSingleDate = sfg::Label::Create("Date");
        m_lSingleDate->SetRequisition(sf::Vector2f(180.0f, 0.0f));
        m_lSingleDate->SetAlignment(sf::Vector2f(0.1f, 0.5f));
        m_boSingleFileHeader->Pack(m_lSingleName, false, false);
        m_boSingleFileHeader->Pack(m_lSingleDate, false, false);

Please see the position of 'File' in the image below, it should be at the far right hand side of the 633.0f label, but instead it is at the far left.
lablebug

I'll do some playing around to see if I can fix it myself.

@Jamie-Booth
Copy link
Author

I have a fix for the alignment, though I've bundled it in with the ability to set text justification in the Misc class. I have also added the Misc class via inheritance to the button and togglebutton classes. This provides left, centre and right justification. If you are interested in this at all, let me know and I'll send a pull request so you can review the code.

@binary1248
Copy link
Collaborator

Send a pull request. 😉

I'll review it and provide feedback. We tend to like individual pull requests for each feature, but if you don't feel like splitting them up, I can edit your commits myself.

@binary1248 binary1248 added the bug label Nov 8, 2015
pkdawson pushed a commit to pkdawson/SFGUI that referenced this issue Oct 19, 2016
Added the ability to justify text (left, centre, right) for a button,
togglebutton and label, which also Fixes TankOs#27.  Examples have not been
created as yet, and current examples impacted by this change have not
been updated.  I'll do this once the change is approved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants