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; v4 = maxValue;
} }
auto newValue = this->Sub96BC10(v4); auto newValue = this->StepValue(v4);
// Clamp to max value // Clamp to max value
if (newValue + this->m_valueStep >= maxValue) { if (newValue + this->m_valueStep >= maxValue) {
@ -322,9 +322,19 @@ void CSimpleSlider::SetValueStep(float valueStep) {
} }
} }
float CSimpleSlider::Sub96BC10(float value) { float CSimpleSlider::StepValue(float value) {
// TODO if (this->m_valueStep == 0.0f) {
return value; 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) { void CSimpleSlider::UnregisterRegion(CSimpleRegion* region) {

View File

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