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

[Old PR libui#384] add submenus api for all platforms #115

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mohad12211
Copy link
Contributor

@mohad12211 mohad12211 commented Jun 20, 2022

based on andlabs/libui#384.
notes:

  • does it make sense to have an onclick for an item with a submenu? should it be userbug to do so?
  • unix code in the original PR has a bug with the free function, I fixed the bug but the code looks kinda messy, no idea how to make it cleaner.
  • windows will crash on calling uiMenuItemDisable on an item with submenu.
  • document the api and add a note for setting an onclick callback.

@mohad12211 mohad12211 changed the title [Old PR libui384 [Old PR libui384] add submenus api for all platforms Jun 20, 2022
@mohad12211 mohad12211 changed the title [Old PR libui384] add submenus api for all platforms [Old PR libui#384] add submenus api for all platforms Jun 20, 2022
@cody271
Copy link
Contributor

cody271 commented Jun 24, 2022

  • does it make sense to have an onclick for an item with a submenu? should it be userbug to do so?

Probably not. Any non-default callback assigned to a submenu item onclick should be userbug for now yes.

  • unix code in the original PR has a bug with the free function, I fixed the bug but the code looks kinda messy, no idea how to make it cleaner.

The uiMenuAppendSubmenu() API addition itself is straightforward and obvious enough, but the unix code here will really have to be cleaned up to merge this. Its very convoluted and hard to follow.. Especially concerning when compared next to the darwin code, which is just a few lines!

@mohad12211
Copy link
Contributor Author

mohad12211 commented Jul 11, 2022

Especially concerning when compared next to the darwin code, which is just a few lines!

unlike macos, on windows and linux, each window has it's own menu, which is the reason for all of these problems...

I refactored the unix code, not the best, but I think it's better, especially the FreeMenubar function which has the most problems.
each uiMenuItem has an array of the menu items on each window, when a window is closed, we remove that menu item from the array, so to find the index of the item to remove, I do a search on the first uiMenuItem (on the first uiMenu in the unix code, and on the first non-submenu uiMenu in the windows code) so I'm assuming that those menus have at least one item, is that safe to assume? should I add a userbug if a uiMenu has no items? or should I change the code and allow empty menus (although it doesn't make sense)

@mohad12211
Copy link
Contributor Author

A way to test this is to change page2.c like this

diff --git a/test/page2.c b/test/page2.c
index abb06489..98b342de 100644
--- a/test/page2.c
+++ b/test/page2.c
@@ -39,6 +39,11 @@ static void movePage1(uiButton *b, void *data)
        moveBack = 1;
 }
 
+int closeWindow(uiWindow *w, void *data)
+{
+       return 1;
+}
+
 static void openAnotherWindow(uiButton *bb, void *data)
 {
        uiWindow *w;
@@ -54,6 +59,7 @@ static void openAnotherWindow(uiButton *bb, void *data)
        } else
                uiWindowSetChild(w, uiControl(makePage6()));
        uiWindowSetMargined(w, 1);
+       uiWindowOnClosing(w, closeWindow, NULL);
        uiControlShow(uiControl(w));
 }

now you can open and close menued and menuless windows to verify that the free function works.

as to uiprivImplBug("menu item %p (%s) still has uiWindows attached...);
should this be a userbug and require the user to destroy all windows before calling uiUninit(), or should it be implementation bug and we should destroy all windows at when calling uiQuit() or uiUninit()?

@cblc
Copy link

cblc commented May 2, 2023

What does this PR need for being accepted? I believe submenus are a must-have.

@cody271
Copy link
Contributor

cody271 commented May 3, 2023

What does this PR need for being accepted? I believe submenus are a must-have.

This PR needs more rigorous testing to be merged. Ideally a new submenu section added to the uiMenu unit tests, to better prove that it doesn't break the existing functionality. There is also a merge conflict present according to GitHub, that would have to be resolved.

@cblc
Copy link

cblc commented May 3, 2023

I could try to do it myself, but I would need to learn how the unit tests work in this repository, because at first glance my impression is that user review of the results would be necessary for UI-related tests. I will take a look at how the tests work and I will try to add the tests if possible.

@cody271
Copy link
Contributor

cody271 commented May 5, 2023

I could try to do it myself, but I would need to learn how the unit tests work in this repository, because at first glance my impression is that user review of the results would be necessary for UI-related tests. I will take a look at how the tests work and I will try to add the tests if possible.

There are actually three different sets of tests:

qa is a manual test suite requiring user review of each step performed.
tester is the original, and a somewhat random collection of tests at this point.
unit is a fully automated unit test suite built with cmocka.

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.

None yet

3 participants