Sample code not working? #2
Comments
As an extension onto #4 I have also tried implementing your OpenGL example (without the OpenGL because I'm using a framebuffer to implement this) and even in the demo.c the program crashes at " running = gui_panel_begin_stacked(&layout, &control->hook, stack, "Control", in);" in "update_control". Any assistance would be greatly appreciated! |
Thank you for your feedback. II.) There are three ways to allocate memory. Fixed size memory, user controlled growable fixed size memory and an allocator. The fixed size you describe is what I personally use the most since it is the easiest and most UIs have roughly known size. If that is to much hassle you can create an gui_allocator and initialize the buffer with gui_command_buffer_init instead. This guarantees that you will always have enough memory but it requires a little bit more work. III.) I updated the example code to hopefully make it more clear. IV.) First of the GUI_ASSERT macro does not define anything by default, since the project does not use the the standart library by default I cannot use the normal #define GUI_ASSERT(expr) assert(expr)
#include "gui.h" before including the header file. Since it was not obvious I added the line to the demos and added a additional assert to the gui_panel_begin function. Please check again if the OpenGL demo still does not work or gives an assert, since it works for me which makes this quite complicated. If the crash is still happening please report on the actual line in the gui_panel_begin function the program crashes on so that I can get a more precise image of where to look for problems. In addition does either the win32 (windows) or the xlib (linux) demo work for you? That would at least further narrow down the problem for me. |
Hey! So sorry for taking so long to get back to you here, I have finally got it to work after a bit of tinkering. A few extra notes here on your example: This line -> void *memory = malloc(MEMORY_SIZE) needs a semi colon This line -> struct gui_font font = {...}; is a bit ambigous... looked at examples and this component "gui_handle userdata;" is still a bit fuzzy on my end. This line -> "len = gui_panel_edit(&layout, buffer, len, 256, &active, GUI_INPUT_DEFAULT);" doesn't quite work :) gui_panel_init(&panel, 50, 50, 220, 170, gui_command_buffer_init_fixed(buffer, memory, MEMORY_SIZE, GUI_CLIP); Need "&" prior to "buffer" Anyways thanks! I'll be in touch soon if I see anymore issues |
After further review I will recant one of my statements This line -> "len = gui_panel_edit(&layout, buffer, len, 256, &active, GUI_INPUT_DEFAULT);" doesn't quite work :). This line actually works! Thank you for your time! |
Another note, I noticed on your example the edges of most of the objects are rounded, however on my rendering the edges are not rounded. I am not using the scissor function currently, could this be the cause? |
Another thing to mention here. For input on the code for: gui_input_char. Could you instead of requesting for a glyph (not entirely sure what this even is?) could you override it or something to just request for a char? Thanks so much! |
Hey, thanks for a good amount of feedback. I.) Font typedef union {
void *ptr;
gui_int id;
} gui_handle; Now that you mentioned it I will probably have to write some more documentation and examples describing how to use images and fonts. II.) Rounding III.) Glyphes typedef gui_char gui_glyph[GUI_UTF_SIZE]; Since it was not obvious I divided the function call into an ASCII version |
Okay "gui_input_char" seems to be working well! Except the cursor on the input box now only seems to measure the length of the new characters and isn't adjusting correctly. |
Oh OK, that one is a really old bug that I previously fixed that now comes back to hunt me. I will probably not be able to fix this tonight so I will look into it tomorrow. |
Okay cool! I look forward to the fix |
It is really strange. Everything works perfect for me until a certain point. When I then add another symbol the text width is suddenly calculated wrong. Do you use my text width calculation function or do you have your own? If you have the same problem than I can at least remove the possibility that my string width calculation function is wrong. |
No, I use my own width calculation algorithm. I've tested it relatively thoroughly, and I'd like to say that my width algorithm is working just fine. (I can do some further tests on it if you would like though) |
No need. If we both have the same results and bug then it is probably on the library end of things. |
OK I think solved the problem. It actually has nothing directly to do with my library code. Instead my opengl font code does not have kerning therefore the text width calculation is not perfect and for some character combinations provides wrong values. At least the X11 and nanovg work as intended. This is why I did not see the bug previously since I worked mostly with nanovg. That being said it still sucks, since I have to rely on the fact that the user has kerning. |
Does it work without the cursor? for example in the spinner. If so then you could just remove the |
As it looks now I will probably rewrite the way text is drawn in the edit box since I need to support arbitrary cursor position for coping and pasting and therefore will draw each character independently. Maybe with a little bit of luck kerning does not have to be provided, at least not for the cursor to work. |
OK small update in the opengl font drawing example. I had a extremely stupid bug in my code and it the editbox and cursor handling now works as intended. So it had nothing to do with kerning but instead I was just to stupid to find a simple bug. |
Hey! So I've stuck with using the function "gui_panel_edit" as this was easier to implement compared to the "gui_panel_editbox" function that you showed, but looks like on the former function the backspace functionality is broken. I have implemented a temporary fix on my end however in the long run I'd like to start using the former function. The former function requires two parameters: a layout and a gui_edit_box. The gui_edit_box seems to be a new addition, and its elements are a bit foreign to me. struct gui_edit_box { I understand the first 2 elements as they are the same as are included in the original "gui_panel_edit" function. However the rest are strange to me. Could you please describe what these are? Also could you set up an editbox that is a password field? Thanks as always! |
Hey, struct gui_clipboard clip;
clip.userdata = your_os_data_clipboard;
clip.copy = your_os_clipboard_copy_callback;
clip.paste = your_os_clipboard_paste_callback; alternatively you can just pass NULL in the static gui_bool filter_numbers(gui_long unicode)
{
if (unicode < '0' || unicode > '9')
return gui_false;
return gui_true;
}
static void copy_callback(gui_handle handle, const char *text, gui_size len)
{
char buffer[1024];
assert(len < 1023);
memcpy(buffer, text, len)
buffer[len] = '\0';
fprintf(stdout, "copied: %s\n", buffer);
}
static void paste_callback(gui_handle handle, char *buffer, gui_size max)
{
const char *text = "abc"
if (max < 3) return;
memcpy(buffer, text, 3);
}
int main(void)
{
/* clipboard does not have to be persistent it gets copied into the editbox */
/* in the gui_edit_box_init function */
struct gui_clipboard clip;
clip.userdata.ptr = NULL;
clip.copy = copy_callback;
clip.paste = paste_callback;
char buffer[256];
struct gui_edit_box edit;
/* if you do not want a clipboard and filter: */
/* gui_edit_box_init_fixed(&edit, buffer, 256, NULL, NULL); */
gui_edit_box_init_fixed(&edit, buffer, 256, &clip, filter_numbers);
} This is a very simple and not very practical example but hopefully explains it a little bit better. So hopefully I will have a new big update this weekend done and I will write an Issue where I will extensively describe all changes. |
I have my code back in a working state and checked if backspace is bugged for the |
Hmm, that's strange. It is still not working for my end. The character is removed from the string but the cursor is not updated. It's almost as if it replaces the character with a space. I have looked around in my code for a bug and I can't seem to find one. For now I'll just try and implement the edit box instead. I'm looking forward to your next big update! |
I also noticed that on your OpenGL example the field "case GUI_COMMAND_IMAGE:" was not initialized. Could you provide an example of this? (I'd like to start drawing pixel buffers there). Thanks! |
Hmm, switch (cmd->type) {
case GUI_COMMAND_IMAGE: {
const struct gui_command_image *i = gui_command(image, cmd);
if (gui_image_is_subimage(&i->img))
draw_image(i->img.handle.ptr, i->x, i->y, i->w, i->h, i->img.region.x, i->img.region.y, i->img.region.w, i->img.region.h);
else draw_image(i->img.handle.ptr, i->x, i->y, i->w, i->h);
} break;
} OK now to explain what I am doing here. First like always the general command is cast to the right command type. Then you have to check if the complete image needs to be drawn or only a subset of the image. To check if the image inside the command uses only a sub region the |
I just read that you requested for a password like editobox. Sorry that I did not replied on that issue. The password editbox shouldn't be a big problem I will take a look into the issue and provide it ASAP. Small update on the clipboard in the editbox. Since the editbox got reworked and now supports text selection (even though it is a little bit shitty and I have to keep on iterating on it) the paste callback changed as well. The demo now has a example for the editbox and system clipboard as well. So you can have a look if you did not get it to work. But for short here is a small example for the new version: static gui_bool filter_numbers(gui_long unicode)
{
if (unicode < '0' || unicode > '9')
return gui_false;
return gui_true;
}
static void copy_callback(gui_handle handle, const char *text, gui_size len)
{
char buffer[1024];
assert(len < 1023);
memcpy(buffer, text, len)
buffer[len] = '\0';
fprintf(stdout, "copied: %s\n", buffer);
}
static void paste_callback(gui_handle handle, struct gui_edit_box *box)
{
/* this adds the string "copied into the editbox "*/
gui_edit_box_add(box, "copied", 5);
}
int main(void)
{
/* clipboard does not have to be persistent it gets copied into the editbox */
/* in the gui_edit_box_init function */
struct gui_clipboard clip;
clip.userdata.ptr = NULL;
clip.copy = copy_callback;
clip.paste = paste_callback;
char buffer[256];
struct gui_edit_box edit;
/* if you do not want a clipboard and filter: */
/* gui_edit_box_init_fixed(&edit, buffer, 256, NULL, NULL); */
gui_edit_box_init_fixed(&edit, buffer, 256, &clip, filter_numbers);
} |
Syncing fork to the original repository
Hey, I have many questions/comments about your sample code under the README. (this is all c++)
The text was updated successfully, but these errors were encountered: