Q: How to synchronize ScrollablePane scrolling?

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

User avatar
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

Q: How to synchronize ScrollablePane scrolling?

Postby Van » Tue Jan 20, 2009 22:43

I have two CEGUI::ScrollablePane windows side-by-side (contain the same look byt have different data). They are used to perform a comparison of two entities using the same dataset. I want to keep the two scrollable panes synchronized as the user scrolls down (keeps the fields horizontally aligned).

Is this possible? Can I set the event callback to scroll the other pane?

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Wed Jan 21, 2009 11:09

Hi,

IMO the nicest solution would be to handle both pane's scroll events seperately, and then do something like this:

Code: Select all

OnScrollPane1()
{
  Scrollbar* bar1 = pane1->getVertScrollbar();
  Scrollbar* bar2 = pane2->getVertScrollbar();
  bar2->setScrollPosition(bar1->getScrollPosition()); 
}

// And the opposite...
OnScrollPane2()
{
  Scrollbar* bar2 = pane2->getVertScrollbar();
  Scrollbar* bar1 = pane1->getVertScrollbar();
  bar1->setScrollPosition(bar2->getScrollPosition()); 
}



Or something similar. You might add some checks in case the height of the content isn't equal.

HTH.
Check out my released snake game using Cegui!

User avatar
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

Postby Van » Wed Jan 21, 2009 12:39

pfft. I knew it was something simple. Thanks scriptkid!

However, if I use the EGUI::ScrollablePane::EventContentPaneScrolled to update each scrollable panes, is there the possibility of double jeopardy? That is, if ScrollablePaneA event fires and updates ScrollablePaneB, won't ScrollablePaneB fire and update ScrollablePaneA?

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Wed Jan 21, 2009 13:42

Van wrote:However, if I use the EGUI::ScrollablePane::EventContentPaneScrolled to update each scrollable panes, is there the possibility of double jeopardy? That is, if ScrollablePaneA event fires and updates ScrollablePaneB, won't ScrollablePaneB fire and update ScrollablePaneA?


Good one :)

You could be right about this one. However you can easily fix this by maintaining a member variable which is flagged during the handling on an event. So you'd get:

Code: Select all

OnScrollPane1()
{
  if (mUpdating)
    return;
  Scrollbar* bar1 = pane1->getVertScrollbar();
  Scrollbar* bar2 = pane2->getVertScrollbar();
  mUpdating = true;
  bar2->setScrollPosition(bar1->getScrollPosition());
  mUpdating = false;
}

// And the opposite...
OnScrollPane2()
{
  if (mUpdating)
    return;
  Scrollbar* bar2 = pane2->getVertScrollbar();
  Scrollbar* bar1 = pane1->getVertScrollbar();
  mUpdating = true;
  bar1->setScrollPosition(bar2->getScrollPosition());
  mUpdating = false;
}


Alternatively, you can temporarily disable events by calling "pane->setEnabled(false)" between the cross-updates. I think that works too.

HTH.
Check out my released snake game using Cegui!

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Postby Jamarr » Wed Jan 21, 2009 16:07

Code: Select all

bar2->setMutedState(true);
bar2->setScrollPosition(bar1->getScrollPosition());
bar2->setMutedState(false);

User avatar
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

Postby Van » Wed Jan 21, 2009 21:18

Thanks everyone!

Good catch Jamarr!


Return to “Help”

Who is online

Users browsing this forum: No registered users and 25 guests