MCPcopy Create free account
hub / github.com/TankOs/SFGUI / CalculateRequisition

Method CalculateRequisition

src/SFGUI/Notebook.cpp:37–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37sf::Vector2f Notebook::CalculateRequisition() {
38 if( !GetPageCount() ) {
39 return sf::Vector2f( 0.f, 0.f );
40 }
41
42 float padding( Context::Get().GetEngine().GetProperty<float>( "Padding", shared_from_this() ) );
43 float border_width( Context::Get().GetEngine().GetProperty<float>( "BorderWidth", shared_from_this() ) );
44
45 sf::Vector2f tab_requisition( 0.f, 0.f );
46 sf::Vector2f child_requisition( 0.f, 0.f );
47
48 for( const auto& child : m_children ) {
49 if( ( GetTabPosition() == TabPosition::TOP ) || ( GetTabPosition() == TabPosition::BOTTOM ) ) {
50 // Tabs are positioned horizontally.
51 tab_requisition.x += ( child.tab_label->GetRequisition().x + 2.f * padding + border_width );
52 tab_requisition.y = std::max( tab_requisition.y, child.tab_label->GetRequisition().y );
53 }
54 else {
55 // Tabs are positioned vertically.
56 tab_requisition.x = std::max( tab_requisition.x, child.tab_label->GetRequisition().x );
57 tab_requisition.y += ( child.tab_label->GetRequisition().y + 2.f * padding + border_width );
58 }
59
60 child_requisition.x = std::max( child_requisition.x, child.child->GetRequisition().x );
61 child_requisition.y = std::max( child_requisition.y, child.child->GetRequisition().y );
62 }
63
64 sf::Vector2f requisition( 0.f, 0.f );
65
66 child_requisition.x += 2.f * ( padding + border_width );
67 child_requisition.y += 2.f * ( padding + border_width );
68
69 if( ( GetTabPosition() == TabPosition::TOP ) || ( GetTabPosition() == TabPosition::BOTTOM ) ) {
70 // Tabs are positioned horizontally.
71 tab_requisition.x += border_width;
72 tab_requisition.y += ( border_width + 2.f * padding );
73
74 requisition.x = std::max( tab_requisition.x, child_requisition.x );
75 requisition.y = tab_requisition.y + child_requisition.y;
76 }
77 else {
78 // Tabs are positioned vertically.
79 tab_requisition.x += ( border_width + 2.f * padding );
80 tab_requisition.y += border_width;
81
82 requisition.x = tab_requisition.x + child_requisition.x;
83 requisition.y = std::max( tab_requisition.y, child_requisition.y );
84 }
85
86 m_child_requisition = child_requisition;
87 m_tab_requisition = tab_requisition;
88
89 if( GetScrollable() ) {
90 if( ( GetTabPosition() == TabPosition::TOP ) || ( GetTabPosition() == TabPosition::BOTTOM ) ) {
91 m_tab_requisition.x = 0.f;
92 requisition.x = m_child_requisition.x + 2.f * ( padding + border_width );
93 }
94 else {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected