Difficulty to handling Scrollview

I m new to Urho 3d, I am migrating from other c++ game engine to urho3d, But I have a difficulties to handle the scroll view.

_Questions: - _
1. It only render the element which within the size, when scroll down, it is empty
2. How do I listen the scroll view event(onMove, onSlide .etc)

This is my sample code below, but i

 _scrollV = GetSubsystem<UI>()->GetRoot()->CreateChild<ScrollView>();    
    _scrollV->SetSize(GetSubsystem<UI>()->GetRoot()->GetWidth()/2, GetSubsystem<UI>()->GetRoot()->GetHeight()/3);
    _scrollV->SetPosition(0, 0);
    _scrollV->SetScrollBarsVisible(true, true);
    SharedPtr<Urho3D::UIElement> chatContentElement(_scrollV->CreateChild<Urho3D::UIElement>());
    chatContentElement->SetPosition(0, 0);
    chatContentElement->SetAlignment(Urho3D::HA_LEFT, Urho3D::VA_BOTTOM);
    for(int i=20;i>0;i--) {
        // Construct new Text object
        SharedPtr<Text> helloText(new Text(context_));
        // Set String to display
        helloText->SetText("Hello World from Urho3D Hello World from Urho3D Hello World from Urho3D Hello World from Urho3D Hello World from Urho3D ");
        // Set font and text color
        helloText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.sdf"), GetSubsystem<UI>()->GetRoot()->GetMaxWidth());
        helloText->SetPosition(0 , GetSubsystem<UI>()->GetRoot()->GetHeight()  * (i/20) );
    SubscribeToEvent(_scrollV, E_MOUSEBUTTONDOWN, URHO3D_HANDLER(HelloWorld, HandleScrollUpdate) );
1 Like

I think I know what are you talking about, but could you provide screenshot?
You probably should increase minimal size of inner elements.

Is E_SCROLLBARCHANGED event from ScrollBar enough for you?

Hi Eugene,

  1. Attached Screen Shot For References29 PM

  2. I couldn’t find out E_SCROLLBARCHANGED event, is this define at other header file? The purpose I want to make it scrollbar move physically.

  3. Should I use ListView instead of scrollbar view?

Well, start with removing this line. You shouldn’t set position and size of your elements manually if you use automatic layout (vertical or horizontal).

Here is the same. You literally forced your content to have the same size as your window. If you use ScrollView, you probably want the content to be bigger.

Depends on desired functionality.

Hi Eugene,

  1. I have applied your suggestion and I also remove this line
    chatContentElement->SetAlignment(Urho3D::HA_LEFT, Urho3D::VA_BOTTOM);
    And now is working fine.

  2. I’ve tried sample a. and it’s not working, but b. is working fine. Am I missing something or ?
    SubscribeToEvent(_scrollV, E_SCROLLBARCHANGED, URHO3D_HANDLER(HelloWorld, HandleScrollUpdate) );
    SubscribeToEvent( E_SCROLLBARCHANGED, URHO3D_HANDLER(HelloWorld, HandleScrollUpdate) ); <<< it is working


1 Like

Hi Eugene,

Noted with Thanks :slight_smile: :+1:

Hi Taymindis, glad you got this working.

Just to be clear for others, we refer to these methods of Object.h

/// Subscribe to a specific sender's event.
void SubscribeToEvent(Object* sender, StringHash eventType, EventHandler* handler);
/// Subscribe to an event that can be sent by any sender.
void SubscribeToEvent(StringHash eventType, EventHandler* handler);