Skip to content

Commit

Permalink
Few fixes for the compact instance properties editor (#6547)
Browse files Browse the repository at this point in the history
- Improve panel spacing
- Remove Restore icon on dimension fields if the instance uses the default size.
- When locking/unlocking multiple instances, apply same value to every instances
  • Loading branch information
AlexandreSi committed May 2, 2024
1 parent 2223b65 commit b7a4bab
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 26 deletions.
47 changes: 38 additions & 9 deletions newIDE/app/src/CompactPropertiesEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export type PrimitiveValueField =
label: string,
tooltipContent: React.Node,
|},
getEndAdornmentIcon?: () => React.Node,
getEndAdornmentIcon?: Instance => ?(className: string) => React.Node,
onClickEndAdornment?: Instance => void,
renderLeftIcon?: (className?: string) => React.Node,
...ValueFieldCommonProperties,
Expand All @@ -69,7 +69,7 @@ export type PrimitiveValueField =
label: string,
labelIsUserDefined?: boolean,
|}>,
getEndAdornmentIcon?: () => React.Node,
getEndAdornmentIcon?: Instance => ?(className: string) => React.Node,
onClickEndAdornment?: Instance => void,
renderLeftIcon?: (className?: string) => React.Node,
...ValueFieldCommonProperties,
Expand All @@ -86,6 +86,7 @@ export type PrimitiveValueField =
getValue: Instance => any,
isHighlighted: (value: any) => boolean,
setValue: (instance: Instance, newValue: any) => void,
getNextValue: (currentValue: any) => any,
...ValueFieldCommonProperties,
|}
| {|
Expand Down Expand Up @@ -257,16 +258,40 @@ const getFieldValue = ({
if (!getValue) return null;

let value = getValue(instances[0]);
for (var i = 1; i < instances.length; ++i) {
if (value !== getValue(instances[i])) {
if (typeof defaultValue !== 'undefined') value = defaultValue;
break;
if (typeof defaultValue !== 'undefined') {
for (var i = 1; i < instances.length; ++i) {
if (value !== getValue(instances[i])) {
value = defaultValue;
break;
}
}
}

return value;
};

const getFieldEndAdornmentIcon = ({
instances,
field,
}: {|
instances: Instances,
field: ValueField,
|}): ?(className: string) => React.Node => {
if (!instances[0]) {
console.warn(
'getFieldEndAdornmentIcon was called with an empty list of instances (or containing undefined). This is a bug that should be fixed.'
);
return null;
}
if (!field.getEndAdornmentIcon) return null;

for (const instance of instances) {
const getEndAdornmentIcon = field.getEndAdornmentIcon(instance);
if (getEndAdornmentIcon) return getEndAdornmentIcon;
}
return null;
};

const getFieldLabel = ({
instances,
field,
Expand Down Expand Up @@ -386,7 +411,8 @@ const CompactPropertiesEditor = ({
_onInstancesModified(instances);
},
disabled: getDisabled({ instances, field }),
renderEndAdornmentOnHover: field.getEndAdornmentIcon || undefined,
renderEndAdornmentOnHover:
getFieldEndAdornmentIcon({ instances, field }) || undefined,
onClickEndAdornment: () => {
if (!onClickEndAdornment) return;
instances.forEach(i => onClickEndAdornment(i));
Expand Down Expand Up @@ -466,7 +492,9 @@ const CompactPropertiesEditor = ({
tooltip={getFieldLabel({ instances, field })}
selected={field.isHighlighted(value)}
onClick={event => {
instances.forEach(i => field.setValue(i, !value));
instances.forEach(i =>
field.setValue(i, field.getNextValue(value))
);
_onInstancesModified(instances);
}}
>
Expand Down Expand Up @@ -515,7 +543,8 @@ const CompactPropertiesEditor = ({
_onInstancesModified(instances);
},
disabled: getDisabled({ instances, field }),
renderEndAdornmentOnHover: field.getEndAdornmentIcon || undefined,
renderEndAdornmentOnHover:
getFieldEndAdornmentIcon({ instances, field }) || undefined,
onClickEndAdornment: () => {
if (!onClickEndAdornment) return;
instances.forEach(i => onClickEndAdornment(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,21 @@ const getTitleRow = ({ i18n }: {| i18n: I18nType |}) => ({
: instance.isLocked()
? 'locked'
: 'free',
setValue: (instance: gdInitialInstance, newValue: boolean) => {
if (instance.isSealed()) {
instance.setSealed(false);
instance.setLocked(false);
return;
}
if (instance.isLocked()) {
instance.setSealed(true);
return;
}
instance.setLocked(true);
setValue: (
instance: gdInitialInstance,
newValue: 'sealed' | 'locked' | 'free'
) => {
instance.setSealed(newValue === 'sealed' ? true : false);
instance.setLocked(
newValue === 'sealed' || newValue === 'locked' ? true : false
);
},
getNextValue: (
currentValue: 'sealed' | 'locked' | 'free'
): 'sealed' | 'locked' | 'free' => {
if (currentValue === 'free') return 'locked';
if (currentValue === 'locked') return 'sealed';
return 'free';
},
},
],
Expand Down Expand Up @@ -251,7 +255,12 @@ const getWidthField = ({
forceUpdate();
},
renderLeftIcon: className => <LetterW className={className} />,
getEndAdornmentIcon: className => <Restore className={className} />,
getEndAdornmentIcon: (instance: gdInitialInstance) => {
if (instance.hasCustomDepth() || instance.hasCustomSize()) {
return className => <Restore className={className} />;
}
return null;
},
onClickEndAdornment: (instance: gdInitialInstance) => {
instance.setHasCustomSize(false);
instance.setHasCustomDepth(false);
Expand Down Expand Up @@ -307,7 +316,12 @@ const getHeightField = ({
forceUpdate();
},
renderLeftIcon: className => <LetterH className={className} />,
getEndAdornmentIcon: className => <Restore className={className} />,
getEndAdornmentIcon: (instance: gdInitialInstance) => {
if (instance.hasCustomDepth() || instance.hasCustomSize()) {
return className => <Restore className={className} />;
}
return null;
},
onClickEndAdornment: (instance: gdInitialInstance) => {
instance.setHasCustomSize(false);
instance.setHasCustomDepth(false);
Expand Down Expand Up @@ -363,7 +377,12 @@ const getDepthField = ({
forceUpdate();
},
renderLeftIcon: className => <LetterD className={className} />,
getEndAdornmentIcon: className => <Restore className={className} />,
getEndAdornmentIcon: (instance: gdInitialInstance) => {
if (instance.hasCustomDepth() || instance.hasCustomSize()) {
return className => <Restore className={className} />;
}
return null;
},
onClickEndAdornment: (instance: gdInitialInstance) => {
instance.setHasCustomSize(false);
instance.setHasCustomDepth(false);
Expand Down Expand Up @@ -392,6 +411,7 @@ const getKeepRatioField = ({
getValue: (instance: gdInitialInstance) => instance.shouldKeepRatio(),
setValue: (instance: gdInitialInstance, newValue: boolean) =>
instance.setShouldKeepRatio(newValue),
getNextValue: (currentValue: boolean) => !currentValue,
});
export const makeSchema = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import propertiesMapToSchema from '../../CompactPropertiesEditor/PropertiesMapTo
import { type Schema } from '../../CompactPropertiesEditor';
import getObjectByName from '../../Utils/GetObjectByName';
import IconButton from '../../UI/IconButton';
import { Line, Column, Spacer } from '../../UI/Grid';
import { Line, Column, Spacer, marginsSize } from '../../UI/Grid';
import Text from '../../UI/Text';
import { type UnsavedChanges } from '../../MainFrame/UnsavedChangesContext';
import ScrollView from '../../UI/ScrollView';
Expand All @@ -38,6 +38,7 @@ export const styles = {
icon: {
fontSize: 18,
},
scrollView: { paddingTop: marginsSize },
};

const gd: libGDevelop = global.gd;
Expand Down Expand Up @@ -149,6 +150,7 @@ const CompactInstancePropertiesEditor = ({
>
<ScrollView
autoHideScrollbar
style={styles.scrollView}
key={instances
.map((instance: gdInitialInstance) => '' + instance.ptr)
.join(';')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const CompactSemiControlledNumberField = ({
onBlur={event => {
const newValue = parseFloat(event.currentTarget.value);
const isNewValueValid = !Number.isNaN(newValue);
if (isNewValueValid) {
if (isNewValueValid && newValue !== value) {
onChange(newValue);
}
setFocused(false);
Expand Down
4 changes: 3 additions & 1 deletion newIDE/app/src/UI/CompactSemiControlledTextField/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ const CompactSemiControlledTextField = ({
if (!commitOnBlur) onChange(newValue);
}}
onBlur={event => {
onChange(event.currentTarget.value);
if (value !== event.currentTarget.value) {
onChange(event.currentTarget.value);
}
setFocused(false);
setText('');
}}
Expand Down

0 comments on commit b7a4bab

Please sign in to comment.