Font fixes (#155)

* Fix AreaText crash

* Add x and y to AreaText doc
This commit is contained in:
Niklas Mischkulnig 2018-06-09 22:35:36 +02:00 committed by Gustav Hansen
parent 9fbc83ec36
commit 178c0903b3
2 changed files with 28 additions and 2 deletions

View file

@ -33,6 +33,8 @@ render(<Example />);
_Not all fonts support all possible options_
* [x](#x) (only in a top level text component)
* [y](#y) (only in a top level text component)
* [fontSize](#fontsize)
* [fontFamily](#fontfamily)
* [color](#color)
@ -126,3 +128,19 @@ Wheter the text should be aligned to the left, center or right. **Works only on
| **Type** | **Required** |
| ------------------------------- | ------------ |
| enum('left', 'center', 'right') | false |
### x
The x coordinate of the text's top left corner. (Only in a top level text component.)
| **Type** | **Required** | **Default** |
| ----------------------------- | ------------ | ----------- |
| number &#x7c; string (number) | false | 0 |
### y
The y coordinate of the text's top left corner. (Only in a top level text component.)
| **Type** | **Required** | **Default** |
| ----------------------------- | ------------ | ----------- |
| number &#x7c; string (number) | false | 0 |

View file

@ -853,6 +853,7 @@ Area.Text = class AreaText extends AreaComponent {
libui.textItalic.normal,
libui.textStretch.normal
);
const layout = new libui.DrawTextLayout(
this.str,
font,
@ -867,8 +868,8 @@ Area.Text = class AreaText extends AreaComponent {
p
.getContext()
.text(
this.parseParent(this.props.x || 0, p, false),
this.parseParent(this.props.y || 0, p, true),
this.parseParent(this.props.x, p, false),
this.parseParent(this.props.y, p, true),
layout
);
@ -900,6 +901,13 @@ function areaProp(props, propName, componentName) {
Area.Text.propTypes = {
children: PropTypes.oneOfType([areaProp, PropTypes.arrayOf(areaProp)]),
x: PropTypes.number,
y: PropTypes.number,
};
Area.Text.defaultProps = {
x: 0,
y: 0,
};
export default Area;