-
Notifications
You must be signed in to change notification settings - Fork 450
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
FlxText
always shrinks its "graphic object" height
#2783
Comments
I'm not sure what your goal is, or what you're suggesting |
Well, let me explain it in more details with screenshots. I can set width and height for openfl textfield so the field gets fixed size. openfl textfield code [CLICK TO EXPAND]var text = new TextField();
text.text = 'Lorem ipsum foo bar sit amet!';
var format = text.defaultTextFormat;
format.font = 'Arial';
format.size = 18;
format.color = 0x111111;
format.align = LEFT;
format.leftMargin = 25;
format.rightMargin = 25;
text.setTextFormat(format);
text.selectable = false;
text.autoSize = NONE;
text.wordWrap = true;
text.background = true;
text.backgroundColor = 0xEEEEEE;
text.textColor = 0x111111;
text.width = stage.stageWidth * 0.8;
text.height = stage.stageHeight * 0.3;
trace(text.height);
text.x = stage.stageWidth * 0.5 - text.width * 0.5;
text.y = stage.stageHeight - text.height * 1.1;
addChild(text); But I cannot do this the same way with flixel textfield code [CLICK TO EXPAND]var text = new FlxText();
text.text = 'Lorem ipsum foo bar sit amet!';
var format = text.textField.defaultTextFormat;
format.size = 18;
format.color = 0x111111;
format.align = LEFT;
format.leftMargin = 25;
format.rightMargin = 25;
text.textField.defaultTextFormat = format;
text.textField.setTextFormat(format);
@:privateAccess text._defaultFormat = format;
@:privateAccess text.updateDefaultFormat();
text.autoSize = false;
text.wordWrap = true;
text.textField.background = true;
text.textField.backgroundColor = 0xEEEEEE;
// text.textColor = 0x111111;
var w = Flixel.width * 0.8;
var h = Flixel.height * 0.25;
trace('h', h);
text.width = text.textField.width = w;
text.height = text.textField.height = h;
trace('field height', text.textField.height);
text.x = Flixel.width * 0.5 - text.width * 0.5;
text.y = Flixel.height - h * 1.1;
trace('field height', text.textField.height); Flixel text field always shrinks its height to match given text, it is not possible to create a fixed-size Possible fixes:
|
a sprite's width and height refer to the size their collision box, not some kind of graphical width or height. sprite's collision size can be set to whatever the dev decides for collision reasons but it's not meant to used internally to represent graphic size. We are actively working to make this distinction more clear, such as with HaxeFlixel/flixel-docs#258 and #2667. So we absolutely should not use |
FlxText
always shrinks its heightFlxText
always shrinks its "graphic object" height
Let me clarify this a little more: the issues is about not being able to set fixed size to openfl textfield itself (i.e. openfl textfield here is a graphic object). Flixel boldly assumes that no one needs this and gives no control on such behavior. |
I think i just need a more concrete example of what you're trying to do but cannot |
The example is above. I want to be able to set fixed size for Current implementation of autosizing does not allow this (it came from flash version of flixel). Without breaking change it could be fixed in this ways:
Any of these fixes would make Also there is a question about FlxText.autoSize. Why was it made to affect only width? Why cannot it be the same as openfl autoSize? Though changing it would be a breaking change, so it is best to left it as another issue. |
I see, I didn't notice you're example above had a dropdown code example, I've never seen this feature of github. I also see that I was mistaking myText.height with mytext.textField.height. this all make sense, I'll play around with TextField and FlxText and see the inconsistencies first hand before making a decision |
I did some tests (they are small and does not cover all possible prop combinations, textfields are complex and tricky 😓 ) and I would say the main problem is |
No matter how I try I cannot set desired height for
FlxText
, its height shrinks to the real text height . After some time digging I found the culprit (see FlxText.hx#710):I believe instead of
textField.textHeight
there should betextField.height
, though maybe there was a reason to not useheight
prop.The text was updated successfully, but these errors were encountered: