Files
storyteller-bevy/studio-ui/src/lib/forms/text-field.element.ts
T
Danny McGee 0d4072c806 Inspector editing (#96)
This PR adds Material component inspection to the frontend Entity
Inspector, and adds functional editing capabilities for the Transform
and Material inspectors.

### Changes
* Added a `ScalarFieldElement` for numeric form fields, with a hybrid
slider/text-input UX inspired by Blender, Unreal Engine, etc.
* Added `MaterialInspectorElement` for inspecting the Bevy
`StandardMaterial` component
* Wired up the `TransformInspectorElement` and
`MaterialInspectorElement` to apply changes made in the UI to the Bevy
scene
* Refactored the `studio/ui/inspector` module to output `Result::Err`s
to the dev console
* Refactored the `studio/interaction/selection` module to use only the
`Selection` resource, removing the redundant `Selected` component which
added some unnecessary complexity. This fixes #39
* Fixed primitive shapes not receiving a selection outline when selected

### To-Do

These tasks will be addressed in a forthcoming PR:

* The **Transform** > **Rotation** section in the inspector is still not
displaying sensible values. Currently it's just displaying the raw
quaternion `xyz` vector rather than displaying the orientation in
human-readable terms (e.g., as Euler angles).
* We're currently ignoring the Primitive Shape component, which would
allow the user to configure some additional geometric properties of the
shape or replace it with a different one.

---------

Co-authored-by: rewin <rewin1996@gmail.com>
2024-03-22 18:53:28 -04:00

60 lines
1.5 KiB
TypeScript

import { on } from "@storyteller/framework";
import { html, nothing, unsafeCSS } from "lit";
import { customElement, property } from "lit/decorators.js";
import { ifDefined } from "lit/directives/if-defined.js";
import { FormFieldBaseElement } from "./form-field-base.element";
import styles from "./text-field.element.scss?inline";
@customElement("sts-text-field")
export class TextFieldElement extends FormFieldBaseElement {
static override styles = unsafeCSS(styles);
static override shadowRootOptions: ShadowRootInit = {
mode: "open",
delegatesFocus: true,
}
@property({
attribute: "type",
reflect: true,
})
fieldType = "text";
@property() placeholder?: string;
@property() value = "";
@property({ attribute: "icon-pre" }) iconPre?: string;
@property({ attribute: "icon-post" }) iconPost?: string;
@on("keydown")
@on("keyup")
blockKeypressBubbling(event: KeyboardEvent): void {
if (event.key !== "Alt" && event.key !== "Control")
event.stopPropagation();
}
#onInput(event: InputEvent): void {
this.dispatchEvent(new CustomEvent("value-change", {
detail: (event.target as HTMLInputElement).value,
}));
}
protected override render = () => html`
${this.iconPre ? html`
<sts-icon part="icon-pre" .icon=${this.iconPre}></sts-icon>
` : nothing}
<input
class="input"
part="input"
.type=${this.fieldType}
placeholder=${ifDefined(this.placeholder)}
.value=${this.value}
@input=${this.#onInput}
/>
${this.iconPost ? html`
<sts-icon part="icon-post" .icon=${this.iconPost}></sts-icon>
` : nothing}
`;
}