MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / updateScrollbar

Method updateScrollbar

launcher/ui/instanceview/InstanceView.cpp:145–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143}
144
145void InstanceView::updateScrollbar()
146{
147 int previousScroll = verticalScrollBar()->value();
148 if (m_groups.isEmpty())
149 {
150 verticalScrollBar()->setRange(0, 0);
151 }
152 else
153 {
154 int totalHeight = 0;
155 // top margin
156 totalHeight += m_categoryMargin;
157 int itemScroll = 0;
158 for (auto category : m_groups)
159 {
160 category->m_verticalPosition = totalHeight;
161 totalHeight += category->totalHeight() + m_categoryMargin;
162 if(!itemScroll && category->totalHeight() != 0)
163 {
164 itemScroll = category->contentHeight() / category->numRows();
165 }
166 }
167 // do not divide by zero
168 if(itemScroll == 0)
169 itemScroll = 64;
170
171 totalHeight += m_bottomMargin;
172 verticalScrollBar()->setSingleStep ( itemScroll );
173 const int rowsPerPage = qMax ( viewport()->height() / itemScroll, 1 );
174 verticalScrollBar()->setPageStep ( rowsPerPage * itemScroll );
175
176 verticalScrollBar()->setRange(0, totalHeight - height());
177 }
178
179 verticalScrollBar()->setValue(qMin(previousScroll, verticalScrollBar()->maximum()));
180}
181
182void InstanceView::updateGeometries()
183{

Callers

nothing calls this directly

Calls 4

isEmptyMethod · 0.80
totalHeightMethod · 0.80
contentHeightMethod · 0.80
numRowsMethod · 0.80

Tested by

no test coverage detected