Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configurable vertical centering via LineHeightStyle.Alignment #1569

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ val MainScreen = Screen.Selection(
BugReproducers,
Screen.Example("Example1") { Example1() },
Screen.Example("ImageViewer") { ImageViewer() },
Screen.Example("TextDirection") { TextDirection() },
Screen.Example("FontFamilies") { FontFamilies() },
Screen.Example("LottieAnimation") { LottieAnimation() },
Screen.Fullscreen("ApplicationLayouts") { ApplicationLayouts(it) },
Screen.Example("GraphicsLayerSettings") { GraphicsLayerSettings() },
Screen.Example("Blending") { Blending() },
Screen.Example("FontRasterization") { FontRasterization() },
Screen.Example("InteropOrder") { InteropOrder() },
AndroidTextFieldSamples,
Screen.Example("Android TextBrushDemo") { TextBrushDemo() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.mpp.demo.components.material3.ModalNavigationDrawerExamp
import androidx.compose.mpp.demo.components.material3.SearchBarExample
import androidx.compose.mpp.demo.components.material3.WindowSizeClassExample
import androidx.compose.mpp.demo.components.popup.Popups
import androidx.compose.mpp.demo.components.text.TextDemos
import androidx.compose.mpp.demo.textfield.TextFields
import androidx.compose.runtime.Composable

Expand All @@ -56,6 +57,7 @@ val Components = Screen.Selection(
"Components",
Popups,
Dialogs,
TextDemos,
TextFields,
LazyLayouts,
MaterialComponents,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

package androidx.compose.mpp.demo
package androidx.compose.mpp.demo.components.text

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -29,27 +29,23 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.dp


@Composable
fun FontFamilies() {
val state = rememberScrollState()
MaterialTheme {
Column(
modifier = Modifier
.fillMaxSize()
.padding(10.dp)
.verticalScroll(state),
verticalArrangement = Arrangement
.spacedBy(10.dp)
) {
for (fontFamily in listOf(
FontFamily.SansSerif,
FontFamily.Serif,
FontFamily.Monospace,
FontFamily.Cursive
)) {
FontFamilyShowcase(fontFamily)
}
Column(
modifier = Modifier
.fillMaxSize()
.padding(10.dp)
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement
.spacedBy(10.dp)
) {
for (fontFamily in listOf(
FontFamily.SansSerif,
FontFamily.Serif,
FontFamily.Monospace,
FontFamily.Cursive
)) {
FontFamilyShowcase(fontFamily)
}
}
}
Expand All @@ -60,15 +56,16 @@ private fun FontFamilyShowcase(fontFamily: FontFamily) {
Text(
text = "$fontFamily"
)
Text(
text = "The quick brown fox jumps over the lazy dog.",
val textStyle = MaterialTheme.typography.h3.copy(
fontFamily = fontFamily,
style = MaterialTheme.typography.h3
)
Text(
TextWithMetrics(
text = "The quick brown fox jumps over the lazy dog.",
style = textStyle
)
TextWithMetrics(
text = "1234567890",
fontFamily = fontFamily,
style = MaterialTheme.typography.h3
style = textStyle
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.mpp.demo.components.text

import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.BasicText
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.FontHinting
import androidx.compose.ui.text.FontRasterizationSettings
import androidx.compose.ui.text.FontSmoothing
import androidx.compose.ui.text.PlatformParagraphStyle
import androidx.compose.ui.text.PlatformTextStyle
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp

@OptIn(ExperimentalTextApi::class)
@Composable
fun FontRasterization() {
val state = rememberScrollState()
Column(
modifier = Modifier.fillMaxSize().padding(10.dp).verticalScroll(state),
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
val hintingOptions = listOf(FontHinting.None, FontHinting.Slight, FontHinting.Normal, FontHinting.Full)
val isAutoHintingForcedOptions = listOf(false, true)
val subpixelOptions = listOf(false, true)
val smoothingOptions = listOf(FontSmoothing.None, FontSmoothing.AntiAlias, FontSmoothing.SubpixelAntiAlias)
val text = "Lorem ipsum"

for (hinting in hintingOptions) {
Row(
horizontalArrangement = Arrangement.spacedBy(10.dp)
) {
for (smoothing in smoothingOptions) {
Column(
modifier = Modifier.weight(1f).border(1.dp, Color.Black).padding(10.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
for (subpixel in subpixelOptions) {
for (autoHintingForced in isAutoHintingForcedOptions) {
FontRasterizationSample(
text = text,
modifier = Modifier.offset(x = 0.25.dp, y = 0.25.dp),
hinting = hinting,
smoothing = smoothing,
subpixelPositioning = subpixel,
autoHintingForced = autoHintingForced
)
}
}
}
}
}
}
}
}

@OptIn(ExperimentalTextApi::class)
@Composable
private fun FontRasterizationSample(
text: String,
modifier: Modifier,
hinting: FontHinting,
smoothing: FontSmoothing,
subpixelPositioning: Boolean,
autoHintingForced: Boolean
) {
BasicText(
text = text,
modifier = modifier,
style = TextStyle(
platformStyle = PlatformTextStyle(
spanStyle = null,
paragraphStyle = PlatformParagraphStyle(
fontRasterizationSettings = FontRasterizationSettings(
smoothing = smoothing,
hinting = hinting,
subpixelPositioning = subpixelPositioning,
autoHintingForced = autoHintingForced
)
)
)
)
)
}
Loading