mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2024-12-22 11:03:48 +01:00
edit width of input based on number of characters
This commit is contained in:
parent
a4a5afeb08
commit
7b9f647f11
@ -6,7 +6,7 @@ import * as actions from '../actions/index.js';
|
||||
import * as CAL from 'cal';
|
||||
import { TEXT_TOOL_FONT_SIZE } from '../constants/d2Constants.js';
|
||||
|
||||
document.createElement('canvas');
|
||||
const CONTEXT = document.createElement('canvas').getContext('2d');
|
||||
|
||||
const styles = {
|
||||
textInputContainer: {
|
||||
@ -63,6 +63,11 @@ class InputText extends React.Component {
|
||||
.multiplyMatrix(state.d2.canvasMatrix)
|
||||
.multiplyMatrix(screenMatrix);
|
||||
|
||||
const { family, style, weight, text } = shapeData.text;
|
||||
|
||||
CONTEXT.font = `${style} normal ${weight} ${TEXT_TOOL_FONT_SIZE}px ${family}`;
|
||||
const width = Math.max(10, CONTEXT.measureText(shapeData.text.text).width);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classes.textInputContainer}
|
||||
@ -70,8 +75,13 @@ class InputText extends React.Component {
|
||||
>
|
||||
<input
|
||||
className={classes.textInput}
|
||||
style={{ fontFamily: shapeData.text.family }}
|
||||
value={shapeData.text.text}
|
||||
style={{
|
||||
fontFamily: family,
|
||||
fontStyle: style,
|
||||
fontWeight: weight,
|
||||
width: `${width}px`
|
||||
}}
|
||||
value={text}
|
||||
ref="text"
|
||||
spellCheck="false"
|
||||
autoFocus
|
||||
|
Loading…
Reference in New Issue
Block a user