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

Method RecalculateSize

src/SFGUI/Notebook.cpp:564–710  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

562}
563
564void Notebook::RecalculateSize() {
565 if( !IsGloballyVisible() ) {
566 return;
567 }
568
569 float padding( Context::Get().GetEngine().GetProperty<float>( "Padding", shared_from_this() ) );
570 float border_width( Context::Get().GetEngine().GetProperty<float>( "BorderWidth", shared_from_this() ) );
571 float scroll_button_size( Context::Get().GetEngine().GetProperty<float>( "ScrollButtonSize", shared_from_this() ) );
572
573 for( const auto& child : m_children ) {
574 child.tab_label->Show( false );
575 }
576
577 auto children_size = static_cast<IndexType>( m_children.size() );
578
579 m_num_displayed_tabs = children_size - GetFirstDisplayedTab();
580
581 if( GetTabPosition() == TabPosition::TOP ) {
582 // Tabs are positioned at top.
583 auto tab_current_x = ( GetScrollable() && GetFirstDisplayedTab() != 0 ) ? scroll_button_size : 0.f;
584
585 for( auto index = GetFirstDisplayedTab(); index < children_size; ++index ) {
586 if( GetScrollable() && ( tab_current_x + border_width + 2.f * padding + m_children[static_cast<std::size_t>( index )].tab_label->GetRequisition().x + scroll_button_size ) > GetAllocation().size.x ) {
587 m_num_displayed_tabs = index - GetFirstDisplayedTab();
588 break;
589 }
590
591 m_children[static_cast<std::size_t>( index )].tab_label->Show( true );
592
593 m_children[static_cast<std::size_t>( index )].child->SetAllocation(
594 sf::FloatRect(
595 { border_width + padding, m_tab_requisition.y + border_width + padding },
596 { GetAllocation().size.x - 2.f * ( border_width + padding ), GetAllocation().size.y - ( 2.f * ( border_width + padding ) + m_tab_requisition.y ) }
597 )
598 );
599
600 m_children[static_cast<std::size_t>( index )].tab_label->SetAllocation(
601 sf::FloatRect(
602 { tab_current_x + border_width + padding, border_width + padding },
603 { m_children[static_cast<std::size_t>( index )].tab_label->GetRequisition().x, m_tab_requisition.y - 2.f * padding - border_width }
604 )
605 );
606
607 tab_current_x += ( border_width + 2.f * padding + m_children[static_cast<std::size_t>( index )].tab_label->GetRequisition().x );
608 }
609 }
610 else if( GetTabPosition() == TabPosition::BOTTOM ) {
611 // Tabs are positioned at bottom.
612 auto tab_current_x = ( GetScrollable() && GetFirstDisplayedTab() != 0 ) ? scroll_button_size : 0.f;
613
614 for( auto index = GetFirstDisplayedTab(); index < children_size; ++index ) {
615 if( GetScrollable() && ( tab_current_x + border_width + 2.f * padding + m_children[static_cast<std::size_t>( index )].tab_label->GetRequisition().x + scroll_button_size ) > GetAllocation().size.x ) {
616 m_num_displayed_tabs = index - GetFirstDisplayedTab();
617 break;
618 }
619
620 m_children[static_cast<std::size_t>( index )].tab_label->Show( true );
621

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.80
SetAllocationMethod · 0.80
ShowMethod · 0.45

Tested by

no test coverage detected