-
-
Notifications
You must be signed in to change notification settings - Fork 934
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
TextBoxComponent
should have the possiblity to align text within itself
#1088
Comments
I just looked into |
It is used in |
I had a go to solve this little puzzle, and here is a way to get it as expected Rename the class to for instance MyTextBoxComponent: class MyTextBoxComponent<T extends TextRenderer> extends TextComponent {
//(...)
//Add this paramter
final TextAlign textAlign;
//(....)
MyTextBoxComponent({
//(...)
int? priority,
this.textAlign = TextAlign.left, //Defaults to left alignment
}) : _boxConfig = boxConfig ?? TextBoxConfig(),
pixelRatio = pixelRatio ?? window.devicePixelRatio,
super( ............. Find the _drawLine routine and change it to this: void _drawLine(Canvas c, String line, double dy) {
if(textAlign == TextAlign.left)
{
textRenderer.render(c, line, Vector2(_boxConfig.margins.left, dy));
}
if(textAlign == TextAlign.center)
{
double _lineActualLength = getLineWidth(line, line.length);
double _lineWidth = ( size.x - _boxConfig.margins.right - _lineActualLength ) / 2;
textRenderer.render(c, line, Vector2(_boxConfig.margins.left + _lineWidth, dy));
}
if(textAlign == TextAlign.right)
{
double _lineActualLength = getLineWidth(line, line.length);
double _lineWidth = ( size.x - _boxConfig.margins.right - _lineActualLength );
textRenderer.render(c, line, Vector2(_boxConfig.margins.left + _lineWidth, dy));
}
} This solution is "good enough" for me. I do not need TextAlign.start, TextAlign.justify and TextAlign.end for my project. |
The |
Problem to solve
Right now the text within a
TextBoxComponent
can only be left aligned.Proposal
I propose that we add a
textAlign
field inTextBoxConfig
. The type of the field could either beTextAlign
or anAnchor
.More information
The text was updated successfully, but these errors were encountered: