Skip to content

Commit 25fc8ba

Browse files
committed
[API] Make all imgui.type classes to implement Comparable<> interface
1 parent 068c1e0 commit 25fc8ba

File tree

7 files changed

+64
-16
lines changed

7 files changed

+64
-16
lines changed

imgui-binding/src/main/java/imgui/type/ImBoolean.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package imgui.type;
22

3-
public final class ImBoolean implements Cloneable {
3+
public final class ImBoolean implements Cloneable, Comparable<ImBoolean> {
44
private final boolean[] data = new boolean[]{false};
55

66
public ImBoolean() {
@@ -53,7 +53,13 @@ public int hashCode() {
5353
}
5454

5555
@Override
56+
@SuppressWarnings("MethodDoesntCallSuperMethod")
5657
public ImBoolean clone() {
5758
return new ImBoolean(this);
5859
}
60+
61+
@Override
62+
public int compareTo(final ImBoolean o) {
63+
return Boolean.compare(get(), o.get());
64+
}
5965
}

imgui-binding/src/main/java/imgui/type/ImDouble.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package imgui.type;
22

3-
public final class ImDouble implements Cloneable {
3+
public final class ImDouble implements Cloneable, Comparable<ImDouble> {
44
private final double[] data = new double[]{0.0d};
55

66
public ImDouble() {
@@ -53,7 +53,13 @@ public int hashCode() {
5353
}
5454

5555
@Override
56+
@SuppressWarnings("MethodDoesntCallSuperMethod")
5657
public ImDouble clone() {
5758
return new ImDouble(this);
5859
}
60+
61+
@Override
62+
public int compareTo(final ImDouble o) {
63+
return Double.compare(get(), o.get());
64+
}
5965
}

imgui-binding/src/main/java/imgui/type/ImFloat.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package imgui.type;
22

3-
public final class ImFloat implements Cloneable {
3+
public final class ImFloat implements Cloneable, Comparable<ImFloat> {
44
private final float[] data = new float[]{0};
55

66
public ImFloat() {
@@ -53,7 +53,13 @@ public int hashCode() {
5353
}
5454

5555
@Override
56+
@SuppressWarnings("MethodDoesntCallSuperMethod")
5657
public ImFloat clone() {
5758
return new ImFloat(this);
5859
}
60+
61+
@Override
62+
public int compareTo(final ImFloat o) {
63+
return Float.compare(get(), o.get());
64+
}
5965
}

imgui-binding/src/main/java/imgui/type/ImInt.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package imgui.type;
22

3-
public final class ImInt implements Cloneable {
3+
public final class ImInt implements Cloneable, Comparable<ImInt> {
44
private final int[] data = new int[]{0};
55

66
public ImInt() {
@@ -53,7 +53,13 @@ public int hashCode() {
5353
}
5454

5555
@Override
56+
@SuppressWarnings("MethodDoesntCallSuperMethod")
5657
public ImInt clone() {
5758
return new ImInt(this);
5859
}
60+
61+
@Override
62+
public int compareTo(final ImInt o) {
63+
return Integer.compare(get(), o.get());
64+
}
5965
}

imgui-binding/src/main/java/imgui/type/ImLong.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package imgui.type;
22

3-
public final class ImLong implements Cloneable {
3+
public final class ImLong implements Cloneable, Comparable<ImLong> {
44
private final long[] data = new long[]{0};
55

66
public ImLong() {
@@ -53,7 +53,13 @@ public int hashCode() {
5353
}
5454

5555
@Override
56+
@SuppressWarnings("MethodDoesntCallSuperMethod")
5657
public ImLong clone() {
5758
return new ImLong(this);
5859
}
60+
61+
@Override
62+
public int compareTo(final ImLong o) {
63+
return Long.compare(get(), o.get());
64+
}
5965
}

imgui-binding/src/main/java/imgui/type/ImShort.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package imgui.type;
22

3-
public final class ImShort implements Cloneable {
3+
public final class ImShort implements Cloneable, Comparable<ImShort> {
44
private final short[] data = new short[]{0};
55

66
public ImShort() {
@@ -53,7 +53,13 @@ public int hashCode() {
5353
}
5454

5555
@Override
56+
@SuppressWarnings("MethodDoesntCallSuperMethod")
5657
public ImShort clone() {
5758
return new ImShort(this);
5859
}
60+
61+
@Override
62+
public int compareTo(final ImShort o) {
63+
return Short.compare(get(), o.get());
64+
}
5965
}

imgui-binding/src/main/java/imgui/type/ImString.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import java.util.Objects;
55

66
/**
7-
* Wrapper for {@link String} to use inside of th Dear ImGui input widgets.
7+
* Wrapper for {@link String} to use inside th Dear ImGui input widgets.
88
*/
9-
public final class ImString implements Cloneable {
9+
public final class ImString implements Cloneable, Comparable<ImString> {
1010
/**
1111
* Default size of the inner buffer, if {@link ImString} created with a constructor without args.
1212
*/
@@ -17,8 +17,8 @@ public final class ImString implements Cloneable {
1717
public static final short CARET_LEN = 1;
1818

1919
/**
20-
* Configuration class to setup some specific behaviour for current string.
21-
* This is useful when string used inside of ImGui#InputText*() methods.
20+
* Configuration class to set up some specific behaviour for current string.
21+
* This is useful when string used inside ImGui#InputText*() methods.
2222
*/
2323
public final InputData inputData = new InputData();
2424

@@ -32,6 +32,7 @@ public ImString() {
3232
this(DEFAULT_LENGTH);
3333
}
3434

35+
@SuppressWarnings("CopyConstructorMissesField")
3536
public ImString(final ImString imString) {
3637
this(imString.text, imString.data.length);
3738
this.inputData.allowedChars = imString.inputData.allowedChars;
@@ -44,6 +45,7 @@ public ImString(final ImString imString) {
4445

4546
/**
4647
* Creates an {@link ImString} instance with provided size for the inner buffer.
48+
*
4749
* @param length size of the inner buffer to use
4850
*/
4951
public ImString(final int length) {
@@ -53,6 +55,7 @@ public ImString(final int length) {
5355
/**
5456
* Creates an {@link ImString} instance from provided string.
5557
* Inner buffer size will be equal to the length of the string + {@link ImString#CARET_LEN}.
58+
*
5659
* @param text string to create a new {@link ImString}
5760
*/
5861
public ImString(final String text) {
@@ -61,7 +64,8 @@ public ImString(final String text) {
6164

6265
/**
6366
* Create an {@link ImString} instance from provided string with custom size for the inner buffer.
64-
* @param text string to a create a new {@link ImString}
67+
*
68+
* @param text string to a creation a new {@link ImString}
6569
* @param length custom size for the inner buffer
6670
*/
6771
public ImString(final String text, final int length) {
@@ -140,30 +144,32 @@ byte[] resizeInternal(final int newSize) {
140144
}
141145

142146
/**
143-
* Get the length of the text inside of the data buffer.
144-
* @return length of the text inside of the data buffer
147+
* Get the length of the text inside the data buffer.
148+
*
149+
* @return length of the text inside the data buffer
145150
*/
146151
public int getLength() {
147152
return get().length();
148153
}
149154

150155
/**
151156
* 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.
157+
*
152158
* @return size of the data buffer
153159
*/
154160
public int getBufferSize() {
155161
return data.length;
156162
}
157163

158164
/**
159-
* @return true if the length of the text inside of the data buffer is 0
165+
* @return true if the length of the text inside the data buffer is 0
160166
*/
161167
public boolean isEmpty() {
162168
return getLength() == 0;
163169
}
164170

165171
/**
166-
* @return true if the length of the text inside of the data buffer is not 0
172+
* @return true if the length of the text inside the data buffer is not 0
167173
*/
168174
public boolean isNotEmpty() {
169175
return !isEmpty();
@@ -199,10 +205,16 @@ public int hashCode() {
199205
}
200206

201207
@Override
208+
@SuppressWarnings("MethodDoesntCallSuperMethod")
202209
public ImString clone() {
203210
return new ImString(this);
204211
}
205212

213+
@Override
214+
public int compareTo(final ImString o) {
215+
return get().compareTo(o.get());
216+
}
217+
206218
/**
207219
* Use this class to customize your ImGui input.
208220
*/
@@ -216,7 +228,7 @@ public static final class InputData {
216228
public String allowedChars = "";
217229

218230
/**
219-
* If true, then string will be resized during the the {@link imgui.ImGui#inputText} and {@link imgui.ImGui#inputTextMultiline} methods.
231+
* If true, then string will be resized during the {@link imgui.ImGui#inputText} and {@link imgui.ImGui#inputTextMultiline} methods.
220232
* Alternatively you can provide {@link imgui.flag.ImGuiInputTextFlags#CallbackResize} flag to the input text widgets to enable string resizing.
221233
* Resize factor of the string could be modified by changing {@link #resizeFactor} field.
222234
*/

0 commit comments

Comments
 (0)