refactor(text): update Editor TextFormatToolbar to use TextSprite API
This commit is contained in:
@@ -37,6 +37,7 @@ import { getPointAnchorWorld } from '../canvas/reviewAnchors';
|
|||||||
import { resolveReviewTargetAtPoint } from '../canvas/reviewTargeting';
|
import { resolveReviewTargetAtPoint } from '../canvas/reviewTargeting';
|
||||||
import type { TextObject } from '../canvas/scene-format';
|
import type { TextObject } from '../canvas/scene-format';
|
||||||
import { VideoSprite } from '../canvas/sprites/VideoSprite';
|
import { VideoSprite } from '../canvas/sprites/VideoSprite';
|
||||||
|
import { TextSprite } from '../canvas/sprites/TextSprite';
|
||||||
import * as ops from '../canvas/operations';
|
import * as ops from '../canvas/operations';
|
||||||
|
|
||||||
// Hooks
|
// Hooks
|
||||||
@@ -902,13 +903,13 @@ export default function Editor({ isPublicView }: EditorProps) {
|
|||||||
onFontSizeChange={(size) => {
|
onFontSizeChange={(size) => {
|
||||||
const scene = canvasRef.current?.getScene();
|
const scene = canvasRef.current?.getScene();
|
||||||
for (const item of textToolbar.items) {
|
for (const item of textToolbar.items) {
|
||||||
(item.data as TextObject).fontSize = size;
|
const d = item.data as TextObject;
|
||||||
const s = (item.displayObject as any)?.style;
|
d.fontSize = size;
|
||||||
if (s) s.fontSize = size;
|
if (item.displayObject instanceof TextSprite) {
|
||||||
// Re-measure text bounds
|
item.displayObject.updateFromData(d);
|
||||||
const bounds = item.displayObject.getLocalBounds();
|
d.w = item.displayObject.measuredWidth;
|
||||||
item.data.w = bounds.width;
|
d.h = item.displayObject.measuredHeight;
|
||||||
item.data.h = bounds.height;
|
}
|
||||||
if (scene) scene.updateSpatialEntry(item);
|
if (scene) scene.updateSpatialEntry(item);
|
||||||
}
|
}
|
||||||
selectionRef.current?.transformBox.update(textToolbar.items);
|
selectionRef.current?.transformBox.update(textToolbar.items);
|
||||||
@@ -918,12 +919,13 @@ export default function Editor({ isPublicView }: EditorProps) {
|
|||||||
onFontFamilyChange={(family) => {
|
onFontFamilyChange={(family) => {
|
||||||
const scene = canvasRef.current?.getScene();
|
const scene = canvasRef.current?.getScene();
|
||||||
for (const item of textToolbar.items) {
|
for (const item of textToolbar.items) {
|
||||||
(item.data as TextObject).fontFamily = family;
|
const d = item.data as TextObject;
|
||||||
const s = (item.displayObject as any)?.style;
|
d.fontFamily = family;
|
||||||
if (s) s.fontFamily = family;
|
if (item.displayObject instanceof TextSprite) {
|
||||||
const bounds = item.displayObject.getLocalBounds();
|
item.displayObject.updateFromData(d);
|
||||||
item.data.w = bounds.width;
|
d.w = item.displayObject.measuredWidth;
|
||||||
item.data.h = bounds.height;
|
d.h = item.displayObject.measuredHeight;
|
||||||
|
}
|
||||||
if (scene) scene.updateSpatialEntry(item);
|
if (scene) scene.updateSpatialEntry(item);
|
||||||
}
|
}
|
||||||
selectionRef.current?.transformBox.update(textToolbar.items);
|
selectionRef.current?.transformBox.update(textToolbar.items);
|
||||||
@@ -932,9 +934,11 @@ export default function Editor({ isPublicView }: EditorProps) {
|
|||||||
}}
|
}}
|
||||||
onFillChange={(color) => {
|
onFillChange={(color) => {
|
||||||
for (const item of textToolbar.items) {
|
for (const item of textToolbar.items) {
|
||||||
(item.data as TextObject).fill = color;
|
const d = item.data as TextObject;
|
||||||
const s = (item.displayObject as any)?.style;
|
d.fill = color;
|
||||||
if (s) s.fill = color;
|
if (item.displayObject instanceof TextSprite) {
|
||||||
|
item.displayObject.updateFromData(d);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
onCanvasChange(textToolbar.items.map(i => i.id));
|
onCanvasChange(textToolbar.items.map(i => i.id));
|
||||||
updateOverlays();
|
updateOverlays();
|
||||||
|
|||||||
Reference in New Issue
Block a user