|
| 1 | +/* |
| 2 | + * Copyright (c) 2018-present, Facebook, Inc. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the LICENSE |
| 5 | + * file in the root directory of this source tree. |
| 6 | + * |
| 7 | + */ |
| 8 | +package com.facebook.yoga; |
| 9 | + |
| 10 | +import com.facebook.proguard.annotations.DoNotStrip; |
| 11 | +import com.facebook.soloader.SoLoader; |
| 12 | +import java.nio.ByteBuffer; |
| 13 | +import java.nio.ByteOrder; |
| 14 | + |
| 15 | +@DoNotStrip |
| 16 | +public class YogaNodePropertiesHybrid extends YogaNodePropertiesJNI { |
| 17 | + |
| 18 | + static { |
| 19 | + SoLoader.loadLibrary("yoga"); |
| 20 | + } |
| 21 | + |
| 22 | + private ByteBuffer mStyleBuffer; |
| 23 | + |
| 24 | + private static native ByteBuffer jni_getStyleBuffer(long nativePointer); |
| 25 | + |
| 26 | + public YogaNodePropertiesHybrid(YogaNode node) { |
| 27 | + super(node); |
| 28 | + mStyleBuffer = jni_getStyleBuffer(getNativePointer()).order(ByteOrder.LITTLE_ENDIAN); |
| 29 | + } |
| 30 | + |
| 31 | + public YogaNodePropertiesHybrid(YogaNode node, YogaConfig config) { |
| 32 | + super(node, config); |
| 33 | + mStyleBuffer = jni_getStyleBuffer(getNativePointer()).order(ByteOrder.LITTLE_ENDIAN); |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public void setDirection(YogaDirection direction) { |
| 38 | + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleDirection, direction.intValue()); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public void setFlexDirection(YogaFlexDirection flexDirection) { |
| 43 | + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleFlexDirection, flexDirection.intValue()); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public void setJustifyContent(YogaJustify justifyContent) { |
| 48 | + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleJustifyContent, justifyContent.intValue()); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void setAlignItems(YogaAlign alignItems) { |
| 53 | + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleAlignItems, alignItems.intValue()); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public void setAlignSelf(YogaAlign alignSelf) { |
| 58 | + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleAlignSelf, alignSelf.intValue()); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public void setAlignContent(YogaAlign alignContent) { |
| 63 | + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleAlignContent, alignContent.intValue()); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public void setPositionType(YogaPositionType positionType) { |
| 68 | + mStyleBuffer.putInt(YogaNodeMemoryLayout.stylePositionType, positionType.intValue()); |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public void setWrap(YogaWrap flexWrap) { |
| 73 | + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleFlexWrap, flexWrap.intValue()); |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public void setOverflow(YogaOverflow overflow) { |
| 78 | + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleOverflow, overflow.intValue()); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public void setDisplay(YogaDisplay display) { |
| 83 | + mStyleBuffer.putInt(YogaNodeMemoryLayout.styleDisplay, display.intValue()); |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public void setFlex(float flex) { |
| 88 | + YogaNodeMemoryLayout.putOptional(mStyleBuffer, YogaNodeMemoryLayout.styleFlex, flex); |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public void setFlexGrow(float flexGrow) { |
| 93 | + YogaNodeMemoryLayout.putOptional(mStyleBuffer, YogaNodeMemoryLayout.styleFlexGrow, flexGrow); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public void setFlexShrink(float flexShrink) { |
| 98 | + YogaNodeMemoryLayout.putOptional( |
| 99 | + mStyleBuffer, YogaNodeMemoryLayout.styleFlexShrink, flexShrink); |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public void setFlexBasis(float flexBasis) { |
| 104 | + YogaNodeMemoryLayout.putPointValue( |
| 105 | + mStyleBuffer, YogaNodeMemoryLayout.styleFlexBasis, flexBasis); |
| 106 | + } |
| 107 | + |
| 108 | + @Override |
| 109 | + public void setFlexBasisPercent(float percent) { |
| 110 | + YogaNodeMemoryLayout.putPercentValue( |
| 111 | + mStyleBuffer, YogaNodeMemoryLayout.styleFlexBasis, percent); |
| 112 | + } |
| 113 | + |
| 114 | + @Override |
| 115 | + public void setFlexBasisAuto() { |
| 116 | + YogaNodeMemoryLayout.putAutoValue(mStyleBuffer, YogaNodeMemoryLayout.styleFlexBasis); |
| 117 | + } |
| 118 | + |
| 119 | + @Override |
| 120 | + public void setMargin(YogaEdge edge, float margin) { |
| 121 | + mEdgeSetFlag |= MARGIN; |
| 122 | + YogaNodeMemoryLayout.putPointValue( |
| 123 | + mStyleBuffer, YogaNodeMemoryLayout.styleMarginOffset(edge), margin); |
| 124 | + } |
| 125 | + |
| 126 | + @Override |
| 127 | + public void setMarginPercent(YogaEdge edge, float percent) { |
| 128 | + mEdgeSetFlag |= MARGIN; |
| 129 | + YogaNodeMemoryLayout.putPercentValue( |
| 130 | + mStyleBuffer, YogaNodeMemoryLayout.styleMarginOffset(edge), percent); |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public void setMarginAuto(YogaEdge edge) { |
| 135 | + mEdgeSetFlag |= MARGIN; |
| 136 | + YogaNodeMemoryLayout.putAutoValue(mStyleBuffer, YogaNodeMemoryLayout.styleMarginOffset(edge)); |
| 137 | + } |
| 138 | + |
| 139 | + @Override |
| 140 | + public void setPadding(YogaEdge edge, float padding) { |
| 141 | + mEdgeSetFlag |= PADDING; |
| 142 | + YogaNodeMemoryLayout.putPointValue( |
| 143 | + mStyleBuffer, YogaNodeMemoryLayout.stylePaddingOffset(edge), padding); |
| 144 | + } |
| 145 | + |
| 146 | + @Override |
| 147 | + public void setPaddingPercent(YogaEdge edge, float percent) { |
| 148 | + mEdgeSetFlag |= PADDING; |
| 149 | + YogaNodeMemoryLayout.putPercentValue( |
| 150 | + mStyleBuffer, YogaNodeMemoryLayout.stylePaddingOffset(edge), percent); |
| 151 | + } |
| 152 | + |
| 153 | + @Override |
| 154 | + public void setBorder(YogaEdge edge, float border) { |
| 155 | + mEdgeSetFlag |= BORDER; |
| 156 | + YogaNodeMemoryLayout.putPointValue( |
| 157 | + mStyleBuffer, YogaNodeMemoryLayout.styleBorderOffset(edge), border); |
| 158 | + } |
| 159 | + |
| 160 | + @Override |
| 161 | + public void setPosition(YogaEdge edge, float position) { |
| 162 | + mHasSetPosition = true; |
| 163 | + YogaNodeMemoryLayout.putPointValue( |
| 164 | + mStyleBuffer, YogaNodeMemoryLayout.stylePositionOffset(edge), position); |
| 165 | + } |
| 166 | + |
| 167 | + @Override |
| 168 | + public void setPositionPercent(YogaEdge edge, float percent) { |
| 169 | + mHasSetPosition = true; |
| 170 | + YogaNodeMemoryLayout.putPercentValue( |
| 171 | + mStyleBuffer, YogaNodeMemoryLayout.stylePositionOffset(edge), percent); |
| 172 | + } |
| 173 | + |
| 174 | + @Override |
| 175 | + public void setWidth(float width) { |
| 176 | + YogaNodeMemoryLayout.putPointValue(mStyleBuffer, YogaNodeMemoryLayout.styleWidth, width); |
| 177 | + } |
| 178 | + |
| 179 | + @Override |
| 180 | + public void setWidthPercent(float percent) { |
| 181 | + YogaNodeMemoryLayout.putPercentValue(mStyleBuffer, YogaNodeMemoryLayout.styleWidth, percent); |
| 182 | + } |
| 183 | + |
| 184 | + @Override |
| 185 | + public void setWidthAuto() { |
| 186 | + YogaNodeMemoryLayout.putAutoValue(mStyleBuffer, YogaNodeMemoryLayout.styleWidth); |
| 187 | + } |
| 188 | + |
| 189 | + @Override |
| 190 | + public void setHeight(float height) { |
| 191 | + YogaNodeMemoryLayout.putPointValue(mStyleBuffer, YogaNodeMemoryLayout.styleHeight, height); |
| 192 | + } |
| 193 | + |
| 194 | + @Override |
| 195 | + public void setHeightPercent(float percent) { |
| 196 | + YogaNodeMemoryLayout.putPercentValue(mStyleBuffer, YogaNodeMemoryLayout.styleHeight, percent); |
| 197 | + } |
| 198 | + |
| 199 | + @Override |
| 200 | + public void setHeightAuto() { |
| 201 | + YogaNodeMemoryLayout.putAutoValue(mStyleBuffer, YogaNodeMemoryLayout.styleHeight); |
| 202 | + } |
| 203 | + |
| 204 | + @Override |
| 205 | + public void setMinWidth(float minWidth) { |
| 206 | + YogaNodeMemoryLayout.putPointValue(mStyleBuffer, YogaNodeMemoryLayout.styleMinWidth, minWidth); |
| 207 | + } |
| 208 | + |
| 209 | + @Override |
| 210 | + public void setMinWidthPercent(float percent) { |
| 211 | + YogaNodeMemoryLayout.putPercentValue(mStyleBuffer, YogaNodeMemoryLayout.styleMinWidth, percent); |
| 212 | + } |
| 213 | + |
| 214 | + @Override |
| 215 | + public void setMinHeight(float minHeight) { |
| 216 | + YogaNodeMemoryLayout.putPointValue( |
| 217 | + mStyleBuffer, YogaNodeMemoryLayout.styleMinHeight, minHeight); |
| 218 | + } |
| 219 | + |
| 220 | + @Override |
| 221 | + public void setMinHeightPercent(float percent) { |
| 222 | + YogaNodeMemoryLayout.putPercentValue( |
| 223 | + mStyleBuffer, YogaNodeMemoryLayout.styleMinHeight, percent); |
| 224 | + } |
| 225 | + |
| 226 | + @Override |
| 227 | + public void setMaxWidth(float maxWidth) { |
| 228 | + YogaNodeMemoryLayout.putPointValue(mStyleBuffer, YogaNodeMemoryLayout.styleMaxWidth, maxWidth); |
| 229 | + } |
| 230 | + |
| 231 | + @Override |
| 232 | + public void setMaxWidthPercent(float percent) { |
| 233 | + YogaNodeMemoryLayout.putPercentValue(mStyleBuffer, YogaNodeMemoryLayout.styleMaxWidth, percent); |
| 234 | + } |
| 235 | + |
| 236 | + @Override |
| 237 | + public void setMaxHeight(float maxHeight) { |
| 238 | + YogaNodeMemoryLayout.putPointValue( |
| 239 | + mStyleBuffer, YogaNodeMemoryLayout.styleMaxHeight, maxHeight); |
| 240 | + } |
| 241 | + |
| 242 | + @Override |
| 243 | + public void setMaxHeightPercent(float percent) { |
| 244 | + YogaNodeMemoryLayout.putPercentValue( |
| 245 | + mStyleBuffer, YogaNodeMemoryLayout.styleMaxHeight, percent); |
| 246 | + } |
| 247 | + |
| 248 | + @Override |
| 249 | + public void setAspectRatio(float aspectRatio) { |
| 250 | + YogaNodeMemoryLayout.putOptional( |
| 251 | + mStyleBuffer, YogaNodeMemoryLayout.styleAspectRatio, aspectRatio); |
| 252 | + } |
| 253 | + |
| 254 | + @Override |
| 255 | + public YogaNodeProperties clone(YogaNode node) { |
| 256 | + YogaNodePropertiesHybrid clone = (YogaNodePropertiesHybrid) super.clone(node); |
| 257 | + clone.mStyleBuffer = |
| 258 | + jni_getStyleBuffer(clone.getNativePointer()).order(ByteOrder.LITTLE_ENDIAN); |
| 259 | + return clone; |
| 260 | + } |
| 261 | +} |
0 commit comments