Files
common/src/main/java/org/saturnclient/config/property/FloatProperty.java
T
selimaj-devandclaude 06a90d8e51 Edit ranged settings with sliders
IntProperty and FloatProperty can take an optional range, step and unit.
PropertyList shows those settings as a Slider: a track to click or drag,
snapping to the step, with the value and unit beside it. Zoom and freelook
levels and durations, fullbright brightness, the theme radii, animation
timings and HUD scale and radius get ranges; the rest stay number boxes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-27 17:39:27 +02:00

57 lines
1.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package org.saturnclient.config.property;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
public class FloatProperty extends Property {
public float value;
public final float defaultValue;
/** Bounds for a slider, when the setting has a sensible range */
public Float min, max;
public float step = 0.1f;
/** Shown after the value, like "×" */
public String unit = "";
public FloatProperty(float defaultValue) {
this.value = defaultValue;
this.defaultValue = defaultValue;
}
/**
* Gives the setting a range, so it's edited with a slider.
*/
public FloatProperty range(float min, float max, float step) {
this.min = min;
this.max = max;
this.step = step;
return this;
}
public FloatProperty unit(String unit) {
this.unit = unit;
return this;
}
public boolean hasRange() {
return min != null && max != null;
}
@Override
public void reset() {
this.value = defaultValue;
this.isReset = true;
}
@Override
public JsonNode toJson() {
return JsonNodeFactory.instance.numberNode(this.value);
}
@Override
public void loadFromJson(JsonNode element) {
if (element.isNumber())
this.value = element.floatValue();
}
}