Skip to content

Commit

Permalink
Fix scrollbar thumb size
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Sep 21, 2024
1 parent b1bde8f commit e5f513a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion games/devtest/mods/testformspec/formspec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ local scroll_fs =
"list[current_player;main;0,5;8,4;]"..
"scroll_container_end[]"..
"scrollbar[10.1,8;0.5,4;vertical;scrbar420;0]"..
-- Scale
-- Buttons for scale comparison
"button[11,8;1,1;;0]"..
"button[11,9;1,1;;1]"..
"button[11,10;1,1;;2]"..
Expand Down
1 change: 1 addition & 0 deletions src/gui/guiScrollBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class GUIScrollBar : public IGUIElement
s32 getSmallStep() const { return small_step; }
s32 getPos() const;
s32 getTargetPos() const;
bool isHorizontal() const { return is_horizontal; }

void setMax(const s32 &max);
void setMin(const s32 &min);
Expand Down
27 changes: 20 additions & 7 deletions src/gui/guiScrollContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,31 @@ void GUIScrollContainer::setScrollBar(GUIScrollBar *scrollbar)
size.addInternalPoint(abs_rect.LowerRightCorner);
}

s32 hidden_content_px = *m_content_padding_px + (
s32 visible_content_px = (
m_orientation == VERTICAL
? std::max<s32>(0, size.LowerRightCorner.Y - AbsoluteClippingRect.LowerRightCorner.Y)
: std::max<s32>(0, size.LowerRightCorner.X - AbsoluteClippingRect.LowerRightCorner.X)
? AbsoluteClippingRect.getHeight()
: AbsoluteClippingRect.getWidth()
);
m_scrollbar->setMin(0);
m_scrollbar->setMax(std::ceil(hidden_content_px / std::fabs(m_scrollfactor)));
m_scrollbar->setPageSize(*m_content_padding_px + (

s32 total_content_px = *m_content_padding_px + (
m_orientation == VERTICAL
? (size.LowerRightCorner.Y - AbsoluteClippingRect.UpperLeftCorner.Y)
: (size.LowerRightCorner.X - AbsoluteClippingRect.UpperLeftCorner.X)
));
);

s32 hidden_content_px = std::max<s32>(0, total_content_px - visible_content_px);
m_scrollbar->setMin(0);
m_scrollbar->setMax(std::ceil(hidden_content_px / std::fabs(m_scrollfactor)));

// Note: generally, the scrollbar has the same size as the scroll container.
// However, in case it isn't, proportional adjustments are needed.
s32 scrollbar_px = (
m_scrollbar->isHorizontal()
? m_scrollbar->getRelativePosition().getWidth()
: m_scrollbar->getRelativePosition().getHeight()
);

m_scrollbar->setPageSize((total_content_px * scrollbar_px) / visible_content_px);
}

updateScrolling();
Expand Down

0 comments on commit e5f513a

Please sign in to comment.