Skip to content

Commit

Permalink
add: ui to rotate text
Browse files Browse the repository at this point in the history
  • Loading branch information
zenkyuv committed Jan 10, 2024
1 parent 083991d commit c48d4da
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions s/views/text-positioner/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {css} from "@benev/slate"

export const styles = css`
.text-rect {
z-index: 999;
outline: 1px solid white;
}
`
35 changes: 35 additions & 0 deletions s/views/text-positioner/view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {html} from "@benev/slate"

import {styles} from "./styles.js"
import {shadow_view} from "../../context/slate.js"

export const TextPositioner = shadow_view({styles}, use => () => {
use.watch(() => use.context.state.timeline)
const {canvas} = use.context.controllers.compositor
const compositor = use.context.controllers.compositor
const selected_effect = use.context.state.timeline.selected_effect?.kind === "text"
? use.context.state.timeline.selected_effect
: null

// scaling to screen coords/sizes
const canvas_rect = canvas.getBoundingClientRect()
const scaleX = canvas.width / canvas_rect.width
const scaleY = canvas.height / canvas_rect.height

return html`
${selected_effect
? html`
<div
style="
width: ${selected_effect?.rect?.width / scaleX}px;
height: ${selected_effect?.rect.height / scaleY}px;
position: absolute;
left: ${selected_effect.rect.position_on_canvas.x / scaleX}px;
transform: rotate(${compositor.TextManager.rotate}rad);
top: ${(selected_effect.rect.position_on_canvas.y - selected_effect.rect.height) / scaleY}px;
" class="text-rect">
</div>
`
: null}
`
})

0 comments on commit c48d4da

Please sign in to comment.