Flex 3 - 在形状中对角绘制文本并调整大小
我正在尝试创建以下组件:
仅供参考,空白区域将包含一个文本控件,我正在创建一个组件,该组件代表带有 (i) 图标和“促销”文本的黑色角。
我遇到问题的部分是这个组件代表带有对角线文本的黑色角。文本必须能够容纳 2 行。并且黑角必须能够调整文本的大小。 更重要的是,文本有旋转...
我对如何执行此操作有一些疑问:
- 我应该为每个文本行设置不同的控件吗?
- 我应该在形状中绘制文本(旋转后)还是应该重叠两个组件? [当我谈论在形状中绘制文本时,我的意思是与 这个问题]
- 有没有办法在不做一些奢侈计算的情况下得到三角形的正确大小?
而且......你有什么“更简单”的方法来做到这一点吗?
非常感谢您提供的任何帮助:)我对这个小组件有点迷失:)
问候。
BS_C3
编辑 1:
- 三角形可以有 2 种尺寸:一种尺寸适合 1 行文本,另一种尺寸适合 2 行文本。
- 文本将作为单个字符串发送,因此如果需要,它必须自动分为两行
- 我正在考虑使用图形来绘制三角形,然后使用蒙版来创建圆角 -->这是因为相同的组件将在应用程序的其他地方使用而无需圆角
I'm trying to create the following component:
Just for information, the blank space will contain a text control, and I'm creating a component that represents the black corner with the (i) icon and the "promotion" text.
The part I'm having issues with is this component representing the black corner with the diagonal text. The text has to be able to hold 2 lines. And the black corner has to be able to adjust to the text's size.
What's more, the text has a rotation...
I'm having some doubts on how to do this:
- Should I have different controls for each text line?
- Should I draw the text in the shape (after doing the rotation) or should I just overlap both components? [When I talk about drawing the text in the shape, I mean in the same way as asked in this question]
- Is there any way to get the proper size of the triangle shape without doing some extravagant calculations?
And... do you have any "easier" ways to do this ?
A big thanks for any help you can provide :) I'm a little bit lost with this little component :)
Regards.
BS_C3
Edit 1:
- The triangle may have 2 sizes: 1 size that will fit 1 line, and another size to fit 2 lines of text.
- The text will be sent as a single string, so it will have to be automatically divided in two lines if needed
- I was thinking of using graphics to draw the triangle shape and then use a mask to create the rounded corner --> This is because the same component will be used in other places of the application without the rounded corner
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Flex 非常擅长将组组件更新为任何大小的内容,动态更新。
根据您的建议,我可能会在角落创建“促销”组作为矩形,旋转它并使其适合像你想要的那样,然后使用你用作主要组件背景的圆角矩形的副本,我会制作一个蒙版来剪切“促销”组件,这样你就看不到重叠。
Flex is pretty good at updating group components to whatever size thier contents become, updating dynamically on the fly..
for what your suggesting, I'd probably create the "Promotion" group in the corner as a rectangle, rotate it and fit it to the corner like you want, then using a copy of the rounded rect you use as the maing component background, i'd make a mask to cut the "Promotion" component so you don't see the overlap.
好吧,我终于写了这个类,结果是这样的:
Well, I finally wrote the class and this is the result: