From 25fc8bae8f6c5b358b0b554123637ba4097ebaa3 Mon Sep 17 00:00:00 2001 From: SpaiR Date: Tue, 28 Feb 2023 19:02:41 +0200 Subject: [PATCH] [API] Make all `imgui.type` classes to implement `Comparable<>` interface --- .../src/main/java/imgui/type/ImBoolean.java | 8 ++++- .../src/main/java/imgui/type/ImDouble.java | 8 ++++- .../src/main/java/imgui/type/ImFloat.java | 8 ++++- .../src/main/java/imgui/type/ImInt.java | 8 ++++- .../src/main/java/imgui/type/ImLong.java | 8 ++++- .../src/main/java/imgui/type/ImShort.java | 8 ++++- .../src/main/java/imgui/type/ImString.java | 32 +++++++++++++------ 7 files changed, 64 insertions(+), 16 deletions(-) diff --git a/imgui-binding/src/main/java/imgui/type/ImBoolean.java b/imgui-binding/src/main/java/imgui/type/ImBoolean.java index a5a9e899..fc4a5725 100644 --- a/imgui-binding/src/main/java/imgui/type/ImBoolean.java +++ b/imgui-binding/src/main/java/imgui/type/ImBoolean.java @@ -1,6 +1,6 @@ package imgui.type; -public final class ImBoolean implements Cloneable { +public final class ImBoolean implements Cloneable, Comparable { private final boolean[] data = new boolean[]{false}; public ImBoolean() { @@ -53,7 +53,13 @@ public int hashCode() { } @Override + @SuppressWarnings("MethodDoesntCallSuperMethod") public ImBoolean clone() { return new ImBoolean(this); } + + @Override + public int compareTo(final ImBoolean o) { + return Boolean.compare(get(), o.get()); + } } diff --git a/imgui-binding/src/main/java/imgui/type/ImDouble.java b/imgui-binding/src/main/java/imgui/type/ImDouble.java index e83a232e..017d8824 100644 --- a/imgui-binding/src/main/java/imgui/type/ImDouble.java +++ b/imgui-binding/src/main/java/imgui/type/ImDouble.java @@ -1,6 +1,6 @@ package imgui.type; -public final class ImDouble implements Cloneable { +public final class ImDouble implements Cloneable, Comparable { private final double[] data = new double[]{0.0d}; public ImDouble() { @@ -53,7 +53,13 @@ public int hashCode() { } @Override + @SuppressWarnings("MethodDoesntCallSuperMethod") public ImDouble clone() { return new ImDouble(this); } + + @Override + public int compareTo(final ImDouble o) { + return Double.compare(get(), o.get()); + } } diff --git a/imgui-binding/src/main/java/imgui/type/ImFloat.java b/imgui-binding/src/main/java/imgui/type/ImFloat.java index 6387fd27..82776c02 100644 --- a/imgui-binding/src/main/java/imgui/type/ImFloat.java +++ b/imgui-binding/src/main/java/imgui/type/ImFloat.java @@ -1,6 +1,6 @@ package imgui.type; -public final class ImFloat implements Cloneable { +public final class ImFloat implements Cloneable, Comparable { private final float[] data = new float[]{0}; public ImFloat() { @@ -53,7 +53,13 @@ public int hashCode() { } @Override + @SuppressWarnings("MethodDoesntCallSuperMethod") public ImFloat clone() { return new ImFloat(this); } + + @Override + public int compareTo(final ImFloat o) { + return Float.compare(get(), o.get()); + } } diff --git a/imgui-binding/src/main/java/imgui/type/ImInt.java b/imgui-binding/src/main/java/imgui/type/ImInt.java index 195688a6..17c1c420 100644 --- a/imgui-binding/src/main/java/imgui/type/ImInt.java +++ b/imgui-binding/src/main/java/imgui/type/ImInt.java @@ -1,6 +1,6 @@ package imgui.type; -public final class ImInt implements Cloneable { +public final class ImInt implements Cloneable, Comparable { private final int[] data = new int[]{0}; public ImInt() { @@ -53,7 +53,13 @@ public int hashCode() { } @Override + @SuppressWarnings("MethodDoesntCallSuperMethod") public ImInt clone() { return new ImInt(this); } + + @Override + public int compareTo(final ImInt o) { + return Integer.compare(get(), o.get()); + } } diff --git a/imgui-binding/src/main/java/imgui/type/ImLong.java b/imgui-binding/src/main/java/imgui/type/ImLong.java index 191a8055..22a5efef 100644 --- a/imgui-binding/src/main/java/imgui/type/ImLong.java +++ b/imgui-binding/src/main/java/imgui/type/ImLong.java @@ -1,6 +1,6 @@ package imgui.type; -public final class ImLong implements Cloneable { +public final class ImLong implements Cloneable, Comparable { private final long[] data = new long[]{0}; public ImLong() { @@ -53,7 +53,13 @@ public int hashCode() { } @Override + @SuppressWarnings("MethodDoesntCallSuperMethod") public ImLong clone() { return new ImLong(this); } + + @Override + public int compareTo(final ImLong o) { + return Long.compare(get(), o.get()); + } } diff --git a/imgui-binding/src/main/java/imgui/type/ImShort.java b/imgui-binding/src/main/java/imgui/type/ImShort.java index a253d36e..f180ce20 100644 --- a/imgui-binding/src/main/java/imgui/type/ImShort.java +++ b/imgui-binding/src/main/java/imgui/type/ImShort.java @@ -1,6 +1,6 @@ package imgui.type; -public final class ImShort implements Cloneable { +public final class ImShort implements Cloneable, Comparable { private final short[] data = new short[]{0}; public ImShort() { @@ -53,7 +53,13 @@ public int hashCode() { } @Override + @SuppressWarnings("MethodDoesntCallSuperMethod") public ImShort clone() { return new ImShort(this); } + + @Override + public int compareTo(final ImShort o) { + return Short.compare(get(), o.get()); + } } diff --git a/imgui-binding/src/main/java/imgui/type/ImString.java b/imgui-binding/src/main/java/imgui/type/ImString.java index e4c800e4..5a527d79 100644 --- a/imgui-binding/src/main/java/imgui/type/ImString.java +++ b/imgui-binding/src/main/java/imgui/type/ImString.java @@ -4,9 +4,9 @@ import java.util.Objects; /** - * Wrapper for {@link String} to use inside of th Dear ImGui input widgets. + * Wrapper for {@link String} to use inside th Dear ImGui input widgets. */ -public final class ImString implements Cloneable { +public final class ImString implements Cloneable, Comparable { /** * Default size of the inner buffer, if {@link ImString} created with a constructor without args. */ @@ -17,8 +17,8 @@ public final class ImString implements Cloneable { public static final short CARET_LEN = 1; /** - * Configuration class to setup some specific behaviour for current string. - * This is useful when string used inside of ImGui#InputText*() methods. + * Configuration class to set up some specific behaviour for current string. + * This is useful when string used inside ImGui#InputText*() methods. */ public final InputData inputData = new InputData(); @@ -32,6 +32,7 @@ public ImString() { this(DEFAULT_LENGTH); } + @SuppressWarnings("CopyConstructorMissesField") public ImString(final ImString imString) { this(imString.text, imString.data.length); this.inputData.allowedChars = imString.inputData.allowedChars; @@ -44,6 +45,7 @@ public ImString(final ImString imString) { /** * Creates an {@link ImString} instance with provided size for the inner buffer. + * * @param length size of the inner buffer to use */ public ImString(final int length) { @@ -53,6 +55,7 @@ public ImString(final int length) { /** * Creates an {@link ImString} instance from provided string. * Inner buffer size will be equal to the length of the string + {@link ImString#CARET_LEN}. + * * @param text string to create a new {@link ImString} */ public ImString(final String text) { @@ -61,7 +64,8 @@ public ImString(final String text) { /** * Create an {@link ImString} instance from provided string with custom size for the inner buffer. - * @param text string to a create a new {@link ImString} + * + * @param text string to a creation a new {@link ImString} * @param length custom size for the inner buffer */ public ImString(final String text, final int length) { @@ -140,8 +144,9 @@ byte[] resizeInternal(final int newSize) { } /** - * Get the length of the text inside of the data buffer. - * @return length of the text inside of the data buffer + * Get the length of the text inside the data buffer. + * + * @return length of the text inside the data buffer */ public int getLength() { return get().length(); @@ -149,6 +154,7 @@ public int getLength() { /** * Get the size of the data buffer. Buffer size will always have '+1' to its size, since it's used by the Dear ImGui to draw a caret char. + * * @return size of the data buffer */ public int getBufferSize() { @@ -156,14 +162,14 @@ public int getBufferSize() { } /** - * @return true if the length of the text inside of the data buffer is 0 + * @return true if the length of the text inside the data buffer is 0 */ public boolean isEmpty() { return getLength() == 0; } /** - * @return true if the length of the text inside of the data buffer is not 0 + * @return true if the length of the text inside the data buffer is not 0 */ public boolean isNotEmpty() { return !isEmpty(); @@ -199,10 +205,16 @@ public int hashCode() { } @Override + @SuppressWarnings("MethodDoesntCallSuperMethod") public ImString clone() { return new ImString(this); } + @Override + public int compareTo(final ImString o) { + return get().compareTo(o.get()); + } + /** * Use this class to customize your ImGui input. */ @@ -216,7 +228,7 @@ public static final class InputData { public String allowedChars = ""; /** - * If true, then string will be resized during the the {@link imgui.ImGui#inputText} and {@link imgui.ImGui#inputTextMultiline} methods. + * If true, then string will be resized during the {@link imgui.ImGui#inputText} and {@link imgui.ImGui#inputTextMultiline} methods. * Alternatively you can provide {@link imgui.flag.ImGuiInputTextFlags#CallbackResize} flag to the input text widgets to enable string resizing. * Resize factor of the string could be modified by changing {@link #resizeFactor} field. */