diff --git a/src/index.tsx b/src/index.tsx
index b78984551..1c61e1064 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -29,7 +29,8 @@ import {
hasStroke,
getElementAtPosition,
createScene,
- getElementContainingPosition
+ getElementContainingPosition,
+ hasText
} from "./scene";
import { renderScene } from "./renderer";
@@ -324,6 +325,14 @@ export class App extends React.Component<{}, AppState> {
}
};
+ private redrawBoundingBox = (element: ExcalidrawTextElement) => {
+ const metrics = measureText(element.text, element.font);
+ element.width = metrics.width;
+ element.height = metrics.height;
+ element.baseline = metrics.baseline;
+ this.forceUpdate();
+ }
+
public render() {
const canvasWidth = window.innerWidth - CANVAS_WINDOW_OFFSET_LEFT;
const canvasHeight = window.innerHeight - CANVAS_WINDOW_OFFSET_TOP;
@@ -452,6 +461,60 @@ export class App extends React.Component<{}, AppState> {
>
)}
+ {hasText(elements) && (
+ <>
+
Font size
+ isTextElement(element) && +element.font.split("px ")[0]
+ )}
+ onChange={value =>
+ this.changeProperty(element => {
+ if(isTextElement(element)) {
+ element.font = `${value}px ${element.font.split("px ")[1]}`;
+ this.redrawBoundingBox(element);
+ }
+ })
+ }
+ />
+ Font familly
+ isTextElement(element) && element.font.split("px ")[1]
+ )}
+ onChange={value =>
+ this.changeProperty(element => {
+ if(isTextElement(element)) {
+ element.font = `${element.font.split("px ")[0]}px ${value}`;
+ this.redrawBoundingBox(element);
+ }
+ })
+ }
+ />
+ >
+ )}
+
Opacity
element.type === "arrow")
);
+export const hasText = (elements: ExcalidrawElement[]) =>
+ elements.some(
+ element => element.isSelected && element.type === "text"
+ );
+
export function getElementAtPosition(
elements: ExcalidrawElement[],
x: number,
diff --git a/src/scene/index.ts b/src/scene/index.ts
index 479c60efa..171315f40 100644
--- a/src/scene/index.ts
+++ b/src/scene/index.ts
@@ -18,6 +18,7 @@ export {
hasBackground,
hasStroke,
getElementAtPosition,
- getElementContainingPosition
+ getElementContainingPosition,
+ hasText
} from "./comparisons";
export { createScene } from "./createScene";