Skip to content

Commit aca706e

Browse files
committed
Implement basic version of grid track sizing algroithm
DEVSIX-8324
1 parent 5805b4e commit aca706e

20 files changed

+929
-898
lines changed

layout/src/main/java/com/itextpdf/layout/properties/GridValue.java

Lines changed: 115 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,124 +27,182 @@ This file is part of the iText (R) project.
2727
* grid-auto-columns/rows properties and the type it is measured in.
2828
*/
2929
public class GridValue {
30-
/**
31-
* The type of the value.
32-
*/
33-
private GridValueType type;
34-
/**
35-
* The flexible value.
36-
*/
37-
private Float flex;
38-
/**
39-
* The sizing value.
40-
*/
41-
private SizingValue sizingValue;
30+
private static final GridValue MIN_CONTENT_VALUE = new GridValue(SizingValueType.MIN_CONTENT);
31+
private static final GridValue MAX_CONTENT_VALUE = new GridValue(SizingValueType.MAX_CONTENT);
32+
private static final GridValue AUTO_VALUE = new GridValue(SizingValueType.AUTO);
33+
34+
private SizingValueType type;
35+
private Float value;
4236

43-
/**
44-
* Creates a new empty instance of {@link GridValue} class.
45-
*/
4637
private GridValue() {
47-
// do nothing
38+
// Do nothing
39+
}
40+
41+
private GridValue(SizingValueType type) {
42+
this.type = type;
4843
}
4944

5045
/**
51-
* Creates an instance of {@link GridValue} with {@link SizingValue} value.
46+
* Creates an instance of {@link GridValue} with point value.
5247
*
53-
* @param sizingValue the sizing value
48+
* @param value the point value
5449
*
5550
* @return the grid value instance
5651
*/
57-
public static GridValue createSizeValue(SizingValue sizingValue) {
52+
public static GridValue createPointValue(float value) {
5853
GridValue result = new GridValue();
59-
result.sizingValue = sizingValue;
60-
result.type = GridValueType.SIZING;
54+
result.type = SizingValueType.POINT;
55+
result.value = value;
6156
return result;
6257
}
6358

6459
/**
65-
* Creates an instance of {@link GridValue} with {@link UnitValue} inside of {@link SizingValue} value.
60+
* Creates an instance of {@link GridValue} with percent value.
6661
*
67-
* @param unitValue the unit value
62+
* @param value the percent value
6863
*
6964
* @return the grid value instance
7065
*/
71-
public static GridValue createUnitValue(UnitValue unitValue) {
66+
public static GridValue createPercentValue(float value) {
7267
GridValue result = new GridValue();
73-
result.sizingValue = SizingValue.createUnitValue(unitValue);
74-
result.type = GridValueType.SIZING;
68+
result.type = SizingValueType.PERCENT;
69+
result.value = value;
7570
return result;
7671
}
7772

7873
/**
79-
* Creates an instance of {@link GridValue} with flex value.
74+
* Creates an instance of {@link GridValue} with min-content value.
75+
*
76+
* @return the grid value instance
77+
*/
78+
public static GridValue createMinContentValue() {
79+
return MIN_CONTENT_VALUE;
80+
}
81+
82+
/**
83+
* Creates an instance of {@link GridValue} with max-content value.
84+
*
85+
* @return the grid value instance
86+
*/
87+
public static GridValue createMaxContentValue() {
88+
return MAX_CONTENT_VALUE;
89+
}
90+
91+
/**
92+
* Creates an instance of {@link GridValue} with auto value.
93+
*
94+
* @return the grid value instance
95+
*/
96+
public static GridValue createAutoValue() {
97+
return AUTO_VALUE;
98+
}
99+
100+
/**
101+
* Creates an instance of {@link GridValue} with flexible value.
80102
*
81-
* @param flex the flex value
103+
* @param value the flexible value
82104
*
83105
* @return the grid value instance
84106
*/
85-
public static GridValue createFlexValue(float flex) {
107+
public static GridValue createFlexValue(float value) {
86108
GridValue result = new GridValue();
87-
result.flex = flex;
88-
result.type = GridValueType.FLEX;
109+
result.type = SizingValueType.FLEX;
110+
result.value = value;
89111
return result;
90112
}
91113

114+
92115
/**
93-
* Checks whether the value is absolute.
116+
* Checks whether the value is absolute.
94117
*
95118
* @return {@code true} if absolute, {@code false} otherwise
96119
*/
97-
public boolean isAbsoluteValue() {
98-
return type == GridValueType.SIZING && sizingValue.isAbsoluteValue();
120+
public boolean isPointValue() {
121+
return type == SizingValueType.POINT;
99122
}
100123

101124
/**
102-
* Gets absolute value, if exists.
125+
* Checks whether the value is percent.
103126
*
104-
* @return absolute value, or {@code null} if value is relative
127+
* @return {@code true} if percent, {@code false} otherwise
105128
*/
106-
public Float getAbsoluteValue() {
107-
if (isAbsoluteValue()) {
108-
return sizingValue.getAbsoluteValue();
109-
}
110-
return null;
129+
public boolean isPercentValue() {
130+
return type == SizingValueType.PERCENT;
111131
}
112132

113133
/**
114-
* Gets type of value.
134+
* Checks whether the value is auto.
115135
*
116-
* @return the type of the value
136+
* @return {@code true} if auto, {@code false} otherwise
117137
*/
118-
public GridValueType getType() {
119-
return type;
138+
public boolean isAutoValue() {
139+
return type == SizingValueType.AUTO;
120140
}
121141

122142
/**
123-
* Gets the flex value.
143+
* Checks whether the value is min-content.
124144
*
125-
* @return the flex value of {@code null} if another value type is stored
145+
* @return {@code true} if min-content, {@code false} otherwise
126146
*/
127-
public Float getFlexValue() {
128-
return flex;
147+
public boolean isMinContentValue() {
148+
return type == SizingValueType.MIN_CONTENT;
129149
}
130150

131151
/**
132-
* Gets the sizing value.
152+
* Checks whether the value is max-content.
133153
*
134-
* @return the instance of {@link SizingValue} or {@code null} if another value type is stored
154+
* @return {@code true} if max-content, {@code false} otherwise
135155
*/
136-
public SizingValue getSizingValue() {
137-
return sizingValue;
156+
public boolean isMaxContentValue() {
157+
return type == SizingValueType.MAX_CONTENT;
138158
}
139159

140160
/**
141-
* Enum of grid value types.
161+
* Checks whether the value is flexible.
162+
*
163+
* @return {@code true} if flexible, {@code false} otherwise
142164
*/
143-
public enum GridValueType {
165+
public boolean isFlexibleValue() {
166+
return type == SizingValueType.FLEX;
167+
}
168+
169+
/**
170+
* Gets value, if exists.
171+
*
172+
* @return the value, or {@code null} if there is no value
173+
*/
174+
public Float getValue() {
175+
return value;
176+
}
177+
178+
/**
179+
* Enum of sizing value types.
180+
*/
181+
private enum SizingValueType {
182+
/**
183+
* Type which presents absolute point value.
184+
*/
185+
POINT,
186+
/**
187+
* Type which presents relative percent value.
188+
*/
189+
PERCENT,
190+
/**
191+
* Type which presents relative auto value.
192+
*/
193+
AUTO,
194+
/**
195+
* Type which presents relative min content value.
196+
*/
197+
MIN_CONTENT,
198+
/**
199+
* Type which presents relative max content value.
200+
*/
201+
MAX_CONTENT,
144202
/**
145-
* Type which presents {@link SizingValue} value.
203+
* Type which presents relative fit content function value.
146204
*/
147-
SIZING,
205+
FIT_CONTENT,
148206
/**
149207
* Type which presents relative flexible value.
150208
*/

layout/src/main/java/com/itextpdf/layout/properties/SizingValue.java

Lines changed: 0 additions & 159 deletions
This file was deleted.

0 commit comments

Comments
 (0)