💄 Rename text-dimensions to get-text-dimensions

This commit is contained in:
Andrey Antukh 2025-08-12 13:55:36 +02:00
parent 0d6eac7656
commit c55f3182d8
5 changed files with 18 additions and 17 deletions

View File

@ -58,13 +58,13 @@
([{:keys [id points selrect] :as shape} content] ([{:keys [id points selrect] :as shape} content]
(wasm.api/use-shape id) (wasm.api/use-shape id)
(wasm.api/set-shape-text id content) (wasm.api/set-shape-text id content)
(let [dimension (wasm.api/text-dimensions) (let [dimension (wasm.api/get-text-dimensions)
resize-v resize-v (gpt/point
(gpt/point (/ (:width dimension) (-> selrect :width))
(/ (:width dimension) (-> selrect :width)) (/ (:height dimension) (-> selrect :height)))
(/ (:height dimension) (-> selrect :height)))
origin (first points)]
origin (first points)]
{id {id
{:modifiers {:modifiers
(ctm/resize-modifiers (ctm/resize-modifiers

View File

@ -19,7 +19,7 @@
(if (features/active-feature? @st/state "render-wasm/v1") (if (features/active-feature? @st/state "render-wasm/v1")
(let [transform (gsh/transform-str shape) (let [transform (gsh/transform-str shape)
{:keys [id x y grow-type]} shape {:keys [id x y grow-type]} shape
{:keys [width height]} (if (= :fixed grow-type) shape (wasm.api/text-dimensions id))] {:keys [width height]} (if (= :fixed grow-type) shape (wasm.api/get-text-dimensions id))]
[:rect.main.viewport-selrect [:rect.main.viewport-selrect
{:x x {:x x
:y y :y y

View File

@ -310,7 +310,7 @@
[x y width height] [x y width height]
(if (features/active-feature? @st/state "render-wasm/v1") (if (features/active-feature? @st/state "render-wasm/v1")
(let [{:keys [max-width height]} (wasm.api/text-dimensions shape-id) (let [{:keys [max-width height]} (wasm.api/get-text-dimensions shape-id)
{:keys [x y]} (:selrect shape)] {:keys [x y]} (:selrect shape)]
[x y max-width height]) [x y max-width height])

View File

@ -309,7 +309,7 @@
(ted/export-content))] (ted/export-content))]
(wasm.api/use-shape edition) (wasm.api/use-shape edition)
(wasm.api/set-shape-text-content edition content) (wasm.api/set-shape-text-content edition content)
(let [dimension (wasm.api/text-dimensions)] (let [dimension (wasm.api/get-text-dimensions)]
(st/emit! (dwt/resize-text-editor edition dimension)) (st/emit! (dwt/resize-text-editor edition dimension))
(wasm.api/clear-drawing-cache) (wasm.api/clear-drawing-cache)
(wasm.api/request-render "content")))))) (wasm.api/request-render "content"))))))

View File

@ -645,6 +645,7 @@
fonts (fonts/get-content-fonts content) fonts (fonts/get-content-fonts content)
emoji? (atom false) emoji? (atom false)
languages (atom #{})] languages (atom #{})]
(loop [index 0] (loop [index 0]
(when (< index (count paragraphs)) (when (< index (count paragraphs))
(let [paragraph (nth paragraphs index) (let [paragraph (nth paragraphs index)
@ -673,16 +674,17 @@
[grow-type] [grow-type]
(h/call wasm/internal-module "_set_shape_grow_type" (sr/translate-grow-type grow-type))) (h/call wasm/internal-module "_set_shape_grow_type" (sr/translate-grow-type grow-type)))
(defn text-dimensions (defn get-text-dimensions
([id] ([id]
(use-shape id) (use-shape id)
(text-dimensions)) (get-text-dimensions))
([] ([]
(let [offset (h/call wasm/internal-module "_get_text_dimensions") (let [offset (-> (h/call wasm/internal-module "_get_text_dimensions")
heapf32 (mem/get-heap-f32) (mem/->offset-32))
width (aget heapf32 (mem/->offset-32 offset)) heapf32 (mem/get-heap-f32)
height (aget heapf32 (mem/->offset-32 (+ offset 4))) width (aget heapf32 (+ offset 0))
max-width (aget heapf32 (mem/->offset-32 (+ offset 8)))] height (aget heapf32 (+ offset 1))
max-width (aget heapf32 (+ offset 2))]
(mem/free) (mem/free)
{:width width :height height :max-width max-width}))) {:width width :height height :max-width max-width})))
@ -776,7 +778,6 @@
(perf/end-measure "set-object") (perf/end-measure "set-object")
pending))) pending)))
(defn process-pending (defn process-pending
[pending] [pending]
(let [event (js/CustomEvent. "wasm:set-objects-finished") (let [event (js/CustomEvent. "wasm:set-objects-finished")