BListView: manage horizontal scrollbar
BListView automatically sets the vertical scrollbar range already. Do the same for the horizontal scrollbar. Also fix BOutlineListView to compute the preferred size taking into account the items outline levels (it needs a little more space). This fixes the horizontal scrollbars in Locale preferences, second part of #6747.
This commit is contained in:
parent
456e971517
commit
34ac7f7ac3
|
@ -1473,33 +1473,51 @@ BListView::_InitObject(list_view_type type)
|
|||
void
|
||||
BListView::_FixupScrollBar()
|
||||
{
|
||||
|
||||
BScrollBar* vertScroller = ScrollBar(B_VERTICAL);
|
||||
if (!vertScroller)
|
||||
return;
|
||||
if (vertScroller != NULL) {
|
||||
BRect bounds = Bounds();
|
||||
int32 count = CountItems();
|
||||
|
||||
BRect bounds = Bounds();
|
||||
int32 count = CountItems();
|
||||
float itemHeight = 0.0;
|
||||
|
||||
float itemHeight = 0.0;
|
||||
if (CountItems() > 0)
|
||||
itemHeight = ItemAt(CountItems() - 1)->Bottom();
|
||||
|
||||
if (CountItems() > 0)
|
||||
itemHeight = ItemAt(CountItems() - 1)->Bottom();
|
||||
if (bounds.Height() > itemHeight) {
|
||||
// no scrolling
|
||||
vertScroller->SetRange(0.0, 0.0);
|
||||
vertScroller->SetValue(0.0);
|
||||
// also scrolls ListView to the top
|
||||
} else {
|
||||
vertScroller->SetRange(0.0, itemHeight - bounds.Height() - 1.0);
|
||||
vertScroller->SetProportion(bounds.Height () / itemHeight);
|
||||
// scroll up if there is empty room on bottom
|
||||
if (itemHeight < bounds.bottom)
|
||||
ScrollBy(0.0, bounds.bottom - itemHeight);
|
||||
}
|
||||
|
||||
if (bounds.Height() > itemHeight) {
|
||||
// no scrolling
|
||||
vertScroller->SetRange(0.0, 0.0);
|
||||
vertScroller->SetValue(0.0);
|
||||
// also scrolls ListView to the top
|
||||
} else {
|
||||
vertScroller->SetRange(0.0, itemHeight - bounds.Height() - 1.0);
|
||||
vertScroller->SetProportion(bounds.Height () / itemHeight);
|
||||
// scroll up if there is empty room on bottom
|
||||
if (itemHeight < bounds.bottom)
|
||||
ScrollBy(0.0, bounds.bottom - itemHeight);
|
||||
if (count != 0)
|
||||
vertScroller->SetSteps(
|
||||
ceilf(FirstItem()->Height()), bounds.Height());
|
||||
}
|
||||
|
||||
if (count != 0)
|
||||
vertScroller->SetSteps(ceilf(FirstItem()->Height()), bounds.Height());
|
||||
BScrollBar* horizontalScroller = ScrollBar(B_HORIZONTAL);
|
||||
if (horizontalScroller != NULL) {
|
||||
float w;
|
||||
GetPreferredSize(&w, NULL);
|
||||
BRect scrollBarSize = horizontalScroller->Bounds();
|
||||
|
||||
if (w <= scrollBarSize.Width()) {
|
||||
// no scrolling
|
||||
horizontalScroller->SetRange(0.0, 0.0);
|
||||
horizontalScroller->SetValue(0.0);
|
||||
} else {
|
||||
horizontalScroller->SetRange(0, w - scrollBarSize.Width());
|
||||
horizontalScroller->SetProportion(scrollBarSize.Width() / w);
|
||||
}
|
||||
printf("Range: %f - %f\n", w, scrollBarSize.Width());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -589,7 +589,26 @@ BOutlineListView::ResizeToPreferred()
|
|||
void
|
||||
BOutlineListView::GetPreferredSize(float* _width, float* _height)
|
||||
{
|
||||
BListView::GetPreferredSize(_width, _height);
|
||||
int32 count = CountItems();
|
||||
|
||||
if (count > 0) {
|
||||
float maxWidth = 0.0;
|
||||
for (int32 i = 0; i < count; i++) {
|
||||
// The item itself does not take his OutlineLevel into account, so
|
||||
// we must make up for that. Also add space for the latch.
|
||||
float itemWidth = ItemAt(i)->Width() + be_plain_font->Size()
|
||||
+ (ItemAt(i)->OutlineLevel() + 1)
|
||||
* be_control_look->DefaultItemSpacing();
|
||||
if (itemWidth > maxWidth)
|
||||
maxWidth = itemWidth;
|
||||
}
|
||||
|
||||
if (_width != NULL)
|
||||
*_width = maxWidth;
|
||||
if (_height != NULL)
|
||||
*_height = ItemAt(count - 1)->Bottom();
|
||||
} else
|
||||
BView::GetPreferredSize(_width, _height);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue