-
Couldn't load subscription status.
- Fork 64
Description
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.

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