fix: tune slider formatting - max 2 decimals, integers show no decimal

This commit is contained in:
tian 2026-07-27 19:09:45 +08:00
parent 1de96c4c02
commit 6229a340a8
3 changed files with 10 additions and 3 deletions

View File

@ -617,6 +617,12 @@ func NewUI(discovery *service.DiscoveryService, registry *service.RegistryServic
return v
}
},
"formatTuneValue": func(value, step float64) string {
if step >= 1 {
return fmt.Sprintf("%.0f", value)
}
return fmt.Sprintf("%.2f", value)
},
}).ParseFS(uiFS, "ui/templates/*.html")
if err != nil {
return nil, err

View File

@ -20,9 +20,10 @@
<div class="tuning-item">
<label class="tuning-label">{{.Label}}</label>
<div class="tuning-control">
<input type="range" name="tune_{{.Path}}" value="{{printf "%.4f" .Value}}" min="{{.Min}}" max="{{.Max}}" step="{{.Step}}"
oninput="this.nextElementSibling.value=Number(this.value).toFixed({{if eq .Step 1.0}}0{{else if eq .Step 0.05}}2{{else}}1{{end}})+'{{.Unit}}'">
<output>{{printf "%.4f" .Value}}{{.Unit}}</output>
<input type="range" name="tune_{{.Path}}" value="{{printf "%v" .Value}}" min="{{.Min}}" max="{{.Max}}" step="{{printf "%v" .Step}}"
data-step="{{printf "%v" .Step}}" data-unit="{{.Unit}}"
oninput="var s=Number(this.dataset.step);var d=s>=1?0:2;this.nextElementSibling.textContent=Number(this.value).toFixed(d)+(this.dataset.unit||'')">
<output>{{formatTuneValue .Value .Step}}{{.Unit}}</output>
</div>
</div>
{{end}}

Binary file not shown.