wxCoord wxScrollBar::ScrollbarToPixel(int thumbPos) { int range = GetRange(); if ( !range ) { // the only valid position anyhow return 0; } if ( thumbPos == -1 ) { // by default use the current thumb position thumbPos = GetThumbPosition(); } const wxSize sizeArrow = m_renderer->GetScrollbarArrowSize(); return (thumbPos * GetScrollbarSize()) / range + (IsVertical() ? sizeArrow.y : sizeArrow.x); }
int wxScrollBar::PixelToScrollbar(wxCoord coord) { const wxSize sizeArrow = m_renderer->GetScrollbarArrowSize(); return ((coord - (IsVertical() ? sizeArrow.y : sizeArrow.x)) * GetRange() ) / GetScrollbarSize(); }
// Formats the enabled scrollbars based on the current size of the host element. void ElementScroll::FormatScrollbars() { Vector2f containing_block = element->GetBox().GetSize(Box::PADDING); for (int i = 0; i < 2; i++) { if (!scrollbars[i].enabled) continue; if (i == VERTICAL) { scrollbars[i].widget->SetBarLength(element->GetClientHeight()); scrollbars[i].widget->SetTrackLength(element->GetScrollHeight()); float traversable_track = element->GetScrollHeight() - element->GetClientHeight(); if (traversable_track > 0) scrollbars[i].widget->SetBarPosition(element->GetScrollTop() / traversable_track); else scrollbars[i].widget->SetBarPosition(0); } else { scrollbars[i].widget->SetBarLength(element->GetClientWidth()); scrollbars[i].widget->SetTrackLength(element->GetScrollWidth()); float traversable_track = element->GetScrollWidth() - element->GetClientWidth(); if (traversable_track > 0) scrollbars[i].widget->SetBarPosition(element->GetScrollLeft() / traversable_track); else scrollbars[i].widget->SetBarPosition(0); } float slider_length = containing_block[1 - i]; float user_scrollbar_margin = scrollbars[i].element->ResolveProperty(SCROLLBAR_MARGIN, slider_length); float min_scrollbar_margin = GetScrollbarSize(i == VERTICAL ? HORIZONTAL : VERTICAL); slider_length -= Math::Max(user_scrollbar_margin, min_scrollbar_margin); scrollbars[i].widget->FormatElements(containing_block, slider_length); scrollbars[i].widget->SetLineHeight((float) ElementUtilities::GetLineHeight(element)); int variable_axis = i == VERTICAL ? 0 : 1; Vector2f offset = element->GetBox().GetPosition(Box::PADDING); offset[variable_axis] += containing_block[variable_axis] - (scrollbars[i].element->GetBox().GetSize(Box::BORDER)[variable_axis] + scrollbars[i].element->GetBox().GetEdge(Box::MARGIN, i == VERTICAL ? Box::RIGHT : Box::BOTTOM)); // Add the top or left margin (as appropriate) onto the scrollbar's position. offset[1 - variable_axis] += scrollbars[i].element->GetBox().GetEdge(Box::MARGIN, i == VERTICAL ? Box::TOP : Box::LEFT); scrollbars[i].element->SetOffset(offset, element, true); } // Format the corner, if it is necessary. if (scrollbars[0].enabled && scrollbars[1].enabled) { CreateCorner(); Box corner_box; corner_box.SetContent(Vector2f(scrollbars[VERTICAL].size, scrollbars[HORIZONTAL].size)); corner->SetBox(corner_box); corner->SetOffset(containing_block - Vector2f(scrollbars[VERTICAL].size, scrollbars[HORIZONTAL].size), element, true); corner->SetProperty(VISIBILITY, "visible"); } else { if (corner != NULL) corner->SetProperty(VISIBILITY, "hidden"); } }