-
Notifications
You must be signed in to change notification settings - Fork 871
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
Toggle Buttons in SceneEditor Toolbar #2215
Conversation
1.Following buttons in toolbar provided with toggle functionality. 2.Buttons BG changes depending upon toggle state of the subEditor.
@Bouh As we discussed on forum. I converted these buttons to toggle and added some styling depending upon the toggle state. |
I'am not sure at all for the background. |
@Bouh After you mentioned this I tried changing the position of subEditors at different positions and it all worked fine in toggling. But the position of the subEditor changes to default layout position. (This functionality you are mentioning was never incorporated in GD though). |
You have twice But i don't know how know which editor it is.
|
Yes, I just placed the background for temporary with colors. |
Material-ui have no recommendation for this kind of button with a big icon with a big filling.
Keep the original visual style of the buttons, remove all css added in this PR. |
1.Fixed issue with editor toggling when close button clicked for closing the editor 2.Fixed issue with persisting editors states in scene editor on reload. 3.Commented the css styling of the toolbar icon for future reference.
I used a small trick here by passing a function as a prop to close button which changes the editor state. ;) I have fixed another issue in the scene editor which I came across while using these toggles, Now |
GDevelop/newIDE/app/src/SceneEditor/index.js Lines 1208 to 1246 in 98a1d69
I think these messages saying "panel is already opened" are not useful anymore as no one is able to open a panel that is already opened. User either will open/close by clicking on toggle.
I think this is a good plan to go forward on this feature. But please be sure to tell the users about toggle functionality or no one will ever notice it unless they accidently double click on any button. !Warning! |
newIDE/app/src/UI/ToolbarIcon.js
Outdated
@@ -11,6 +11,7 @@ type Props = {| | |||
disabled?: boolean, | |||
onClick?: () => void, | |||
onContextMenu?: () => void, | |||
showComponent?: boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was used for styles, as we don't want style remove this props everywhere.
newIDE/app/src/UI/ToolbarIcon.js
Outdated
//We can use here (showComponent) value from props to set the UI texture of the button to ON/OFF state | ||
//Following example shows how to use this in simple manner | ||
// let buttonStyle = {}; | ||
// if (showComponent !== undefined) { | ||
// buttonStyle = showComponent | ||
// ? { | ||
// border: '5px solid #80BE1F', | ||
// backgroundColor: '#80BE1F', | ||
// marginRight: '5px', | ||
// } | ||
// : { | ||
// border: '5px solid #FF3232', | ||
// backgroundColor: '#FF3232', | ||
// marginRight: '5px', | ||
// }; | ||
// } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this useless code please.
<ToolbarCommands | ||
openObjectsList={this.props.openObjectsList} | ||
openObjectGroupsList={this.props.openObjectGroupsList} | ||
openPropertiesPanel={this.props.openProperties} | ||
toggleObjectsList={this.props.toggleObjectsList} | ||
toggleObjectGroupsList={this.props.toggleObjectGroupsList} | ||
togglePropertiesPanel={this.props.toggleProperties} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToolbarCommands component is used for bind an action to shortcuts.
In your case this code isn't complete, because props in ToolbarCommands are not complete.
See if you press O for open the object editor the app should crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now toggle functionality linked to shortcut keys.
@@ -24,6 +28,7 @@ export default class CloseButton extends Component { | |||
{({ mosaicWindowActions }) => ( | |||
<IconButton | |||
onClick={() => { | |||
if (this.props.closeActions) this.props.closeActions(); | |||
mosaicActions.remove(mosaicWindowActions.getPath()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See in newIDE\app\src\UI\EditorMosaic\index.js
you have the current stuff for add a node in mosaic with addNode
.
It would be better to add a similar for removeNode.
Same for nodeExist for checking if an editor living in the node tree of mosaic.
This way you have not to check or add a state for know if the panel is already open.
And all your stuff in componentWillMount
in newIDE\app\src\SceneEditor\index.js
will be useless.
Not sure of the best way to do it thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React recommends toggling of components through react state. As you can see , Material-UI also follows this convention. This way we can use this state anywhere in component and other components.
mosiacAction.remove(path)
is already doing the job of removal of node.
The code in componentWillMount
I wrote only for the first render. That is when project loads for the first time.
By doing this we will set the sceneEditor state of the panels as they were before closing the project.
Another example of state use is as you can see here , we have used state to display message :
GDevelop/newIDE/app/src/SceneEditor/index.js
Lines 1208 to 1216 in 98a1d69
<InfoBar | |
identifier="objects-panel-explanation" | |
message={ | |
<Trans> | |
Objects panel is already opened: use it to add and edit objects. | |
</Trans> | |
} | |
show={!!this.state.showObjectsListInfoBar} | |
/> |
So I don't think removing state is a good idea in case of toggle components. But You gave a solid idea of creating this removeNode
function. Now speed of toggling of panels can be increased by 200%.
Thank you for your hint. In the next commit I will apply these changes.
The first part of info bar can be edited for explain that panels are toggleable. |
1.Panels in the scene editor can be toggled with shortcut keys also. 2.Changed the text to toggle keys in preferances tab -> shortcut keys. 3.added removeNode and hasNode functions in EditorMosaic. 4.added closeEditor function in EditorMosaic.
So I didn't removed the code in the |
@Bouh Can you please review this PR now ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds a lot of complexity in SceneEditor, by lifting only part of the state of EditorMosaic inside SceneEditor, meaning that we have a mix of imperative functions (openEditor, closeEditor in EditorMosaic) and declarative ones (toggleObjectsList, etc... in SceneEditor).
The additional code in componentWillMount is also something I want to avoid at all costs - it should not be the responsibility of SceneEditor to deal with this.
Two solutions:
- either keep EditorMosaic responsible for handling its state (I.e: don't lift the state), in which case you can call a
toggleEditor
function on it. Advantage: easier. Disadvantage: you can't know the state (opened or not) from SceneEditor. - or do a more important refactoring work where all the functions to handle the state of an EditorMosaic is put in a React hook, that can be then used in SceneEditor (and the state is then passed down to EditorMosaic).
Appreciate your efforts so far! But in the current situation I think it's adding too much complexity for just toggling stuff. We have to either follow the current architecture or change it. componentWillMount
should almost never be used.
Ok, so you mean remove all the following states for panels from the SceneEditor : GDevelop/newIDE/app/src/SceneEditor/index.js Lines 144 to 149 in 30aa5e7
And give total responsibility of EditorMosaic of its state to itself. and then use react hooks to know and control the state of the EditorMosaic. So toggling can be done with these hooks as OnToggle first check whether the panel is open or not and act accordingly. Is I am correct ? 😕 |
That's a possibility yes. If a state is a component, then by definition this component has the responsibility of it.
so either:
2 is better but needs refactoring also in other editors. 1 is a simpler change to toggle just the editor, but you won't be able to show in the toolbar if something is toggled or not. Might not be worth it anyway? Also remember that on small screens, clicking on buttons will replace the currently opened editor :) EDIT: I know it's a bit discouraging because you already did work on this, but we need to find a solution that is not a mix of responsibility between components. Otherwise we would add an antipattern and technical debt to the codebase. |
1.Added following public functions in EditorMosiac : 1)isEditorOpen 2)toggleEditor and one private function : 1)_isEditorExist 2.Removed panels/editor states from SceneEditor 3.Removed componentWillUnmount from SceneEditor 4.refacotred toggling of the editors in SceneEditor 5.removed InfoBars related to panels in SceneEditor 6.removed closeActions function from CloseButton
@4ian I went with this approach and created two additional imperative functions named I also removed these unnecessary infobars as they are not useful now, since toggling is enabled. GDevelop/newIDE/app/src/SceneEditor/index.js Lines 1208 to 1246 in 98a1d69
The toggling is working fine now :) |
I got crash when i go for toggle panels.
|
@Bouh this happens when you try to toggle the editors at high speed like double clicking the toggle button or fast double press. |
Closing as old. |
1.Following buttons in toolbar provided with toggle functionality.
2.Buttons BG changes depending upon toggle state of the subEditor.
Current Problems :
1.Clicking on the close button in subEditor do not changes the subEditor state.
GDevelop/newIDE/app/src/UI/EditorMosaic/index.js
Line 116 in d21a818
(As close button mentioned only in the object-list editor as separate attribute and for other subEditors as a default.
So need some help how close button can reference state of sceneEditor)
Example of how scene editor looks now :
Preview Video :
https://streamable.com/nykuzj