int ScrollbarThemeOverlay::thumbPosition(const ScrollbarThemeClient& scrollbar)
{
    if (!scrollbar.totalSize())
        return 0;

    int trackLen = trackLength(scrollbar);
    float proportion = static_cast<float>(scrollbar.currentPos()) / scrollbar.totalSize();
    return round(proportion * trackLen);
}
int ScrollbarThemeOverlay::thumbLength(const ScrollbarThemeClient& scrollbar)
{
    int trackLen = trackLength(scrollbar);

    if (!scrollbar.totalSize())
        return trackLen;

    float proportion = static_cast<float>(scrollbar.visibleSize()) / scrollbar.totalSize();
    int length = round(proportion * trackLen);
    int minLen = std::min(minimumThumbLength(scrollbar), trackLen);
    length = clampTo(length, minLen, trackLen);
    return length;
}
Esempio n. 3
0
int ScrollbarTheme::thumbPosition(const ScrollbarThemeClient& scrollbar,
                                  float scrollPosition) {
  if (scrollbar.enabled()) {
    float size = scrollbar.totalSize() - scrollbar.visibleSize();
    // Avoid doing a floating point divide by zero and return 1 when
    // usedTotalSize == visibleSize.
    if (!size)
      return 0;
    float pos = std::max(0.0f, scrollPosition) *
                (trackLength(scrollbar) - thumbLength(scrollbar)) / size;
    return (pos < 1 && pos > 0) ? 1 : pos;
  }
  return 0;
}
Esempio n. 4
0
int ScrollbarTheme::thumbLength(const ScrollbarThemeClient& scrollbar) {
  if (!scrollbar.enabled())
    return 0;

  float overhang = fabsf(scrollbar.elasticOverscroll());
  float proportion = 0.0f;
  float totalSize = scrollbar.totalSize();
  if (totalSize > 0.0f) {
    proportion = (scrollbar.visibleSize() - overhang) / totalSize;
  }
  int trackLen = trackLength(scrollbar);
  int length = round(proportion * trackLen);
  length = std::max(length, minimumThumbLength(scrollbar));
  if (length > trackLen)
    length = 0;  // Once the thumb is below the track length, it just goes away
                 // (to make more room for the track).
  return length;
}