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

mText cutoff and wrapping issue #140

Open
1 task
Nealsoni00 opened this issue Sep 20, 2020 · 5 comments
Open
1 task

mText cutoff and wrapping issue #140

Nealsoni00 opened this issue Sep 20, 2020 · 5 comments
Labels

Comments

@Nealsoni00
Copy link

What kind of issue is this?

  • UI Bug
    image

Details

When text is too long, it is both hidden behind the slide icon button as well as gets cut off since it does not support text-wrapping.

Is there any way to fix both: Get the text to start after the slide icon button and wrap to multiple lines if it is too long?

@cortinico
Copy link
Owner

Is there any way to fix both: Get the text to start after the slide icon button and wrap to multiple lines if it is too long?

Thanks for the report.

No there is no support for text wrapping at the moment. Also wrapping the text won't really solve the issue if you're providing a text that is anyway too long.

@quanta-kt
Copy link
Contributor

Can adding multi-line support (#112) resolve this?

I'd like make a PR but there are these issues I seek guidance on-

  • Is it possible to get the width of the text to be drawn in advanced, before it is drawn so as to calculate where the line should be broken? Maybe use of StaticLayout instead of calling Canvas#drawText will simplify this?
  • What happens when the height of the widget is exhausted too due to too many lines? Could trim the string and add a ellipsis at the end.

@Nealsoni00
Copy link
Author

Nealsoni00 commented Sep 28, 2020

I just created a static layout that solves the issue I described for devices above M. Might make it into a pull request + clean it up properly later but otherwise other people can use it.
image

https://github.com/InvictusApps/slidetoact
implementation "com.github.InvictusApps:slidetoact:0.9.2"

Relevant Change:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            val leftOffset = (mAreaHeight - 2 * mActualAreaMargin).toFloat() / mAreaHeight.toFloat() * mBorderRadius.toFloat() * 2
            val maxWidth = mAreaWidth - (2 * mActualAreaWidth) - leftOffset
            val textLayout = StaticLayout.Builder
                    .obtain(textToDraw, 0, textToDraw.length, mTextPaint, maxWidth)
                    .setAlignment(Layout.Alignment.ALIGN_NORMAL)
                    .setMaxLines(4)
                    .build()
            canvas.save()

            val dY = (height / 2) - (textLayout.height / 2)
            val dX = (width / 2) - (textLayout.width / 2)

            val mTextLeft = mActualAreaWidth + leftOffset + dX
            val mTextTop = 0 + dY
            val mTextRight =  mAreaWidth - mActualAreaWidth  - dX

            canvas.translate(mTextLeft.toFloat(), mTextTop.toFloat())
            canvas.translate(((mTextRight - mTextLeft) / 2).toFloat(), 0f)
            textLayout.draw(canvas)

            canvas.restore()
        } else {
            canvas.drawText(textToDraw, 0, textToDraw.length, mTextXPosition, mTextYPosition, mTextPaint)
//         textLayout = StaticLayout(textToDraw, mTextPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        }

@cortinico
Copy link
Owner

I just created a static layout that solves the issue I described for devices above M. Might make it into a pull request + clean it up properly later but otherwise other people can use it.

Thanks for doing this. I've quickly checked your fork and it looks like a valid solution. However this is still unfixed:

What happens when the height of the widget is exhausted too due to too many lines? Could trim the string and add a ellipsis at the end.

Happy to discuss over this on PR anyway 👍

@JeppeLeth
Copy link

I created a PR for this feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants