Merge branch 'main' of ssh://tudbut.de:222/BaseBand/BaseBandRewrite
Some checks failed
/ Build BaseBand DSM & Broadway (push) Failing after 43s
Some checks failed
/ Build BaseBand DSM & Broadway (push) Failing after 43s
This commit is contained in:
commit
ba04f54db6
4 changed files with 25 additions and 15 deletions
|
@ -143,10 +143,12 @@ public abstract class Feature extends ToggleButton implements SetCommand {
|
|||
if (f.getType() == int.class) {
|
||||
Range range = f.getDeclaredAnnotation(Range.class);
|
||||
if (range != null) {
|
||||
String[] r = range.value().split("\\.\\.");
|
||||
String[] rStep = range.value().split("@");
|
||||
String[] r = rStep[0].split("\\.\\.");
|
||||
int min = Integer.parseInt(r[0]);
|
||||
int max = Integer.parseInt(r[1]);
|
||||
subComponents.add(new IntSlider(config.value(), settings, config.value(), Object::toString, max - min, min).gate(gate).hover(description));
|
||||
int step = rStep.length == 1 ? 1 : Integer.parseInt(rStep[1]);
|
||||
subComponents.add(new IntSlider(config.value(), settings, config.value(), Object::toString, max - min, min, step).gate(gate).hover(description));
|
||||
} else {
|
||||
throw new RuntimeException("No range specified for slider");
|
||||
}
|
||||
|
@ -154,10 +156,12 @@ public abstract class Feature extends ToggleButton implements SetCommand {
|
|||
if (f.getType() == float.class) {
|
||||
Range range = f.getDeclaredAnnotation(Range.class);
|
||||
if (range != null) {
|
||||
String[] r = range.value().split("\\.\\.");
|
||||
String[] rStep = range.value().split("@");
|
||||
String[] r = rStep[0].split("\\.\\.");
|
||||
float min = Float.parseFloat(r[0]);
|
||||
float max = Float.parseFloat(r[1]);
|
||||
subComponents.add(new Slider(config.value(), settings, config.value(), n -> String.valueOf(Math.round(n * 100) / 100f), max - min, min).gate(gate).hover(description));
|
||||
float step = rStep.length == 1 ? 1f : Float.parseFloat(rStep[1]);
|
||||
subComponents.add(new Slider(config.value(), settings, config.value(), n -> String.valueOf(Math.round(n * 100) / 100f), max - min, min, step).gate(gate).hover(description));
|
||||
} else {
|
||||
throw new RuntimeException("No range specified for slider");
|
||||
}
|
||||
|
|
|
@ -18,21 +18,23 @@ public class IntSlider extends Component {
|
|||
Function<Integer, Boolean> updateMethod;
|
||||
int mapper;
|
||||
int adder;
|
||||
int step;
|
||||
|
||||
{green = true;}
|
||||
|
||||
public IntSlider(String s, ConfigHandle handle, String field, Function<Integer, String> text, int mapper, int adder, Function<Integer, Boolean> updateMethod) {
|
||||
public IntSlider(String s, ConfigHandle handle, String field, Function<Integer, String> text, int mapper, int adder, int step, Function<Integer, Boolean> updateMethod) {
|
||||
this.text = s;
|
||||
this.handle = handle;
|
||||
this.field = field;
|
||||
this.sliderText = text;
|
||||
this.mapper = mapper;
|
||||
this.adder = adder;
|
||||
this.step = step;
|
||||
this.updateMethod = updateMethod;
|
||||
}
|
||||
|
||||
public IntSlider(String s, ConfigHandle handle, String field, Function<Integer, String> text, int mapper, int adder) {
|
||||
this(s, handle, field, text, mapper, adder, t -> true);
|
||||
public IntSlider(String s, ConfigHandle handle, String field, Function<Integer, String> text, int mapper, int adder, int step) {
|
||||
this(s, handle, field, text, mapper, adder, step, t -> true);
|
||||
}
|
||||
|
||||
int countdown = 0;
|
||||
|
@ -96,9 +98,10 @@ public class IntSlider extends Component {
|
|||
if(mouseButton == 0) {
|
||||
f = Math.max(Math.min(x, 140), 0) / 140f;
|
||||
|
||||
handle.getContent().set(field, Math.round(f * mapper + adder));
|
||||
int i = Math.round((f * mapper + adder) / step) * step;
|
||||
handle.getContent().set(field, i);
|
||||
handle.updated(field);
|
||||
if (!updateMethod.apply(Math.round(f * mapper + adder))) {
|
||||
if (!updateMethod.apply(i)) {
|
||||
System.out.println("Something went wrong handling the sliders!");
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
|
|
@ -18,21 +18,23 @@ public class Slider extends Component {
|
|||
Function<Float, Boolean> updateMethod;
|
||||
float mapper;
|
||||
float adder;
|
||||
float step;
|
||||
|
||||
{green = true;}
|
||||
|
||||
public Slider(String s, ConfigHandle handle, String field, Function<Float, String> text, float mapper, float adder, Function<Float, Boolean> updateMethod) {
|
||||
public Slider(String s, ConfigHandle handle, String field, Function<Float, String> text, float mapper, float adder, float step, Function<Float, Boolean> updateMethod) {
|
||||
this.text = s;
|
||||
this.handle = handle;
|
||||
this.field = field;
|
||||
this.sliderText = text;
|
||||
this.mapper = mapper;
|
||||
this.adder = adder;
|
||||
this.step = step;
|
||||
this.updateMethod = updateMethod;
|
||||
}
|
||||
|
||||
public Slider(String s, ConfigHandle handle, String field, Function<Float, String> text, float mapper, float adder) {
|
||||
this(s, handle, field, text, mapper, adder, t -> true);
|
||||
public Slider(String s, ConfigHandle handle, String field, Function<Float, String> text, float mapper, float adder, float step) {
|
||||
this(s, handle, field, text, mapper, adder, step, t -> true);
|
||||
}
|
||||
|
||||
int countdown = 0;
|
||||
|
@ -94,9 +96,10 @@ public class Slider extends Component {
|
|||
if(mouseButton == 0) {
|
||||
f = Math.max(Math.min(x, 140), 0) / 140f;
|
||||
|
||||
handle.getContent().set(field, f * mapper + adder);
|
||||
float f = Math.round((this.f * mapper + adder) / step) * step;
|
||||
handle.getContent().set(field, f);
|
||||
handle.updated(field);
|
||||
if (!updateMethod.apply(f * mapper + adder)) {
|
||||
if (!updateMethod.apply(f)) {
|
||||
System.out.println("Something went wrong handling the sliders!");
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.lang.annotation.Target;
|
|||
public @interface Range {
|
||||
|
||||
/**
|
||||
* n..m
|
||||
* begin..end[@step]
|
||||
* @return the range
|
||||
*/
|
||||
String value();
|
||||
|
|
Loading…
Add table
Reference in a new issue