Skip to content

Commit

Permalink
Fixes slider step not working properly (move slider with keyboard or …
Browse files Browse the repository at this point in the history
…mouse wheel)
  • Loading branch information
Zailer43 committed Jun 18, 2024
1 parent d9aec6e commit baf3d45
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected void setupButtonsCallbacks(FlowLayout rootComponent) {
this.authorField = TextBoxRow.setup(rootComponent, AUTHOR_ID, MinecraftClient.getInstance().player.getName().getString(), 512);
this.titleField = TextBoxRow.setup(rootComponent, TITLE_ID, config.defaultBookTitle(), WrittenBookContentComponent.MAX_TITLE_LENGTH);
this.maxMessageLengthField = SliderRow.setup(rootComponent, MAX_MESSAGE_LENGTH_ID, config.maxMessageLength(),
1, 512, Integer.class, 0, 1,
1, 512, Integer.class, 0, 16,
aDouble -> this.messageField.setMaxLength(aDouble.intValue())
);
//bottom buttons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static SliderWidget setup(FlowLayout rootComponent, String id, double def
numberSlider.max(max);
numberSlider.setFromDiscreteValue(defaultValue);
numberSlider.updateMessage();
numberSlider.scrollStep(scrollStep);
numberSlider.scrollStep(scrollStep / (max - min));

resetButton.onPress(button -> numberSlider.setFromDiscreteValue(defaultValue));
resetButton.active = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.wispforest.owo.ui.container.FlowLayout;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.Text;
import net.minecraft.util.Pair;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -77,15 +78,16 @@ protected void setupButtonsCallbacks(FlowLayout rootComponent) {
SliderWidget widthSlider = rootComponent.childById(SliderWidget.class, SliderRow.getSliderId(WIDTH_ID));
SliderWidget heightSlider = rootComponent.childById(SliderWidget.class, SliderRow.getSliderId(HEIGHT_ID));
ButtonWidget.PressAction onWidthChange = button -> this.onResolutionChanged(imageButton, this.preserveImageAspectRatioToggle, widthSlider, heightSlider, true);
this.widthSlider = SliderRow.setup(rootComponent, WIDTH_ID, DEFAULT_SIZE_VALUE, 2, config.maxResolution(), Integer.class, 0, 1,
this.widthSlider = SliderRow.setup(rootComponent, WIDTH_ID, DEFAULT_SIZE_VALUE, 2, config.maxResolution(), Integer.class, 0, 3,
aDouble -> onWidthChange.onPress(null)
);
this.heightSlider = SliderRow.setup(rootComponent, HEIGHT_ID, DEFAULT_SIZE_VALUE, 2, config.maxResolution(), Integer.class, 0, 1,
this.heightSlider = SliderRow.setup(rootComponent, HEIGHT_ID, DEFAULT_SIZE_VALUE, 2, config.maxResolution(), Integer.class, 0, 3,
aDouble -> this.onResolutionChanged(imageButton, this.preserveImageAspectRatioToggle, heightSlider, widthSlider, false)
);
this.showResolutionToggle = BooleanRow.setup(rootComponent, SHOW_RESOLUTION_ID, false);
this.smoothImageToggle = BooleanRow.setup(rootComponent, SMOOTH_IMAGE_ID, true);
this.percentageOfSimilarityToCompress = SliderRow.setup(rootComponent, PERCENTAGE_OF_SIMILARITY_TO_COMPRESS_ID, config.defaultPercentageOfSimilarityToCompress(), 0d, MAX_PERCENTAGE_OF_SIMILARITY_TO_COMPRESS, Double.class, 1, 0.05d, null);
this.percentageOfSimilarityToCompress = SliderRow.setup(rootComponent, PERCENTAGE_OF_SIMILARITY_TO_COMPRESS_ID, config.defaultPercentageOfSimilarityToCompress(), 0d, MAX_PERCENTAGE_OF_SIMILARITY_TO_COMPRESS, Double.class, 1, 0.1d, null);
this.percentageOfSimilarityToCompress.message(s -> Text.literal(s + "%"));
//tabs
this.setTabs(rootComponent, selectedTab, ImagetextTabs.values(), "tabs", anEnum -> selectedTab = (ImagetextTabs) anEnum, this.tabs);
this.setTabs(rootComponent, selectedAlgorithm, ImagetextAlgorithms.values(), "algorithms", anEnum -> selectedAlgorithm = (ImagetextAlgorithms) anEnum, this.algorithmsTabs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public List<MutableText> get(ImagetextLogic logic, ImagetextData data, int lineS

@Override
public void setupComponents(FlowLayout rootComponent) {
this.edgeThresholdSlider = SliderRow.setup(rootComponent, EDGE_THRESHOLD_ID, 30, 1, 255, Integer.class, 0, 1, null);
this.edgeThresholdSlider = SliderRow.setup(rootComponent, EDGE_THRESHOLD_ID, 30, 1, 255, Integer.class, 0, 5, null);
this.edgeDistanceSlider = SliderRow.setup(rootComponent, EDGE_DISTANCE_ID, 2, 1, 5, Integer.class, 0, 1, null);
this.invertBooleanButton = BooleanRow.setup(rootComponent, INVERT_ID, false, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ public void execute(ImagetextLogic logic) {
public void setupComponents(FlowLayout rootComponent) {
assert MinecraftClient.getInstance().player != null;

this.textOpacity = SliderRow.setup(rootComponent, TEXT_OPACITY_ID, 255, 0, 255, Integer.class, 0, 1, null);
this.textOpacity = SliderRow.setup(rootComponent, TEXT_OPACITY_ID, 255, 0, 255, Integer.class, 0, 10, null);
this.backgroundColor = ColorRow.setup(rootComponent, BACKGROUND_COLOR_ID, Color.ofArgb(DisplayEntity.TextDisplayEntity.INITIAL_BACKGROUND), true, 0, null);
this.textShadow = BooleanRow.setup(rootComponent, TEXT_SHADOW_ID, false, null);
this.textSeeThrough = BooleanRow.setup(rootComponent, TEXT_SEE_THROUGH_ID, false, null);
this.textAlignment = EnumRow.setup(rootComponent, TEXT_ALIGNMENT_ID, TextDisplayAlignmentOption.LEFT, null);
this.billboard = EnumRow.setup(rootComponent, BILLBOARD_ID, DisplayEntityBillboardOption.FIXED, null);
this.rotation = SliderRow.setup(rootComponent, ROTATION_ID, MathHelper.wrapDegrees(MinecraftClient.getInstance().player.getYaw()), -180, 180, Float.class, 1, 0.25d, null);
this.rotation = SliderRow.setup(rootComponent, ROTATION_ID, MathHelper.wrapDegrees(MinecraftClient.getInstance().player.getYaw()), -180, 180, Float.class, 1, 30, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public Text getText(TextFormatLogic logic) {
@Override
public void setupComponents(FlowLayout rootComponent) {
FzmmConfig.TextFormat config = FzmmClient.CONFIG.textFormat;
this.hue = SliderRow.setup(rootComponent, HUE_ID, 1d, 0d, 1d, Float.class, 3, 0.001d, d -> this.callback.accept(""));
this.brightness = SliderRow.setup(rootComponent, BRIGHTNESS_ID, 0.8d, 0d, 1d, Float.class, 3, 0.001d, d -> this.callback.accept(""));
this.saturation = SliderRow.setup(rootComponent, SATURATION_ID, 1d, 0d, 1d, Float.class, 3, 0.001d, d -> this.callback.accept(""));
this.hueStep = SliderRow.setup(rootComponent, HUE_STEP_ID, 0.05d, config.minRainbowHueStep(), config.maxRainbowHueStep(), Float.class, 3, 0.001d, d -> this.callback.accept(""));
this.hue = SliderRow.setup(rootComponent, HUE_ID, 1d, 0d, 1d, Float.class, 3, 0.025d, d -> this.callback.accept(""));
this.brightness = SliderRow.setup(rootComponent, BRIGHTNESS_ID, 0.8d, 0d, 1d, Float.class, 3, 0.025d, d -> this.callback.accept(""));
this.saturation = SliderRow.setup(rootComponent, SATURATION_ID, 1d, 0d, 1d, Float.class, 3, 0.025d, d -> this.callback.accept(""));
this.hueStep = SliderRow.setup(rootComponent, HUE_STEP_ID, 0.05d, config.minRainbowHueStep(), config.maxRainbowHueStep(), Float.class, 3, 0.005d, d -> this.callback.accept(""));
}

@Override
Expand Down

0 comments on commit baf3d45

Please sign in to comment.