1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.compose.ui.text.style 18 19 import androidx.compose.runtime.Immutable 20 import androidx.compose.runtime.Stable 21 import androidx.compose.ui.util.lerp 22 23 /** 24 * The amount by which the text is shifted up or down from current the baseline. 25 * 26 * @param multiplier shift the baseline by multiplier * (baseline - ascent) 27 * @constructor 28 * @sample androidx.compose.ui.text.samples.BaselineShiftSample 29 * @sample androidx.compose.ui.text.samples.BaselineShiftAnnotatedStringSample 30 */ 31 @Immutable 32 @kotlin.jvm.JvmInline 33 value class BaselineShift(val multiplier: Float) { 34 companion object { 35 /** Default baseline shift for superscript. */ 36 @Stable val Superscript = BaselineShift(0.5f) 37 38 /** Default baseline shift for subscript */ 39 @Stable val Subscript = BaselineShift(-0.5f) 40 41 /** Constant for no baseline shift. */ 42 @Stable val None = BaselineShift(0.0f) 43 } 44 } 45 46 /** Linearly interpolate two [BaselineShift]s. */ 47 @Stable lerpnull48fun lerp(start: BaselineShift, stop: BaselineShift, fraction: Float): BaselineShift { 49 return BaselineShift(lerp(start.multiplier, stop.multiplier, fraction)) 50 } 51