From 178c0903b3d7bdd9a8116a771006651a817c6d02 Mon Sep 17 00:00:00 2001 From: Niklas Mischkulnig Date: Sat, 9 Jun 2018 22:35:36 +0200 Subject: [PATCH] Font fixes (#155) * Fix AreaText crash * Add x and y to AreaText doc --- docs/component_APIs/area_text.md | 18 ++++++++++++++++++ src/components/Area.js | 12 ++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/component_APIs/area_text.md b/docs/component_APIs/area_text.md index 57ebc23..16a853e 100644 --- a/docs/component_APIs/area_text.md +++ b/docs/component_APIs/area_text.md @@ -33,6 +33,8 @@ render(); _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 | 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 | string (number) | false | 0 | diff --git a/src/components/Area.js b/src/components/Area.js index 2788748..2d4ee6b 100644 --- a/src/components/Area.js +++ b/src/components/Area.js @@ -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;