Archive 17/01/2023.

Difficulty to handling Scrollview

Taymindis

Greeting,
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->SetStyleAuto();
    _scrollV->SetSize(GetSubsystem<UI>()->GetRoot()->GetWidth()/2, GetSubsystem<UI>()->GetRoot()->GetHeight()/3);
    _scrollV->SetPosition(0, 0);
    _scrollV->SetPriority(100);
    _scrollV->SetColor(Color::BLACK);
    _scrollV->SetEnabled(true);
    _scrollV->SetDeepEnabled(true);
    _scrollV->SetSelected(true);
    _scrollV->SetHovering(true);
    _scrollV->SetScrollBarsVisible(true, true);
    
    
    SharedPtr<Urho3D::UIElement> chatContentElement(_scrollV->CreateChild<Urho3D::UIElement>());
    _scrollV->SetContentElement(chatContentElement);
    chatContentElement->SetLayoutMode(Urho3D::LM_VERTICAL);
    chatContentElement->SetStyleAuto();
    chatContentElement->SetPosition(0, 0);
    chatContentElement->SetAlignment(Urho3D::HA_LEFT, Urho3D::VA_BOTTOM);
    
    chatContentElement->SetSize(_scrollV->GetSize());
    
    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->SetColor(Color::GREEN);
        
        helloText->SetPosition(0 , GetSubsystem<UI>()->GetRoot()->GetHeight()  * (i/20) );
        helloText->SetPriority(100);
        _scrollV->GetContentElement()->AddChild(helloText);
    }
    
    SubscribeToEvent(_scrollV, E_MOUSEBUTTONDOWN, URHO3D_HANDLER(HelloWorld, HandleScrollUpdate) );
Eugene

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?

Taymindis

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?

Eugene

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.

Taymindis

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 ?
    a.
    SubscribeToEvent(_scrollV, E_SCROLLBARCHANGED, URHO3D_HANDLER(HelloWorld, HandleScrollUpdate) );
    b.
    SubscribeToEvent( E_SCROLLBARCHANGED, URHO3D_HANDLER(HelloWorld, HandleScrollUpdate) ); <<< it is working

Eugene

Yep, you are. E_SCROLLBARCHANGED is

Taymindis

Hi Eugene,

Noted with Thanks :slight_smile: :+1:

jmiller

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);