Skip to content

Commit a8eb955

Browse files
committed
Implement inspector dropdown widget for enum values
1 parent 29f7c4e commit a8eb955

File tree

3 files changed

+107
-14
lines changed

3 files changed

+107
-14
lines changed

etc/js/components/widgets/dropdown.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ const props = defineProps({
4646
label: {type: String, required: false},
4747
postfix: {type: String, required: false},
4848
transparent: {type: Boolean, required: false, default: false},
49+
auto_select_first: {type: Boolean, required: false, default: true},
4950
});
5051
5152
const activeItem = defineModel("active_item");
5253
const showList = ref(false);
5354
const dropdown = ref(null);
5455
5556
onMounted(() => {
56-
if (!activeItem.value) {
57+
if (props.auto_select_first && !activeItem.value) {
5758
activeItem.value = props.items[0];
5859
}
5960
@@ -77,6 +78,10 @@ function onClick() {
7778
}
7879
7980
function onWindowClick(event) {
81+
if (!dropdown.value) {
82+
return;
83+
}
84+
8085
// Close if the dropdown doesn't contain the clicked element
8186
if (!dropdown.value.contains(event.target)) {
8287
showList.value = false;

etc/js/components/widgets/inspector/entity-inspector-component.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ div.component-name-inherited {
310310
div.component-value {
311311
padding-left: 20px;
312312
padding-right: 24px;
313-
overflow-x: hidden;
313+
overflow: visible;
314314
overflow-wrap: break-word;
315315
}
316316

etc/js/components/widgets/inspector/entity-inspector-field.vue

Lines changed: 100 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,27 @@
44
</template>
55
<template v-else>
66
<div :class="css">
7-
<input
8-
type="text"
9-
ref="editEl"
10-
@click.stop
11-
@focus="onFocus"
12-
@blur="onBlur"
13-
@mousedown.stop="onMouseDown"
14-
@keydown.enter="onSubmit"
15-
@keydown.esc="onCancel">
7+
<template v-if="isEnumType">
8+
<dropdown
9+
class="enum-field-dropdown"
10+
:items="enumItems"
11+
:auto_select_first="false"
12+
v-model:active_item="localValue"
13+
@update:active_item="onEnumSelect"
14+
@click.stop>
15+
</dropdown>
16+
</template>
17+
<template v-else>
18+
<input
19+
type="text"
20+
ref="editEl"
21+
@click.stop
22+
@focus="onFocus"
23+
@blur="onBlur"
24+
@mousedown.stop="onMouseDown"
25+
@keydown.enter="onSubmit"
26+
@keydown.esc="onCancel">
27+
</template>
1628
</div>
1729
</template>
1830
</template>
@@ -53,6 +65,9 @@ let dragging = {
5365
const css = computed(() => {
5466
let classes = ["input-wrapper", props.class];
5567
classes.push(`value-${props.type[0]}`);
68+
if (isEnumType.value) {
69+
classes.push("value-dropdown");
70+
}
5671
5772
if (props.readonly) {
5873
classes.push(`${props.class}-readonly`);
@@ -68,8 +83,20 @@ const isNumberType = computed(() => {
6883
return props.type[0] === "float" || props.type[0] === "int";
6984
});
7085
86+
const isEnumType = computed(() => {
87+
return Array.isArray(props.type) && props.type[0] === "enum";
88+
});
89+
90+
const enumItems = computed(() => {
91+
if (!isEnumType.value) {
92+
return [];
93+
}
94+
return props.type.slice(1).filter((item) => typeof item === "string");
95+
});
96+
7197
const unit = computed(() => {
72-
if (props.type.length > 1) {
98+
if (Array.isArray(props.type) && props.type.length > 1 &&
99+
typeof props.type[1] === "object") {
73100
return props.type[1];
74101
}
75102
});
@@ -162,6 +189,13 @@ function onSubmit() {
162189
emit("setValue", {value: localValue.value});
163190
}
164191
192+
function onEnumSelect(value) {
193+
if (isEnumType.value) {
194+
localValue.value = value;
195+
emit("setValue", {value: value});
196+
}
197+
}
198+
165199
function onCancel() {
166200
editMode.value = "default";
167201
dragging.instance = null;
@@ -241,16 +275,62 @@ div.value input {
241275
cursor: text;
242276
}
243277
278+
div.value :deep(div.enum-field-dropdown) {
279+
width: 100%;
280+
display: block;
281+
box-sizing: border-box;
282+
background-color: var(--bg-input);
283+
position: relative;
284+
z-index: 10;
285+
}
286+
287+
div.value :deep(div.enum-field-dropdown:hover) {
288+
background-color: var(--bg-button-hover);
289+
}
290+
291+
div.value-dropdown {
292+
overflow: visible;
293+
}
294+
295+
div.value :deep(div.enum-field-dropdown div.dropdown-container) {
296+
grid-template-columns: 1fr 32px;
297+
}
298+
299+
div.value :deep(div.enum-field-dropdown div.dropdown-text) {
300+
padding: 4px;
301+
padding-left: 8px;
302+
}
303+
304+
div.value :deep(div.enum-field-dropdown div.dropdown-button) {
305+
padding: 4px;
306+
text-align: right;
307+
}
308+
309+
div.value :deep(div.enum-field-dropdown div.dropdown-list) {
310+
top: calc(100% + 2px);
311+
left: 0;
312+
z-index: 999;
313+
}
314+
244315
div.value-readonly input {
245316
/* background-color: var(--bg-input); */
246317
cursor: default;
247318
opacity: 0.8;
248319
}
249320
321+
div.value-readonly :deep(div.enum-field-dropdown) {
322+
cursor: default;
323+
opacity: 0.8;
324+
}
325+
250326
div.value-compact input {
251327
white-space: nowrap;
252328
}
253329
330+
div.value-compact :deep(div.enum-field-dropdown div.dropdown-text) {
331+
white-space: nowrap;
332+
}
333+
254334
div.value-bool, div.value-bool input {
255335
color: #4981B5;
256336
}
@@ -272,7 +352,15 @@ div.value-entity, div.value-entity input {
272352
}
273353
274354
div.value-enum, div.value-enum input, div.value-bitmask, div.value-bitmask input {
275-
color: #7D67B5;
355+
color: var(--light-green);
356+
}
357+
358+
div.value-enum :deep(span.dropdown-text-active) {
359+
color: var(--light-green);
360+
}
361+
362+
div.value-enum :deep(li.dropdown-item) {
363+
color: var(--primary-text);
276364
}
277365
278366
</style>
@@ -285,4 +373,4 @@ html.cursor-ew * {
285373
cursor: inherit !important;
286374
}
287375
288-
</style>
376+
</style>

0 commit comments

Comments
 (0)