|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +package com.facebook.yoga |
| 9 | + |
| 10 | +import com.facebook.yoga.YogaNative.jni_YGConfigGetErrataJNI |
| 11 | +import com.facebook.yoga.YogaNative.jni_YGConfigNewJNI |
| 12 | +import com.facebook.yoga.YogaNative.jni_YGConfigSetErrataJNI |
| 13 | +import com.facebook.yoga.YogaNative.jni_YGConfigSetExperimentalFeatureEnabledJNI |
| 14 | +import com.facebook.yoga.YogaNative.jni_YGConfigSetLoggerJNI |
| 15 | +import com.facebook.yoga.YogaNative.jni_YGConfigSetPointScaleFactorJNI |
| 16 | +import com.facebook.yoga.YogaNative.jni_YGConfigSetUseWebDefaultsJNI |
| 17 | + |
| 18 | +public abstract class YogaConfigJNIBase |
| 19 | +private constructor(@JvmField protected var nativePointer: Long) : YogaConfig() { |
| 20 | + private var _logger: YogaLogger? = null |
| 21 | + |
| 22 | + init { |
| 23 | + check(nativePointer != 0L) { "Failed to allocate native memory" } |
| 24 | + } |
| 25 | + |
| 26 | + internal constructor() : this(jni_YGConfigNewJNI()) |
| 27 | + |
| 28 | + internal constructor(useVanillaJNI: Boolean) : this(jni_YGConfigNewJNI()) |
| 29 | + |
| 30 | + public override fun setExperimentalFeatureEnabled( |
| 31 | + feature: YogaExperimentalFeature, |
| 32 | + enabled: Boolean, |
| 33 | + ) { |
| 34 | + YogaNative.jni_YGConfigSetExperimentalFeatureEnabledJNI( |
| 35 | + nativePointer, |
| 36 | + feature.intValue(), |
| 37 | + enabled, |
| 38 | + ) |
| 39 | + } |
| 40 | + |
| 41 | + public override fun setUseWebDefaults(useWebDefaults: Boolean) { |
| 42 | + YogaNative.jni_YGConfigSetUseWebDefaultsJNI(nativePointer, useWebDefaults) |
| 43 | + } |
| 44 | + |
| 45 | + public override fun setPointScaleFactor(pixelsInPoint: Float) { |
| 46 | + YogaNative.jni_YGConfigSetPointScaleFactorJNI(nativePointer, pixelsInPoint) |
| 47 | + } |
| 48 | + |
| 49 | + public override fun setErrata(errata: YogaErrata) { |
| 50 | + YogaNative.jni_YGConfigSetErrataJNI(nativePointer, errata.intValue()) |
| 51 | + } |
| 52 | + |
| 53 | + public override fun getErrata(): YogaErrata = |
| 54 | + YogaErrata.fromInt(YogaNative.jni_YGConfigGetErrataJNI(nativePointer)) |
| 55 | + |
| 56 | + public override fun setLogger(logger: YogaLogger?) { |
| 57 | + _logger = logger |
| 58 | + YogaNative.jni_YGConfigSetLoggerJNI(nativePointer, logger) |
| 59 | + } |
| 60 | + |
| 61 | + public override fun getLogger(): YogaLogger? = _logger |
| 62 | + |
| 63 | + public override fun getNativePointer(): Long = nativePointer |
| 64 | +} |
0 commit comments