Skip to content

Commit

Permalink
[API] Make all imgui.type classes to implement Comparable<> inter…
Browse files Browse the repository at this point in the history
…face
  • Loading branch information
SpaiR committed Feb 28, 2023
1 parent 068c1e0 commit 25fc8ba
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 16 deletions.
8 changes: 7 additions & 1 deletion imgui-binding/src/main/java/imgui/type/ImBoolean.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package imgui.type;

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

public ImBoolean() {
Expand Down Expand Up @@ -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());
}
}
8 changes: 7 additions & 1 deletion imgui-binding/src/main/java/imgui/type/ImDouble.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package imgui.type;

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

public ImDouble() {
Expand Down Expand Up @@ -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());
}
}
8 changes: 7 additions & 1 deletion imgui-binding/src/main/java/imgui/type/ImFloat.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package imgui.type;

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

public ImFloat() {
Expand Down Expand Up @@ -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());
}
}
8 changes: 7 additions & 1 deletion imgui-binding/src/main/java/imgui/type/ImInt.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package imgui.type;

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

public ImInt() {
Expand Down Expand Up @@ -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());
}
}
8 changes: 7 additions & 1 deletion imgui-binding/src/main/java/imgui/type/ImLong.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package imgui.type;

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

public ImLong() {
Expand Down Expand Up @@ -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());
}
}
8 changes: 7 additions & 1 deletion imgui-binding/src/main/java/imgui/type/ImShort.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package imgui.type;

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

public ImShort() {
Expand Down Expand Up @@ -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());
}
}
32 changes: 22 additions & 10 deletions imgui-binding/src/main/java/imgui/type/ImString.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImString> {
/**
* Default size of the inner buffer, if {@link ImString} created with a constructor without args.
*/
Expand All @@ -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();

Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -140,30 +144,32 @@ 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();
}

/**
* 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() {
return data.length;
}

/**
* @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();
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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.
*/
Expand Down

0 comments on commit 25fc8ba

Please sign in to comment.