Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Sep 30, 2023
1 parent 0fed88a commit ea2eb6a
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 144 deletions.
4 changes: 4 additions & 0 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const testNumber = ref(Math.PI)
const testBoolean = ref(false)
const testAlign = ref<'left' | 'center' | 'right'>('left')
const colorSpace = ref<'r|g|b' | 'svh' | 'hsv' | 'hvs' | 'hsvr'>('hsv')
const cubicBezier = ref([0, 0.5, 0.5, 1] as const)
// interface PaperDesc {
// id?: string
Expand Down Expand Up @@ -438,6 +439,9 @@ window.addEventListener('drop', async e => {
<Tq.Parameter label="Button">
<Tq.InputButton label="Hey" />
</Tq.Parameter>
<Tq.Parameter label="Button">
<Tq.InputCubicBezierPicker v-model="cubicBezier" />
</Tq.Parameter>
</Tq.ParameterGrid>
</Tq.FloatingPane>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/tweeq/FloatingPane/FloatingPane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ onMounted(() => {
right 0
bottom 0
left 0
overflow hidden
&:has(.resize:hover)
border-color var(--tq-color-primary)
Expand Down
59 changes: 29 additions & 30 deletions src/tweeq/InputCubicBezier/InputCubicBezier.vue
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
<template>
<button
ref="buttonEl"
class="InputCubicBezier"
:class="{opened}"
v-bind="$attrs"
@click="opened = true"
>
<svg class="InputCubicBezier__icon" viewBox="0 0 1 1">
<path :d="easingPath" />
</svg>
</button>
<Popover ref="$button" v-model:open="opened" placement="bottom">
<div class="InputCubicBezier__popover-frame">
<InputCubicBezierPicker
:modelValue="modelValue"
@update:modelValue="$emit('update:modelValue', $event)"
/>
</div>
</Popover>
</template>

<script lang="ts" setup>
import {computed, ref} from 'vue'
import Popover from '../Popover.vue'
import InputCubicBezierPicker from './InputCubicBezierPicker.vue'
import {CubicBezier} from './types'
import {CubicBezierValue} from './util'
interface Props {
modelValue: CubicBezier
modelValue: CubicBezierValue
}
const props = defineProps<Props>()
defineEmits<{
'update:modelValue': [CubicBezier]
const emit = defineEmits<{
'update:modelValue': [CubicBezierValue]
}>()
defineOptions({
inheritAttrs: false,
})
const $button = ref<HTMLElement | null>(null)
const opened = ref(false)
const open = ref(false)
const easingPath = computed(() => {
const [x1, y1, x2, y2] = props.modelValue
return `M 0,0 C ${x1},${y1} ${x2},${y2} 1,1`
})
</script>

<template>
<button
ref="buttonEl"
class="InputCubicBezier"
:class="{open}"
v-bind="$attrs"
@click="open = true"
>
<svg class="InputCubicBezier__icon" viewBox="0 0 1 1">
<path :d="easingPath" />
</svg>
</button>
<Popover v-model:open="open" :reference="$button" placement="bottom">
<div class="InputCubicBezier__popover-frame">
<InputCubicBezierPicker
:modelValue="modelValue"
@update:modelValue="emit('update:modelValue', $event)"
/>
</div>
</Popover>
</template>

<style lang="stylus">
@import '../common.styl'
Expand All @@ -65,8 +64,8 @@ const easingPath = computed(() => {
&:focus
background base16('01')
&:hover, &.opened
background base16('accent', 0.5)
&:hover, &.open
background red
&__icon
margin $subcontrol-margin
Expand Down
154 changes: 75 additions & 79 deletions src/tweeq/InputCubicBezier/InputCubicBezierPicker.vue
Original file line number Diff line number Diff line change
@@ -1,107 +1,103 @@
<template>
<div class="InputCubicBezierPicker">
<svg ref="editor" viewBox="0 0 1 1" class="InputCubicBezierPicker__editor">
<g>
<line :x1="0" :y1="0" :x2="x1" :y2="y1" />
<line :x1="1" :y1="1" :x2="x2" :y2="y2" />
<path :d="easingPath" />
<circle :cx="x1" :cy="y1" r=".035" @mousedown="draggingPoint = 0" />
<circle :cx="x2" :cy="y2" r=".035" @mousedown="draggingPoint = 1" />
</g>
</svg>
</div>
</template>

<script lang="ts">
<script lang="ts" setup>
import {templateRef} from '@vueuse/core'
import {clamp} from 'lodash'
import {computed, defineComponent, PropType, ref} from 'vue-demi'
import {CubicBezierPoints} from '@vueuse/core'
import {vec2} from 'linearly'
import {computed, ref} from 'vue-demi'
import useDrag from '@/tweeq/useDragV1'
export default defineComponent({
name: 'InputCubicBezierPicker',
props: {
modelValue: {
type: Array as PropType<number[]>,
required: true,
},
},
emit: ['update:modelValue'],
setup(props, context) {
const editorEl = templateRef<HTMLElement>('editor')
useDrag(editorEl, {
onDrag({pos, left, right, top, bottom}) {
if (draggingPoint.value === null) return
import {CubicBezierValue} from './util'
let x = (pos[0] - left) / (right - left)
let y = 1 - (pos[1] - top) / (bottom - top)
interface Props {
modelValue: CubicBezierValue
}
x = clamp(x, 0, 1)
y = clamp(y, 0, 1)
const props = defineProps<Props>()
const newValue = [...props.modelValue]
const emit = defineEmits<{
'update:modelValue': [CubicBezierValue]
}>()
newValue[draggingPoint.value * 2 + 0] = x
newValue[draggingPoint.value * 2 + 1] = y
const $editor = templateRef<HTMLElement>('$editor')
context.emit('update:modelValue', newValue)
},
onDragEnd() {
draggingPoint.value = null
},
})
useDrag($editor, {
onDrag({pos, left, right, top, bottom}) {
if (draggingPoint.value === null) return
const easingPath = computed(() => {
const [x1, y1, x2, y2] = props.modelValue
return `M 0,0 C ${x1},${y1} ${x2},${y2} 1,1`
})
const uv = vec2.invlerp([left, bottom], [right, top], pos)
const [x, y] = vec2.clamp(uv, [0, 0], [1, 1])
const x1 = computed(() => props.modelValue[0])
const y1 = computed(() => props.modelValue[1])
const x2 = computed(() => props.modelValue[2])
const y2 = computed(() => props.modelValue[3])
const newValue: CubicBezierPoints = [...props.modelValue]
const draggingPoint = ref<number | null>(null)
newValue[draggingPoint.value * 2 + 0] = x
newValue[draggingPoint.value * 2 + 1] = y
return {easingPath, x1, y1, x2, y2, draggingPoint}
emit('update:modelValue', newValue)
},
onDragEnd() {
draggingPoint.value = null
},
})
const easingPath = computed(() => {
const [x1, y1, x2, y2] = props.modelValue
return `M 0,0 C ${x1},${y1} ${x2},${y2} 1,1`
})
const x1 = computed(() => props.modelValue[0])
const y1 = computed(() => props.modelValue[1])
const x2 = computed(() => props.modelValue[2])
const y2 = computed(() => props.modelValue[3])
const draggingPoint = ref<number | null>(null)
</script>

<template>
<div class="InputCubicBezierPicker">
<svg ref="$editor" viewBox="0 0 1 1" class="pad">
<g>
<line :x1="0" :y1="0" :x2="x1" :y2="y1" />
<line :x1="1" :y1="1" :x2="x2" :y2="y2" />
<path :d="easingPath" />
<circle :cx="x1" :cy="y1" r=".035" @mousedown="draggingPoint = 0" />
<circle :cx="x2" :cy="y2" r=".035" @mousedown="draggingPoint = 1" />
</g>
</svg>
</div>
</template>

<style lang="stylus">
@import '../common.styl'
.InputCubicBezierPicker
&__editor
overflow visible
margin 0.8em
width calc(100% - 1.6em)
.pad
overflow visible
margin 0.8em
width calc(100% - 1.6em)
*
vector-effect non-scaling-stroke
*
vector-effect non-scaling-stroke
g
transform scaleY(-1)
transform-origin 50% 50%
g
transform scaleY(-1)
transform-origin 50% 50%
path, line, circle
fill none
stroke-linecap round
path, line, circle
fill none
stroke-linecap round
path, circle
stroke-width 2
stroke base16('05')
path, circle
stroke-width 2
stroke var(--tq-color-primary)
line
stroke-width 1
stroke base16('03')
line
stroke-width 1
stroke var(--md-sys-color-outline)
circle
fill var(--tq-color-text)
circle
fill var(--tq-color-bg)
hover-transition(fill, stroke)
&:hover
fill var(--tq-color-primary)
stroke var(--tq-color-primary)
&:hover
fill var(--tq-color-primary)
stroke var(--tq-color-primary)
</style>
3 changes: 2 additions & 1 deletion src/tweeq/InputCubicBezier/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import InputCubicBezier from './InputCubicBezier.vue'
import InputCubicBezierPicker from './InputCubicBezierPicker.vue'

export default InputCubicBezier
export {InputCubicBezier, InputCubicBezierPicker}
1 change: 0 additions & 1 deletion src/tweeq/InputCubicBezier/types.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/tweeq/InputCubicBezier/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type CubicBezierValue = readonly [number, number, number, number]
15 changes: 10 additions & 5 deletions src/tweeq/InputNumber/InputNumber.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {useElementBounding, useFocus, useKeyModifier} from '@vueuse/core'
import {useWheel} from '@vueuse/gesture'
import {scalar, Vec2} from 'linearly'
import {computed, ref, watch, watchEffect} from 'vue'
import {computed, ref, watch} from 'vue'
import {useDrag} from '../useDrag'
import {toFixed, unsignedMod} from '../util'
Expand Down Expand Up @@ -222,11 +222,16 @@ const onBlur = () => {
}
}
watchEffect(() => {
if (tweaking.value) {
display.value = props.modelValue.toFixed(tweakPrecision.value)
watch(
() => [props.modelValue, tweaking.value, tweakPrecision.value] as const,
([modelValue, tweaking]) => {
if (tweaking) {
display.value = modelValue.toFixed(tweakPrecision.value)
} else {
display.value = toFixed(modelValue, props.precision)
}
}
})
)
const scaleOffset = ref(0)
Expand Down
Loading

0 comments on commit ea2eb6a

Please sign in to comment.