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

Implement Dropdown Widgets. #8411

Merged
merged 2 commits into from
Nov 30, 2023

Conversation

MichaelMauderer
Copy link
Contributor

@MichaelMauderer MichaelMauderer commented Nov 28, 2023

Pull Request Description

Closes #8259

Peek.2023-11-28.12-22.webm

Important Notes

Some TODOs left for after the AST refactoring:

  • Updating the AST with the elected value.
  • Getting the Expr ID from the parent node to determine the correct color.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

@MichaelMauderer MichaelMauderer self-assigned this Nov 28, 2023
@MichaelMauderer MichaelMauderer added CI: No changelog needed Do not require a changelog entry for this PR. g-widgets labels Nov 28, 2023
@MichaelMauderer MichaelMauderer marked this pull request as ready for review November 28, 2023 14:51
<div class="WidgetDrodown">
<DropdownWidget
v-if="showDropdownWidget"
:color="parentColor"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this could just be a constant color="var(--node-color-primary)"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, it seems that var(--node-color-primary) can only be used in CSS. But this got me thinking about a workaround: get the style variable from an HTML element. This seems to work as intended now.

Copy link
Contributor

Choose a reason for hiding this comment

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

the color prop is passed directly to CSS though, so i believe @Frizi's suggestion should theoretically work

<DropdownWidget
v-if="showDropdownWidget"
:color="parentColor"
:values="tagLabels ?? []"
Copy link
Contributor

Choose a reason for hiding this comment

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

This ?? looks unnecessary, I think tagLabels should always be at least an empty array.

Comment on lines 70 to 76
<span class="WidgetArgumentName" @pointerdown="showDropdownWidget = !showDropdownWidget">
<template v-if="showArgumentValue">
<span class="name">{{ argName }}</span
><span> {{ selectedValue }} </span>
</template>
<template v-else>{{ argName }}</template>
</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

this part of the template is incorrect, you shouldn't be handling argument names within the drodpowns explicitly. We still want to show more complicated widget trees on elements that have dropdown choices, e.g to show nested function calls or array widgets within the selected expression. To properly render the dropdown as a wrapper widget around other widgets, you should use <NodeWidget :input="props.input" /> in some place. That way you allow other matching widgets to attach to the same node.

</template>
<template v-else>{{ argName }}</template>
</span>
<div class="WidgetDrodown">
Copy link
Contributor

Choose a reason for hiding this comment

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

Inconsistent class. It should be the same as the component name. Also, how about naming it WidgetSingleChoice?

// When the selected index changes, we update the expression content.
watch(selectedIndex, (_index) => {
console.warn('TODO: Update the expression content once the AST is updated.')
const id = '' // TODO: Get the id of the expression once the AST is updated.
Copy link
Contributor

Choose a reason for hiding this comment

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

To make it work at least in case of existing argument, you could use

const id = props.input instanceof ArgumentAst ? props.input.ast.astId : undefined

Copy link
Contributor

@Frizi Frizi left a comment

Choose a reason for hiding this comment

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

Still have a few questions/nits, but it's in good enough shape to merge into develop and keep working on it there.

@@ -34,7 +34,7 @@ export const widgetDefinition = defineWidget([ArgumentPlaceholder, ArgumentAst],
<template>
<span class="WidgetArgumentName" :class="{ placeholder, primary }">
<template v-if="showArgumentValue">
<span class="name">{{ props.input.info!.name }}</span
<span class="value">{{ props.input.info!.name }}</span
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why is this changed? That span is actually representing the argument name, not its value. The "value" is represented by the NodeWidget below.

<template>
<div ref="rootElement" class="WidgetRoot">
<span class="WidgetArgumentName" @pointerdown="showDropdownWidget = !showDropdownWidget">
<template v-if="showArgumentValue">
Copy link
Contributor

Choose a reason for hiding this comment

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

This ref is always true, right? I think you could remove this branch completely.

<div ref="rootElement" class="WidgetRoot">
<span class="WidgetArgumentName" @pointerdown="showDropdownWidget = !showDropdownWidget">
<template v-if="showArgumentValue">
<NodeWidget :input="props.input" /><span class="value"> {{ selectedValue }} </span>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not super sure why you need to display the selectedValue here, since the NodeWidget should on its own represent that value properly. I believe this may lead to repeated text.

@Frizi Frizi added the CI: Ready to merge This PR is eligible for automatic merge label Nov 30, 2023
@mergify mergify bot merged commit 2014c88 into develop Nov 30, 2023
31 of 32 checks passed
@mergify mergify bot deleted the wip/MichaelMauderer/gui2/Static-drop-downs branch November 30, 2023 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-gui CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Static drop-downs
3 participants