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

Allow extensions to define units of measurement for their properties #4576

Merged
merged 17 commits into from
Nov 30, 2022

Conversation

D8H
Copy link
Collaborator

@D8H D8H commented Nov 23, 2022

  • It use the scientific notation because it's the easiest to generate and it looks clean.
  • It only works for behavior properties. It will be hard to do for objects like the ParticleEmitter because there is no property metadata.
  • It doesn't allow event-based extensions to define units. I want to wait that everyone is ok with what is done for the built-in extensions because event-based extensions need a serialization and it's hard to go back.

image

@D8H D8H changed the title Allow extension to define units of measurement for their properties Allow extensions to define units of measurement for their properties Nov 23, 2022
@D8H D8H marked this pull request as ready for review November 24, 2022 16:29
@D8H D8H requested a review from 4ian as a code owner November 24, 2022 16:29
Comment on lines 7 to 13
// Strings are used instead of gdMeasurementUnit
// because the C++ instance would be dead when the component is rendered.
type Props = {|
label: string,
description: string,
elementsWithWords: string,
|};
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is it ok?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure what "dead" means

Copy link
Collaborator Author

@D8H D8H Nov 28, 2022

Choose a reason for hiding this comment

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

The gdMeasurementUnit instances are only living during their iteration on the properties when building the property editor view. As the rendering of MeasurementUnitDocumentation is done outside of this loop, the memory referenced by the gdMeasurementUnit instance has been reused and it displays wrong values.
I pass strings instead of gdMeasurementUnit to avoid this.

Copy link
Collaborator

@ClementPasteau ClementPasteau Nov 30, 2022

Choose a reason for hiding this comment

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

ok then! (maybe adding what you wrote in the code would be a better comment 👍)

@D8H D8H force-pushed the unit-of-measurement branch from 08c9b6d to 8b6e357 Compare November 28, 2022 09:10
Copy link
Collaborator

@ClementPasteau ClementPasteau left a comment

Choose a reason for hiding this comment

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

lgtm 👍
Just unsure about the typing comment's meaning

Comment on lines 7 to 13
// Strings are used instead of gdMeasurementUnit
// because the C++ instance would be dead when the component is rendered.
type Props = {|
label: string,
description: string,
elementsWithWords: string,
|};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure what "dead" means

Copy link
Collaborator

@ClementPasteau ClementPasteau left a comment

Choose a reason for hiding this comment

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

maybe improve the comment on typing a bit, then good to go!

Copy link
Owner

@4ian 4ian left a comment

Choose a reason for hiding this comment

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

Looks good generally but the translations won't work when you switch to another language because things are constructed statically.
Would be worth having a "gd::MeasurementUnit::ApplyTranslation" to changes all the transaltable labels.
Note that it is a good thing to avoid recreating at every call a new MeasurementUnit! Otherwise this creates a lot of temporary just to destroy them after and this is needlessly costly.
But the labels should be updated when the language is changed in the editor.

@D8H
Copy link
Collaborator Author

D8H commented Nov 30, 2022

I did the change, it seems to work.

image

There is a bit of duplicated code but I looked for static blocks in C++ and it seems complicated and risky.

@4ian
Copy link
Owner

4ian commented Nov 30, 2022

There is a bit of duplicated code but I looked for static blocks in C++ and it seems complicated and risky.

Yes. Terribly risky (there is even a page about it: https://en.cppreference.com/w/cpp/language/siof). Let's avoid doing anything risky in the statics and just keep a good old function applying translations.

@D8H D8H merged commit 33b2fb0 into master Nov 30, 2022
@D8H D8H deleted the unit-of-measurement branch November 30, 2022 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants