| 378 | } |
| 379 | |
| 380 | void ComboBox::HandleStateChange( State old_state ) { |
| 381 | Bin::HandleStateChange( old_state ); |
| 382 | |
| 383 | if( GetState() == State::ACTIVE ) { |
| 384 | SetZOrder( 1 ); |
| 385 | |
| 386 | GrabModal(); |
| 387 | |
| 388 | m_start_entry = 0; |
| 389 | |
| 390 | float padding( Context::Get().GetEngine().GetProperty<float>( "ItemPadding", shared_from_this() ) ); |
| 391 | const std::string& font_name( Context::Get().GetEngine().GetProperty<std::string>( "FontName", shared_from_this() ) ); |
| 392 | unsigned int font_size( Context::Get().GetEngine().GetProperty<unsigned int>( "FontSize", shared_from_this() ) ); |
| 393 | const sf::Font& font( *Context::Get().GetEngine().GetResourceManager().GetFont( font_name ) ); |
| 394 | const float line_height( Context::Get().GetEngine().GetFontLineHeight( font, font_size ) ); |
| 395 | |
| 396 | if( ( GetDisplayedItemCount() > 2 ) && ( GetDisplayedItemCount() < GetItemCount() ) ) { |
| 397 | float border_width( Context::Get().GetEngine().GetProperty<float>( "BorderWidth", shared_from_this() ) ); |
| 398 | |
| 399 | |
| 400 | const sf::Vector2f item_size( |
| 401 | GetAllocation().size.x - 2 * border_width, |
| 402 | line_height + 2 * padding |
| 403 | ); |
| 404 | |
| 405 | m_scrollbar = Scrollbar::Create( Scrollbar::Orientation::VERTICAL ); |
| 406 | |
| 407 | auto offset = ( GetState() == State::ACTIVE ? border_width : 0.f ) + GetAllocation().size.x - padding - line_height; |
| 408 | |
| 409 | m_scrollbar->SetPosition( sf::Vector2f( offset, GetAllocation().size.y + border_width ) ); |
| 410 | m_scrollbar->SetRequisition( sf::Vector2f( GetAllocation().size.x - offset, static_cast<float>( GetDisplayedItemCount() ) * item_size.y - 2.f * border_width ) ); |
| 411 | |
| 412 | m_scrollbar->GetAdjustment()->SetPageSize( static_cast<float>( GetDisplayedItemCount() ) ); |
| 413 | m_scrollbar->GetAdjustment()->SetLower( 0.f ); |
| 414 | m_scrollbar->GetAdjustment()->SetUpper( static_cast<float>( GetItemCount() ) ); |
| 415 | m_scrollbar->GetAdjustment()->SetMinorStep( 1.f ); |
| 416 | m_scrollbar->GetAdjustment()->SetMajorStep( 1.f ); |
| 417 | |
| 418 | auto weak_this = std::weak_ptr<Widget>( shared_from_this() ); |
| 419 | |
| 420 | m_scrollbar->GetAdjustment()->GetSignal( Adjustment::OnChange ).Connect( [weak_this] { |
| 421 | auto shared_this = weak_this.lock(); |
| 422 | |
| 423 | if( !shared_this ) { |
| 424 | return; |
| 425 | } |
| 426 | |
| 427 | auto combo_box = std::dynamic_pointer_cast<ComboBox>( shared_this ); |
| 428 | |
| 429 | if( !combo_box ) { |
| 430 | return; |
| 431 | } |
| 432 | |
| 433 | combo_box->ChangeStartEntry(); |
| 434 | } ); |
| 435 | |
| 436 | m_scrollbar->SetZOrder( 2 ); |
| 437 |
nothing calls this directly
no test coverage detected