@@ -14,20 +14,12 @@ public final class ImString {
14
14
* Size of ImGui caret which is shown during the input text focus.
15
15
*/
16
16
public static final short CARET_LEN = 1 ;
17
- /**
18
- * Default resize value, used to set up {@link ImString#resizeFactor}.
19
- */
20
- public static final short DEFAULT_RESIZE = 10 ;
21
17
22
18
/**
23
19
* Configuration class to setup some specific behaviour for current string.
24
20
* This is useful when string used inside of ImGui#InputText*() methods.
25
21
*/
26
22
public final ImGuiInputTextData inputData = new ImGuiInputTextData ();
27
- /**
28
- * String will be resized to the value equal to a new size plus this resize factor.
29
- */
30
- public int resizeFactor = DEFAULT_RESIZE ;
31
23
32
24
byte [] data ;
33
25
private String text = "" ;
@@ -75,23 +67,25 @@ public String get() {
75
67
}
76
68
77
69
public void set (final String value ) {
78
- set (value , inputData .isResizable , resizeFactor );
70
+ set (value , inputData .isResizable , inputData . resizeFactor );
79
71
}
80
72
81
73
public void set (final String value , final boolean resize ) {
82
- set (value , resize , resizeFactor );
74
+ set (value , resize , inputData . resizeFactor );
83
75
}
84
76
85
77
public void set (final String value , final boolean resize , final int resizeValue ) {
86
78
final byte [] valueBuff = value .getBytes ();
87
79
final int currentLen = data == null ? 0 : data .length ;
88
80
byte [] newBuff = null ;
89
81
82
+ // If provided value require bigger buffer and we can resize it
90
83
if (resize && (currentLen - CARET_LEN ) < valueBuff .length ) {
91
84
newBuff = new byte [valueBuff .length + resizeValue + CARET_LEN ];
92
85
inputData .size = valueBuff .length ;
93
86
}
94
87
88
+ // If there were no resize and we still need a new buffer
95
89
if (newBuff == null ) {
96
90
newBuff = new byte [currentLen ];
97
91
inputData .size = Math .max (0 , Math .min (valueBuff .length , currentLen - CARET_LEN ));
@@ -103,15 +97,11 @@ public void set(final String value, final boolean resize, final int resizeValue)
103
97
}
104
98
105
99
public void resize (final int newSize ) {
106
- resize (newSize , false );
107
- }
108
-
109
- public void resize (final int newSize , final boolean respectResizeFactor ) {
110
100
if (newSize < data .length ) {
111
101
throw new IllegalArgumentException ("New size should be greater than current size of the buffer" );
112
102
}
113
103
114
- final int size = newSize + CARET_LEN + ( respectResizeFactor ? resizeFactor : 0 ) ;
104
+ final int size = newSize + CARET_LEN ;
115
105
final byte [] newBuffer = new byte [size ];
116
106
System .arraycopy (data , 0 , newBuffer , 0 , data .length );
117
107
data = newBuffer ;
0 commit comments