Skip to content

Commit

Permalink
Add back null microcontroller, change controls space in abs mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rianadon committed Dec 22, 2024
1 parent 43dae97 commit 7a738c9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
6 changes: 5 additions & 1 deletion src/lib/3d/TransformControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
export let visible = true
export let snap: boolean
export let useAbsolute = false
let controls: TC
const dispatch = createEventDispatcher()
Expand Down Expand Up @@ -58,7 +59,10 @@
<TransformControls
object={ref}
size={0.9}
space={$transformMode == 'translate' && $selectMode == 'cluster' ? 'world' : 'local'}
space={($transformMode == 'translate' && $selectMode == 'cluster') ||
(useAbsolute && $selectMode == 'key')
? 'world'
: 'local'}
mode={$transformMode}
rotationSnap={snap ? Math.PI / 2 : undefined}
bind:controls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<span>{option.label}</span>
</div>

{#if $tooltipOpen}
{#if $tooltipOpen && option.key !== null}
<div
use:melt={$content}
transition:fade={{ duration: 50 }}
Expand Down
19 changes: 7 additions & 12 deletions src/routes/beta/lib/editor/SelectThingy.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
export let options: Option[] | Record<string, Option[]>
const allOptions = Array.isArray(options) ? options : Object.values(options).flat()
const toOption = (option: Option): SelectOptionProps<string> => ({
value: option.key,
label: option.label,
disabled: false,
})
const toOption = (option: Option | undefined): SelectOptionProps<string> =>
option
? { value: option.key, label: option.label, disabled: false }
: { value: '', label: '', disabled: true }
export let value: string
export let clazz: string = ''
Expand All @@ -41,7 +40,7 @@
// This DX is pretty bad.
const sync = createSync({ selected })
$: sync.selected(toOption(allOptions.find((opt) => opt.key == value)!), (v) => v && (value = v.value))
$: sync.selected(toOption(allOptions.find((opt) => opt.key == value)), (v) => v && (value = v.value))
export let component: ComponentType<SvelteComponent<{ option: Option }>>
export let labelComponent: ComponentType<SvelteComponent<{ option: { label: string; value: string } }>>
Expand All @@ -51,15 +50,11 @@
</script>

<div class="relative">
<button
use:melt={$trigger}
class={clazz || 's-input pl-2 pr-8 truncate text-start'}
placeholder="Choose Switch"
>
<button use:melt={$trigger} class={clazz || 's-input pl-2 pr-8 truncate text-start'}>
{#if labelComponent && $selected}
<svelte:component this={labelComponent} option={$selected} />
{:else}
{$selectedLabel || 'Select a Switch'}
{$selectedLabel || 'Choose One'}
{/if}
</button>
<div class="absolute right-4 top-1/2 z-10 -translate-y-1/2">
Expand Down
31 changes: 17 additions & 14 deletions src/routes/beta/lib/editor/VisualEditor2.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1043,20 +1043,23 @@
<SelectThingy
bind:value={$protoConfig.microcontroller}
on:change={updateMicrocontroller}
options={Object.fromEntries(
MICROCONTROLLER_SIZES.map((s) => [
s,
notNull(MICROCONTROLLER_NAME)
.filter(
(m) => BOARD_PROPERTIES[m].sizeName == s && (flags.draftuc || !BOARD_PROPERTIES[m].draft)
)
.sort(sortMicrocontrollers)
.map((m) => ({
key: m,
label: BOARD_PROPERTIES[m].name + ' ' + (BOARD_PROPERTIES[m].extraName || ''),
})),
])
)}
options={{
...Object.fromEntries(
MICROCONTROLLER_SIZES.map((s) => [
s,
notNull(MICROCONTROLLER_NAME)
.filter(
(m) => BOARD_PROPERTIES[m].sizeName == s && (flags.draftuc || !BOARD_PROPERTIES[m].draft)
)
.sort(sortMicrocontrollers)
.map((m) => ({
key: m,
label: BOARD_PROPERTIES[m].name + ' ' + (BOARD_PROPERTIES[m].extraName || ''),
})),
])
),
More: [{ key: null, label: 'None' }],
}}
component={SelectMicrocontrollerInner}
/>
<!-- <Select bind:value={$protoConfig.microcontroller} on:change={updateMicrocontroller}>
Expand Down
1 change: 1 addition & 0 deletions src/routes/beta/lib/viewers/Viewer3D.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,7 @@
<TransformControls
snap={snapRotation}
visible={!showSupports}
useAbsolute={$useAbsolute}
on:move={(e) => onMove(e.detail, false)}
on:change={(e) => onMove(e.detail, true)}
/>
Expand Down

0 comments on commit 7a738c9

Please sign in to comment.