Hi,
I'm working on a wrapper library that embeds NAppGUI: https://github.com/causerp/nappgui4cj
It's still a work in progress. I have migrated 3 of the examples to test my approach.
It's been tested on Windows, but it compiles on Linux.
I have a few questions:
- When I pass a nrc ResId (const char *) ID to some of the functions, I noticed that a copy isn't stored internally, but if I pass a generic string, it stores a copy. I had to add 2 overloads to functions:
public func setTitle(id: ResId): Unit {
unsafe {
window_title(m_handle, id.cStr)
}
}
public func setTitle(title: String): Unit {
unsafe {
let strPtr = LibC.mallocCString(title)
window_title(m_handle, strPtr)
LibC.free(strPtr)
}
}
With this appoach, it works, because I never free the ResID, but I can safely free a generic text. I can see a potential problem if a user passes a string that happens to match the ResId text. If NappGUI stored a copy internally, it would simplify code wrappers.
-
Do you know of more cases where we need to keep the string we pass to the function alive? If NappGUI stores copies internally, it can avoid problems.
-
To add icons on windows, I have to link the resource. the examples do this. The icon appears on windows explorer but it doesn't show on the app. I have to patch this function to use i_INSTANCE on LoadIcon to get the icon to show on the app:
https://github.com/causerp/nappgui4cj/blob/main/nappgui/src/osgui/win/osgui_win.cpp
static void i_registry_custom_window_class(void)
{
WNDCLASSEX wc;
cassert(i_INSTANCE != NULL);
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = DefWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = i_INSTANCE;
wc.hIcon = LoadIcon(i_INSTANCE, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
/* Avoid warning C4306: 'type cast' : conversion from 'int' to 'HBRUSH' of greater size */
#if defined(__x64__)
wc.hbrBackground = (HBRUSH)(uint64_t)(COLOR_BTNFACE);
#else
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
#endif
wc.lpszMenuName = NULL;
wc.lpszClassName = kWINDOW_CLASS;
wc.hIconSm = LoadIcon(i_INSTANCE, IDI_APPLICATION);
{
ATOM ret = 0;
ret = RegisterClassEx(&wc);
cassert_unref(ret != 0, ret);
}
}
If I do this. the icon appears. From reading the documentation, passing the instance is the correct behavior. I also patched the other loadIcon on the same file.
-
Not all functions and structs/enums are for public use, are they? Can you refactor the headers so that when you install the headers installed contain all the public functions? It would make it easier to know which functions are internal.
-
There's a small amount of C++ used in draw2d. From what I can see, it's very small. Could it be refactored to use C code only? It would allow me to remove libc++ dependency, which from what I remember was only used in a small place (I'm linking exception related code, but I'm assuming there are no exceptions being thrown since this is a C API (it shouldn't throw))
-
I tried to add a localized image to test nrc and see if it adds both images. it does but the image doesn't change when the locale changes. Is the locale only for strings? if so, is there a point in adding PNG images in locale? I tried this in the C example too and it wasn't switching the image (die example)
I haven't wrapped most of the functions. I think the approach I've taken for these examples should work for the rest of the library. The biggest problem I see is functions that can take both pointers to strings or pointers to images or mixed data types (is the pointer checked against nrc resources only? in which case only nrc generated data that is registered is safe to use in these mixed functions. If I pass a custom ResID string will it compare text or pointers?)
Thanks in advance. Great library.
Hi,
I'm working on a wrapper library that embeds NAppGUI: https://github.com/causerp/nappgui4cj
It's still a work in progress. I have migrated 3 of the examples to test my approach.
It's been tested on Windows, but it compiles on Linux.
I have a few questions:
With this appoach, it works, because I never free the ResID, but I can safely free a generic text. I can see a potential problem if a user passes a string that happens to match the ResId text. If NappGUI stored a copy internally, it would simplify code wrappers.
Do you know of more cases where we need to keep the string we pass to the function alive? If NappGUI stores copies internally, it can avoid problems.
To add icons on windows, I have to link the resource. the examples do this. The icon appears on windows explorer but it doesn't show on the app. I have to patch this function to use
i_INSTANCEonLoadIconto get the icon to show on the app:https://github.com/causerp/nappgui4cj/blob/main/nappgui/src/osgui/win/osgui_win.cpp
If I do this. the icon appears. From reading the documentation, passing the instance is the correct behavior. I also patched the other loadIcon on the same file.
Not all functions and structs/enums are for public use, are they? Can you refactor the headers so that when you install the headers installed contain all the public functions? It would make it easier to know which functions are internal.
There's a small amount of C++ used in draw2d. From what I can see, it's very small. Could it be refactored to use C code only? It would allow me to remove libc++ dependency, which from what I remember was only used in a small place (I'm linking exception related code, but I'm assuming there are no exceptions being thrown since this is a C API (it shouldn't throw))
I tried to add a localized image to test nrc and see if it adds both images. it does but the image doesn't change when the locale changes. Is the locale only for strings? if so, is there a point in adding PNG images in locale? I tried this in the C example too and it wasn't switching the image (die example)
I haven't wrapped most of the functions. I think the approach I've taken for these examples should work for the rest of the library. The biggest problem I see is functions that can take both pointers to strings or pointers to images or mixed data types (is the pointer checked against nrc resources only? in which case only nrc generated data that is registered is safe to use in these mixed functions. If I pass a custom ResID string will it compare text or pointers?)
Thanks in advance. Great library.