feat(ui): implement CSimpleSlider::StepValue

This commit is contained in:
fallenoak 2025-11-30 16:41:37 -06:00
parent fd6d6244ed
commit 0300d42061
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 15 additions and 5 deletions

View File

@ -287,7 +287,7 @@ void CSimpleSlider::SetValue(float value) {
v4 = maxValue;
}
auto newValue = this->Sub96BC10(v4);
auto newValue = this->StepValue(v4);
// Clamp to max value
if (newValue + this->m_valueStep >= maxValue) {
@ -322,11 +322,21 @@ void CSimpleSlider::SetValueStep(float valueStep) {
}
}
float CSimpleSlider::Sub96BC10(float value) {
// TODO
float CSimpleSlider::StepValue(float value) {
if (this->m_valueStep == 0.0f) {
return value;
}
auto valueOffset = value - this->m_baseValue;
auto halfStep = this->m_valueStep / 2.0f;
if (valueOffset <= 0.0f) {
return CMath::fint((valueOffset - halfStep) / this->m_valueStep) * this->m_valueStep + this->m_baseValue;
}
return CMath::fint((valueOffset + halfStep) / this->m_valueStep) * this->m_valueStep + this->m_baseValue;
}
void CSimpleSlider::UnregisterRegion(CSimpleRegion* region) {
if (this->m_thumbTexture == region) {
this->m_thumbTexture = nullptr;

View File

@ -57,7 +57,7 @@ class CSimpleSlider : public CSimpleFrame {
void SetThumbTexture(CSimpleTexture* texture, int32_t drawLayer);
void SetValue(float value);
void SetValueStep(float valueStep);
float Sub96BC10(float value);
float StepValue(float value);
};
#endif