1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Add scrollbaroptions FormSpec element (#8530)

This commit is contained in:
v-rob 2019-12-06 12:51:10 -08:00 committed by rubenwardy
parent 9a5d43a4f5
commit 4f45bfd08b
5 changed files with 159 additions and 36 deletions

View file

@ -247,7 +247,7 @@ s32 GUIScrollBar::getPosFromMousePos(const core::position2di &pos) const
w = RelativeRect.getHeight() - border_size * 2 - thumb_size;
p = pos.Y - AbsoluteRect.UpperLeftCorner.Y - border_size - offset;
}
return core::isnotzero(range()) ? s32(f32(p) / f32(w) * range()) + min_pos : 0;
return core::isnotzero(range()) ? s32(f32(p) / f32(w) * range() + 0.5f) + min_pos : 0;
}
void GUIScrollBar::setPos(const s32 &pos)
@ -272,7 +272,8 @@ void GUIScrollBar::setPos(const s32 &pos)
f32 f = core::isnotzero(range()) ? (f32(thumb_area) - f32(thumb_size)) / range()
: 1.0f;
draw_center = s32((f32(scroll_pos) * f) + (f32(thumb_size) * 0.5f)) + border_size;
draw_center = s32((f32(scroll_pos - min_pos) * f) + (f32(thumb_size) * 0.5f)) +
border_size;
}
void GUIScrollBar::setSmallStep(const s32 &step)
@ -315,6 +316,12 @@ void GUIScrollBar::setPageSize(const s32 &size)
setPos(scroll_pos);
}
void GUIScrollBar::setArrowsVisible(ArrowVisibility visible)
{
arrow_visibility = visible;
refreshControls();
}
s32 GUIScrollBar::getPos() const
{
return scroll_pos;
@ -419,7 +426,21 @@ void GUIScrollBar::refreshControls()
down_button->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT,
EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
}
bool visible = (border_size != 0);
bool visible;
if (arrow_visibility == DEFAULT)
visible = (border_size != 0);
else if (arrow_visibility == HIDE) {
visible = false;
border_size = 0;
} else {
visible = true;
if (is_horizontal)
border_size = RelativeRect.getHeight();
else
border_size = RelativeRect.getWidth();
}
up_button->setVisible(visible);
down_button->setVisible(visible);
}