Java Code Examples for com.facebook.yoga.YogaEdge#intValue()

The following examples show how to use com.facebook.yoga.YogaEdge#intValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultInternalNode.java    From litho with Apache License 2.0 5 votes vote down vote up
private void setIsPaddingPercent(YogaEdge edge, boolean isPaddingPercent) {
  if (mIsPaddingPercent == null && isPaddingPercent) {
    mIsPaddingPercent = new boolean[YogaEdge.ALL.intValue() + 1];
  }
  if (mIsPaddingPercent != null) {
    mIsPaddingPercent[edge.intValue()] = isPaddingPercent;
  }
}
 
Example 2
Source File: DefaultInternalNode.java    From litho with Apache License 2.0 4 votes vote down vote up
private boolean isPaddingPercent(YogaEdge edge) {
  return mIsPaddingPercent != null && mIsPaddingPercent[edge.intValue()];
}
 
Example 3
Source File: Edges.java    From litho with Apache License 2.0 4 votes vote down vote up
public boolean set(YogaEdge yogaEdge, float value) {
  final int edgeIntValue = yogaEdge.intValue();
  if (!floatsEqual(getRaw(edgeIntValue), value)) {
    final byte edgeIndex = getIndex(edgeIntValue);

    // If we need to "unset" a previously set edge.
    if (YogaConstants.isUndefined(value)) {
      // UNSET index:
      // Set the 4 bits representing the edge as undefined ('1111').
      mEdgesToValuesIndex |= ((long) UNDEFINED_INDEX << (edgeIntValue * 4));
      mValues[edgeIndex] = YogaConstants.UNDEFINED;

      // If we need to insert a new edge value.
    } else if (edgeIndex == UNDEFINED_INDEX) {
      final byte newIndex = getFirstAvailableIndex();
      if (newIndex >= EDGES_LENGTH) {
        throw new IllegalStateException(
            "The newIndex for the array cannot be bigger than the amount of Yoga Edges.");
      }
      // SETS index:
      // Clear the bits at the index position.
      mEdgesToValuesIndex &= ~((long) (0xF) << (edgeIntValue * 4));
      // Then set the actual 4 bits value of the index. Leaving this as two steps for clarity.
      mEdgesToValuesIndex |= ((long) newIndex << (edgeIntValue * 4));
      mValues[newIndex] = value;

      // Otherwise we need to overwrite an existing value.
    } else {
      mValues[edgeIndex] = value;
    }

    // 1. It moves the right most 3 "4bits set" represeting ALL, VERTICAL and HORIZONTAL
    //    to the first 3 "4bits set" position of our long array (0xFFF).
    // 2. It converts the array from long to int.
    // 3. It inverts the bits of the current array. UNDEFINED_INDEX is 0xF or "1111".
    //    When an UNDEFINED_INDEX is inverted, we expect all zeros "0000".
    // 4. Now the inverted array is masked with 0xFFF to get only the values we
    //    are interested into.
    // 5. If the result is equal to 0, we know that ALL, VERTICAL and HORIZONTAL were
    //    all containing UNDEFINED_INDEXes. If that's not the case, we have an alias
    //    set and will set the mHasAliasesSet flag to true.
    mHasAliasesSet = (~((int) (mEdgesToValuesIndex >> ALIASES_RIGHT_SHIFT)) & ALIASES_MASK) != 0;

    return true;
  }

  return false;
}