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

Inhibit clipping when dropdown is opened #9434

Merged
merged 4 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions app/gui2/src/components/GraphEditor/NodeWidgetTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { provideWidgetTree } from '@/providers/widgetTree'
import { useGraphStore, type NodeId } from '@/stores/graph'
import { Ast } from '@/util/ast'
import type { Icon } from '@/util/iconName'
import { computed, toRef } from 'vue'
import { computed, ref, toRef } from 'vue'

const props = defineProps<{
ast: Ast.Ast
Expand Down Expand Up @@ -65,6 +65,8 @@ function handleWidgetUpdates(update: WidgetUpdate) {
return true
}

const deepDisableClipping = ref(false)

const layoutTransitions = useTransitioning(observedLayoutTransitions)
provideWidgetTree(
toRef(props, 'ast'),
Expand All @@ -77,6 +79,7 @@ provideWidgetTree(
() => {
emit('openFullMenu')
},
(clippingInhibitorsExist) => (deepDisableClipping.value = clippingInhibitorsExist),
)
</script>
<script lang="ts">
Expand All @@ -86,7 +89,12 @@ export const ICON_WIDTH = 16
</script>

<template>
<div class="NodeWidgetTree" spellcheck="false" v-on="layoutTransitions.events">
<div
class="NodeWidgetTree"
:class="{ deepDisableClipping }"
spellcheck="false"
v-on="layoutTransitions.events"
>
<!-- Display an icon for the node if no widget in the tree provides one. -->
<SvgIcon
v-if="!props.connectedSelfArgumentId"
Expand Down Expand Up @@ -128,4 +136,8 @@ export const ICON_WIDTH = 16
color: white;
margin: 0 v-bind('GRAB_HANDLE_X_MARGIN_PX');
}

.deepDisableClipping :deep(.overridableClipState) {
overflow: visible !important;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export const widgetDefinition = defineWidget(ArgumentApplicationKey, {
<NodeWidget :input="WidgetInput.FromAst(application.infixOperator)" />
</div>
<Transition name="collapse-argument">
<div v-if="tree.extended || !application.argument.hideByDefault" class="argument">
<div
v-if="tree.extended || !application.argument.hideByDefault"
class="argument overridableClipState"
>
Comment on lines +51 to +54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it the only place which may clip drop-down? Could node clip the leftmost drop-down?

Copy link
Contributor Author

@kazcw kazcw Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents the clipping required by the hidden-placeholders animation from interfering with the dropdown. I don't think we have any other animations that could clip the dropdown, but if we do this solution could be applied to them. If any widget is enabling clipping on its children statically, that would be a separate problem with a different solution (the widget must not do that).

<NodeWidget :input="application.argument.toWidgetInput()" nest />
</div>
</Transition>
Expand Down
11 changes: 10 additions & 1 deletion app/gui2/src/components/widgets/DropdownWidget.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script setup lang="ts">
import SvgIcon from '@/components/SvgIcon.vue'
import { injectWidgetTree } from '@/providers/widgetTree'
import type { Icon } from '@/util/iconName'
import { computed, ref } from 'vue'
import { computed, onMounted, onUnmounted, ref } from 'vue'

enum SortDirection {
none = 'none',
Expand All @@ -12,6 +13,14 @@ enum SortDirection {
const props = defineProps<{ color: string; selectedValue: string | undefined; values: string[] }>()
const emit = defineEmits<{ click: [index: number, keepOpen: boolean] }>()

const tree = injectWidgetTree()

let endClippingInhibition: (() => void) | undefined
onMounted(() => {
endClippingInhibition = tree.inhibitClipping()
})
onUnmounted(() => endClippingInhibition?.())

kazcw marked this conversation as resolved.
Show resolved Hide resolved
const sortDirection = ref<SortDirection>(SortDirection.none)

const sortedValuesAndIndices = computed(() => {
Expand Down
17 changes: 17 additions & 0 deletions app/gui2/src/providers/widgetTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ import { Ast } from '@/util/ast'
import type { Icon } from '@/util/iconName'
import { computed, proxyRefs, type Ref } from 'vue'

function makeExistenceRegistry(onChange: (anyExist: boolean) => void) {
kazcw marked this conversation as resolved.
Show resolved Hide resolved
const registered = new Set<number>()
let nextId = 0
return () => {
const id = nextId++
if (registered.size === 0) onChange(true)
registered.add(id)
return () => {
registered.delete(id)
if (registered.size === 0) onChange(false)
}
}
}

export { injectFn as injectWidgetTree, provideFn as provideWidgetTree }
const { provideFn, injectFn } = createContextStore(
'Widget tree',
Expand All @@ -17,9 +31,11 @@ const { provideFn, injectFn } = createContextStore(
extended: Ref<boolean>,
hasActiveAnimations: Ref<boolean>,
emitOpenFullMenu: () => void,
clippingInhibitorsChanged: (anyExist: boolean) => void,
) => {
const graph = useGraphStore()
const nodeSpanStart = computed(() => graph.moduleSource.getSpan(astRoot.value.id)![0])
const inhibitClipping = makeExistenceRegistry(clippingInhibitorsChanged)
return proxyRefs({
astRoot,
nodeId,
Expand All @@ -30,6 +46,7 @@ const { provideFn, injectFn } = createContextStore(
nodeSpanStart,
hasActiveAnimations,
emitOpenFullMenu,
inhibitClipping,
})
},
)
Loading