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

Aligning Text not working on Desktop App #92

Closed
ScottPierce opened this issue Nov 12, 2020 · 2 comments
Closed

Aligning Text not working on Desktop App #92

ScottPierce opened this issue Nov 12, 2020 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ScottPierce
Copy link
Contributor

ScottPierce commented Nov 12, 2020

I'm not a compose expert, but it looks like this is a bug to me. I'm running Desktop Compose, and text alignment seems to not be working.

Here is the code snippet:

        Column(
            Modifier
                .fillMaxSize()
                .padding(20.dp)
        ) {
            Text(
                text = "Test test test asdfasdfa sfj aslf lajsdlf jlajdsfl jlasjf jaslkfj klajdfl jaslf lkasjfljaslk f",
                style = typography.h3,
                color = Color.White,
                textAlign = TextAlign.End,
                modifier = Modifier.background(Color.Black),
            )
        }

Here is the result:
Screen Shot 2020-11-11 at 10 02 17 PM

As you can see, the text isn't aligning to the end as I'd expect. I've also tried aligning center, and aligning doesn't seem to have any impact for the text.

Here is the full code sample:

fun main() {
    Window(
        title = "Test",
        centered = true,
    ) {
        Surface(modifier = Modifier.fillMaxSize()) {
            MaterialTheme {
                DesktopTheme {
                    AuthScreen()
                }
            }
        }
    }
}
@Composable
fun AuthScreen() {
    Row {
        PrimarySection(Modifier.weight(1f))
        SecondarySection(Modifier.weight(1f))
    }
}

@Composable
private fun PrimarySection(modifier: Modifier) {
    val typography = MaterialTheme.typography

    Column(
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = modifier.fillMaxSize(),
    ) {

        Text(
            text = "Please log in to your account",
            style = typography.h3,
            color = Color.Black,
            textAlign = TextAlign.Center
        )
    }
}

@Composable
private fun SecondarySection(modifier: Modifier) {
    val typography = MaterialTheme.typography

    Box(
        modifier
            .fillMaxSize()
            .backgroundVerticalGradient(
                Color(125, 206, 250),
                Color(82, 88, 245)
            )
    ) {
        Column(
            Modifier
                .fillMaxSize()
                .padding(20.dp)
        ) {
            Text(
                text = "Test test test asdfasdfa sfj aslf lajsdlf jlajdsfl jlasjf jaslkfj klajdfl jaslf lkasjfljaslk f",
                style = typography.h3,
                color = Color.White,
                textAlign = TextAlign.End,
                modifier = Modifier.background(Color.Black),
            )
        }
    }
}

fun Modifier.backgroundVerticalGradient(start: Color, end: Color): Modifier =
    drawWithCache {
        onDrawBehind {
            drawRect(
                VerticalGradient(
                    colors = listOf(start, end),
                    startY = 0f,
                    endY = size.height
                )
            )

        }
    }
@prepor prepor added this to the M2 milestone Nov 12, 2020
@igordmn igordmn added the bug Something isn't working label Nov 19, 2020
@prepor
Copy link
Contributor

prepor commented Nov 24, 2020

It should be fixed. Please, check with 0.2.0-build129.

@prepor prepor closed this as completed Nov 24, 2020
@ScottPierce
Copy link
Contributor Author

Wow - fast turn-around. I'm impressed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants