By popular demand (my own taste, and a request of a tester), I hide a button when we can
no longer scroll in this direction...
I replaced the hackish test:
if (scrollRightButton.isVisible())
with a specialized field:
private boolean isScrolling;
The following are the added / modified methods with regard to my previous
message:
private void adjustScroll(int diff)
{
int newLeft = parsePosition(tabBar.getElement().getStyle().getLeft()) +
diff;
if (newLeft <= 0)
{
int gap = computeGap();
if (gap < -newLeft)
{
// If we are about to scroll too far away from the right
border, adjust back
newLeft += -newLeft - gap;
}
}
else
{
// Don't scroll for a positive newLeft
newLeft = 0;
}
scrollTo(newLeft);
}
/**
* Gap = distance between right of last tab and right of the tab bar.
*/
private int computeGap()
{
Widget lastTab = getLastTab();
if (lastTab == null)
return 0;
return getRightPosition(lastTab) - getTabBarWidth();
}
private void showScrollButtonsIfNecessary()
{
// Defer size calculations until sizes are available.
// When calculating immediately after add(), all size methods return
zero.
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand()
{
@Override
public void execute()
{
boolean shouldScroll = isScrollingNecessary();
if (isScrolling)
{
if (!shouldScroll)
{
// The scroll buttons are being hidden, reset the scroll position
to zero to avoid
// having tabs starting in the middle of the window!
scrollTo(0);
}
else
{
// Resizing or adding / removing tabs, recompute the
scroll
adjustScroll(0);
}
}
else
{
// Was not scrolling, show leftmost tab and adjust scroll button
visibility
scrollTo(0);
}
}
});
}
private void scrollTo(int pos)
{
tabBar.getElement().getStyle().setLeft(pos, Unit.PX);
// Change visibility of the scroll buttons, depending on the current
scrolling
isScrolling = pos < 0;
// Visible if not in the rightmost position
scrollLeftButton.setVisible(isScrolling);
// Visible if not in the leftmost position (and if we must scroll)
scrollRightButton.setVisible(isScrollingNecessary() && computeGap() !=
-pos);
}
HTH.
--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --
--
You received this message because you are subscribed to the Google Groups "Google
Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.