-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add get function for window menu object #7295
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -49,6 +49,12 @@ class MenuBase { | |||||||||||||||||
|
|
||||||||||||||||||
| virtual int GetNumberOfItems() const = 0; | ||||||||||||||||||
|
|
||||||||||||||||||
| /// Get the Menu by name. Returns nullptr if not found. | ||||||||||||||||||
| virtual std::shared_ptr<MenuBase> GetMenu(const char* name) = 0; | ||||||||||||||||||
|
|
||||||||||||||||||
| /// Get the Menu by ItemId. Returns nullptr if not found. | ||||||||||||||||||
| virtual std::shared_ptr<MenuBase> GetMenu(ItemId item_id) = 0; | ||||||||||||||||||
|
Comment on lines
+53
to
+56
|
||||||||||||||||||
| virtual std::shared_ptr<MenuBase> GetMenu(const char* name) = 0; | |
| /// Get the Menu by ItemId. Returns nullptr if not found. | |
| virtual std::shared_ptr<MenuBase> GetMenu(ItemId item_id) = 0; | |
| virtual std::shared_ptr<MenuBase> GetMenu(const char* name) const = 0; | |
| /// Get the Menu by ItemId. Returns nullptr if not found. | |
| virtual std::shared_ptr<MenuBase> GetMenu(ItemId item_id) const = 0; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -35,6 +35,9 @@ class MenuImgui : public MenuBase { | |||||
|
|
||||||
| int GetNumberOfItems() const override; | ||||||
|
|
||||||
| std::shared_ptr<MenuBase> GetMenu(const char* name) override; | ||||||
|
||||||
| std::shared_ptr<MenuBase> GetMenu(const char* name) override; | |
| std::shared_ptr<MenuBase> GetMenu(const char* name) const override; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1400,6 +1400,10 @@ Ctrl-alt-click to polygon select)"; | |||||
| scene_->ForceRedraw(); | ||||||
| } | ||||||
|
|
||||||
| std::shared_ptr<MenuBase> GetMenubar() { | ||||||
|
||||||
| std::shared_ptr<MenuBase> GetMenubar() { | |
| std::shared_ptr<gui::MenuBase> GetMenubar() { |
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.
I'm open to do it, however, the same file L:45 already have a similar case without gui:: namespace. I followed the convention. Which is better?
https://github.com/EwingKang/Open3D/blob/menu_get_fun/cpp/open3d/visualization/gui/MenuBase.h#L47
Copilot
AI
Jul 1, 2025
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 should be marked const since it does not modify object state: std::shared_ptr<gui::MenuBase> O3DVisualizer::GetMenubar() const {
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.
I'm baffled. Does the modification of the smart-pointer-pointed count as mutation to the object? I'm open to both ways.
Personally, after reading https://isocpp.org/wiki/faq/const-correctness#logical-vs-physical-const and some stackoverflow articles, I would say that this member should NOT be marked as const. Since the const label hints the programmer that no part of this object will be changed. This would not be intuitive since the purpose of the get function is for the user to modify the content. For example the sample code provided in the original PR.
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.
To be more specific, almost all discussion I read have the following syntax:
int *GetPointerToMember() { return &member; }
const int *GetPointerToMember() const { return &member; }Usually there are always two versions of the get function. Should I straight up provide two versions of the get function?
@ssheorey I hate to bother you with this trivial question, but it would be nice if you can give some pointers.
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.
Similarly, mark this override as
const:std::shared_ptr<MenuBase> GetMenu(const char* name) const override;