Page 1 of 1

Q: How to synchronize ScrollablePane scrolling?

Posted: Tue Jan 20, 2009 22:43
by Van
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?

Posted: Wed Jan 21, 2009 11:09
by scriptkid
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.

Posted: Wed Jan 21, 2009 12:39
by Van
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?

Posted: Wed Jan 21, 2009 13:42
by scriptkid
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.

Posted: Wed Jan 21, 2009 16:07
by Jamarr

Code: Select all

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

Posted: Wed Jan 21, 2009 21:18
by Van
Thanks everyone!

Good catch Jamarr!