2525import java .util .List ;
2626
2727/**
28- * An arrangement of {@link Keyline}s that are positioned along a scrolling axis.
28+ * An arrangement of keylines that are positioned along a scrolling axis.
2929 *
30- * <p>This class is the structure used to tell a scrolling item how it should be masked, offset, or
31- * treated, at certain points along the scrolling axis.
30+ * <p>This class is the model used to tell a scrolling item how it should be masked, offset, or
31+ * treated at certain points (keylines) along the scrolling axis.
3232 *
33- * <p>KeylineState enforces the following rules:
33+ * <p>Keylines are points located along a scrolling axis, relative to the scrolling container's
34+ * bounds, that tell an item how it should be treated (masked, offset) when it's center is located
35+ * at a keyline. When between keylines, a scrolling item is treated by interpolating between the
36+ * states of its nearest surrounding keylines. When put together, a KeylineState contains all
37+ * keylines associated with a scrolling container and is able to tell a scrolling item how it should
38+ * be treated at any point (as the item moves) along the scrolling axis, creating a fluid
39+ * interpolated motion tied to scroll position.
3440 *
35- * <ol>
36- * <li>There must be one or two keylines marked as "focal". These define the range along the
37- * scrolling axis where an item or items are considered fully unmasked and viewable.
38- * <li>Keylines can only remain the same size or increase in size as they approach the focal
39- * range. Keylines before the focal range cannot be larger than a focal item.
40- * <li>Keylines can only remain the same size or decrease in size as they move away from the focal
41- * range. Keylines after the focal range cannot be larger than a focal item.
42- * </ol>
41+ * <p>Keylines can be either focal or non-focal. A focal keyline is a keyline where items are
42+ * considered visible or interactable in their fullest form. This usually means where items will be
43+ * fully unmaksed and viewable. There must be at least one focal keyline in a KeylineState. The
44+ * focal keylines are important for usability and alignment. Start-aligned configurations should
45+ * place focal keylines at the beginning of the scroll container, center-aligned configurations at
46+ * the center of the scroll container, etc.
4347 */
4448final class KeylineState {
4549
@@ -48,7 +52,7 @@ final class KeylineState {
4852 private final int firstFocalKeylineIndex ;
4953 private final int lastFocalKeylineIndex ;
5054
51- KeylineState (
55+ private KeylineState (
5256 float itemSize ,
5357 List <Keyline > keylines ,
5458 int firstFocalKeylineIndex ,
@@ -167,6 +171,26 @@ static KeylineState reverse(KeylineState keylineState) {
167171 return builder .build ();
168172 }
169173
174+ /**
175+ * A builder used to construct a {@link KeylineState}.
176+ *
177+ * <p>{@link KeylineState.Builder} enforces the following rules:
178+ *
179+ * <ol>
180+ * <li>There must be one or more keylines marked as "focal". These are keylines along the
181+ * scrolling axis where an item or items are considered fully unmasked and viewable.
182+ * <li>Focal keylines must be added adjacent to each other. A non-focal keyline cannot be added
183+ * between focal keylines.
184+ * <li>A keyline's masked item size can only remain the same size or increase in size as it
185+ * approaches the focal range. A keyline's masked item size before the focal range cannot be
186+ * larger than a focal keyline's masked item size.
187+ * <li>A keyline's masked item size can only remain the same size or decrease in size as it
188+ * moves away from the focal range. A keyline's masked item size after the focal range
189+ * cannot be larger than a focal keyline's masked item size.
190+ * </ol>
191+ *
192+ * Typically there should be a keyline for every visible item in the scrolling container.
193+ */
170194 static final class Builder {
171195
172196 private static final int NO_INDEX = -1 ;
@@ -187,16 +211,18 @@ static final class Builder {
187211 /**
188212 * Creates a new {@link KeylineState.Builder}.
189213 *
190- * @param itemSize the size of a fully unmaksed item. All mask values will be a percentage of
191- * this size.
214+ * @param itemSize The size of a fully unmaksed item. This is the size that will be used by the
215+ * carousel to measure and lay out all children, overriding each child's desired size.
192216 */
193217 Builder (float itemSize ) {
194218 this .itemSize = itemSize ;
195219 }
196220
197221 /**
198- * Adds a point along the scrolling axis where an object should be masked by the given {@code
199- * mask} percentage.
222+ * Adds a keyline along the scrolling axis where an object should be masked by the given {@code
223+ * mask} and positioned at {@code offsetLoc}.
224+ *
225+ * @see #addKeyline(float, float, float, boolean)
200226 */
201227 @ NonNull
202228 @ CanIgnoreReturnValue
@@ -206,18 +232,21 @@ Builder addKeyline(
206232 }
207233
208234 /**
209- * Adds a point along the scrolling axis where an object should be masked by the given {@code
210- * mask} percentage .
235+ * Adds a keyline along the scrolling axis where an object should be masked by the given {@code
236+ * mask} and positioned at {@code offsetLoc} .
211237 *
212- * <p>Keylines are added in order! Keylines added at the beginning of the list will appear at
213- * the start of the scroll axis.
238+ * <p>Note that calls to {@link #addKeyline(float, float, float, boolean)} and {@link
239+ * #addKeylineRange(float, float, float, int)} are added in order. Typically, this means
240+ * keylines should be added in order of ascending {@code offsetLoc}.
214241 *
215- * @param offsetLoc The location along the axis where this keyline is positioned.
216- * @param mask The percentage of {@code itemSize} that a child should be masked by when its
217- * center is at {@code loc}.
218- * @param maskedItemSize The total size of this item when masked. This might differ from the
219- * masked size depending on how margins are included in the mask.
220- * @param isFocal Whether this keyline marks the beginning or end of the focal range.
242+ * @param offsetLoc The location of this keyline along the scrolling axis. An offsetLoc of 0
243+ * will be at the start of the scroll container.
244+ * @param mask The percentage of a child's full size that it should be masked by when its center
245+ * is at {@code offsetLoc}. 0 is fully unmasked and 1 is fully masked.
246+ * @param maskedItemSize The total size of this item when masked. This might differ from {@code
247+ * itemSize - (itemSize * mask)} depending on how margins are included in the {@code mask}.
248+ * @param isFocal Whether this keyline is considered part of the focal range. Typically, this is
249+ * when {@code mask} is equal to 0.
221250 */
222251 @ NonNull
223252 @ CanIgnoreReturnValue
@@ -266,8 +295,11 @@ Builder addKeyline(
266295 }
267296
268297 /**
269- * Adds a range along the scrolling axis where an object should be masked by {@code mask} when
270- * its center is between {@code offsetLoc} and {@code offsetLoc * (maskedItemSize + count)}.
298+ * Adds a range of keylines along the scrolling axis where an item should be masked by {@code
299+ * mask} when its center is between {@code offsetLoc} and {@code offsetLoc + (maskedItemSize *
300+ * count)}.
301+ *
302+ * @see #addKeylineRange(float, float, float, int, boolean)
271303 */
272304 @ NonNull
273305 @ CanIgnoreReturnValue
@@ -281,21 +313,22 @@ Builder addKeylineRange(
281313
282314 /**
283315 * Adds a range along the scrolling axis where an object should be masked by {@code mask} when
284- * its center is between {@code offsetLoc} and {@code offsetLoc * (maskedItemSize + count)}.
316+ * its center is between {@code offsetLoc} and {@code offsetLoc + (maskedItemSize * count)}.
285317 *
286- * <p>Keyline ranges are added in order! Keyline ranges added at the beginning of the list will
287- * appear at the start of the scroll axis. Also note that keylines can only increase in size or
288- * remain the same size as they approach the focal range and decrease in size or remain the same
289- * size as they exit the focal range.
318+ * <p>Note that calls to {@link #addKeyline(float, float, float, boolean)} and {@link
319+ * #addKeylineRange(float, float, float, int)} are added in order. Typically, this means
320+ * keylines should be added in order of ascending {@code offsetLoc}.
290321 *
291- * @param offsetLoc location along the axis where this range starts.
292- * @param mask The percentage of {@code itemSize} that a child should be masked by when its
293- * center is within this keyline range. 0F is fully unmasked and 1F is fully masked.
294- * @param maskedItemSize The total size of this item when masked. This might differ from the
295- * masked size depending on how margins are included in the mask.
322+ * @param offsetLoc the location along the scrolling axis where this range starts. The range's
323+ * end will be defined by {@code offsetLoc + (maskedItemSize * count)}. An offsetLoc of 0
324+ * will be at the start of the scrolling container.
325+ * @param mask the percentage of a child's full size that it should be masked by when its center
326+ * is within the keyline range. 0 is fully unmasked and 1 is fully masked.
327+ * @param maskedItemSize the total size of this item when masked. This might differ from {@code
328+ * itemSize - (itemSize * mask)} depending on how margins are included in the {@code mask}.
296329 * @param count The number of items that should be in this range at a time.
297- * @param isFocal Whether this range should be used to align the keylines within the scroll
298- * container .
330+ * @param isFocal whether this keyline range is the focal range. Typically this is when {@code
331+ * mask} is equal to 0 .
299332 */
300333 @ NonNull
301334 @ CanIgnoreReturnValue
@@ -317,6 +350,7 @@ Builder addKeylineRange(
317350 return this ;
318351 }
319352
353+ /** Builds and returns a {@link KeylineState}. */
320354 @ NonNull
321355 KeylineState build () {
322356 if (tmpFirstFocalKeyline == null ) {
@@ -375,7 +409,7 @@ static final class Keyline {
375409 * it should be in the state defined by {@code locOffset} and {@code mask}.
376410 * @param locOffset The location within the carousel where an item should be when its center is
377411 * at {@code loc}.
378- * @param mask The percentage of this items full width that it should be masked by when its
412+ * @param mask The percentage of this items full size that it should be masked by when its
379413 * center is at {@code loc}.
380414 * @param maskedItemSize The size of this item when masked.
381415 */
0 commit comments