Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[experiment] Controls #2989

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

[experiment] Controls #2989

wants to merge 5 commits into from

Conversation

SomeHats
Copy link
Contributor

Controls are a sort of combined virtual shape / mini state node that render on top of the canvas? IDK. I was into this when i first thought about it but now i'm not so sure.

The idea: call addControls with a reactive function that returns some number of Control objects. You can think of this function as being similar to a react component, e.g.

editor.addControls(() => {
    if (!editor.isIn('select.idle')) return null
    return new MyControl()
})

is conceptually similar to

function MyControlWrapper() {
    if (!editor.isIn('select.idle')) return null
    return <MyControl />
}

The control object itself has geometry, a component, and can store any information it needs too.

When a pointer event comes in, if we're hovering a control, then the event is sent there first. From there, we can use normal state chart modifications or do whatever else we want. I had to add a .preventDefault() to get this to play nice. idk about it. very buggy and rough, but check the speech bubble example for a demo of how this might work

Copy link

vercel bot commented Feb 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
examples ❌ Failed (Inspect) Mar 7, 2024 2:51pm
1 Ignored Deployment
Name Status Preview Updated (UTC)
tldraw-docs ⬜️ Ignored (Inspect) Visit Preview Mar 7, 2024 2:51pm

@mimecuvalo
Copy link
Collaborator

neat exploration! i'd be curious to talk more about this option with you @SomeHats and your hesitation now that you've implemented it. i think initial sketch of it seems compelling to me as a first impression. i don't like how it has to be wired up via onMount but i could be convinced?

@steveruizok steveruizok changed the title [prototype] Controls [experiment] Controls Mar 7, 2024
@steveruizok steveruizok mentioned this pull request Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants