nuklear icon indicating copy to clipboard operation
nuklear copied to clipboard

new keys:

Open pascualle opened this issue 8 years ago • 8 comments

new keys:

NK_INCLUDE_DRAW_VERTEX_CUSTOM_FUNCTION

use custom draw_vertex function (adopted for glDrawArrays(GL_TRIANGLES)) this key switches off all inner nk_draw_vertex() related functionality user must assign in struct nk_draw_list his own custom external function typedef void*(*nk_draw_vertex_f)(void *dst, const struct nk_convert_config *config, struct nk_vec2 pos, struct nk_vec2 uv, struct nk_colorf color); each time nk_draw_list_* related functions call, list->draw_vertex() external function calls

example:

/* init in your_engine_helper.c: */
nk_init_default(&nuklear_instance.ctx, font);
nuklear_instance.ctx.draw_list.draw_vertex = nk_custom_draw_vertex;
...

/* custom implementation in your_engine_helper.c */
static void* nk_custom_draw_vertex(void *draw_list, const struct nk_convert_config *config, struct nk_vec2 pos, struct nk_vec2 uv, struct nk_colorf color)
{
	/* add vertex to own vertex buffer */ 
	return NULL;
}

NK_INCLUDE_DRAW_TEXT_CUSTOM_FUNCTION

use custom draw_text function if user engine contains his own text drawing functionality and no need in any nuklear font (nk_query_font_glyph_f query, nk_handle texture etc) related code function for text drawing typedef void*(*nk_draw_vertex_f)(void *dst, const struct nk_convert_config *config, struct nk_vec2 pos, struct nk_vec2 uv, struct nk_colorf color);

example:

/* init in your_engine_helper.c: */
SDK_NULL_ASSERT(font);
font->userdata.id = /* external font id */;
font->height = /* custom function to get external font size */
font->width = nk_custom_font_get_text_width; /* custom function to get text width */
nk_init_default(&nuklear_instance.ctx, font);
nuklear_instance.ctx.draw_list.draw_text = nk_custom_draw_list_add_text; /* custom function to draw text */
...

/* custom implementation in your_engine_helper.c */
static void nk_custom_draw_list_add_text(struct nk_draw_list* draw_list, const struct nk_user_font* font, struct nk_rect rect,
											const nk_tchar *text, int len, float font_height, struct nk_color color)
{
	const YourEngineRgba bg_color = 0;
	struct YourEngineRect txt_rect;
	SDK_NULL_ASSERT(draw_list);
	SDK_NULL_ASSERT(font);
	CpuCopy8(&rect.x, &txt_rect.x, sizeof(float) * 4);
	txt_rect.h = font_height;
	YourEngineDrawText(font->userdata.id, (const wchar*)text, (u32)len, (const struct YourEngineRect*)&txt_rect,
					(const struct YourEngineRect*)&((struct nk_draw_list *)draw_list)->clip_rect,
					 COLOR(color.r, color.g, color.b), bg_color, FALSE);
}

NK_INCLUDE_UNICODE_SUPPORT

unicode support (instead utf8) yes, wchar_t support

NK_INCLUDE_DISABLE_KEYBOARD_EDIT

no keyboard input no cursor more for android/ios/etc devices

NK_INCLUDE_TOUCHPAD_MODE

use touchpad instead mouse more for android/ios/etc devices

pascualle avatar Feb 10 '17 16:02 pascualle

Thanks for your PR. These are some massive changes that will take some time to review. If it conforms to my quality standard then this probably will be version 2.0. So far I took a quick peek inside and I noticed you overwrote NK_UINT_MAX to 4294967295 instead of 4294967295u, please change it back. Other than that I have to review all of your design changes to make sure they are correct. I cannot make any promises on when I will be able to pull this. It takes some time to work through ~2k changes.

vurtun avatar Feb 11 '17 16:02 vurtun

hi, vurtun! about NK_UINT_MAX.. oups, you absolutely right, i dont know how 'u' it disappeared. all of these changes were for my tiny engine, but i hope, it will be useful for you. in general, i prefer to use bitbucket, my fork placed here: https://bitbucket.org/pascualle/nuklear

i still work on nuklear to my tiny engine integration. but i already can show results: http://casualgum.com/public/nuklear_gui.html with keys #define NK_INCLUDE_FIXED_TYPES #define NK_INCLUDE_STANDARD_VARARGS #define NK_INCLUDE_DEFAULT_ALLOCATOR #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT #define NK_INCLUDE_DRAW_VERTEX_CUSTOM_FUNCTION #define NK_INCLUDE_DRAW_TEXT_CUSTOM_FUNCTION #define NK_INCLUDE_DISABLE_KEYBOARD_EDIT #define NK_INCLUDE_UNICODE_SUPPORT #define NK_IMPLEMENTATION #define NK_TENGINE_IMPLEMENTATION

pascualle avatar Feb 12 '17 12:02 pascualle

@pascualle , does your version based on most modern Nuklear? NK_UINT_MAX was changed some weeks after my Habrahabr's publication. Was version merging correct?

DeXP avatar Feb 12 '17 17:02 DeXP

last merge: Added function to remove edit focus #321 (https://github.com/vurtun/nuklear/commit/ef2dcd3b779647e0140bb78863cb8439774e277b) yes, you right, one commit missed Merge pull request #335 from DeXP/master Remove warning "unsigned only in ISO C90" -#define NK_UINT_MAX 4294967295 +#define NK_UINT_MAX 4294967295u

pascualle avatar Feb 12 '17 21:02 pascualle

up to date

pascualle avatar Mar 02 '18 11:03 pascualle

NK_INCLUDE_UNICODE_SUPPORT

unicode support (instead utf8) yes, wchar_t support

This is quite confusing. Unicode does not imply at all non-utf8 implementation. Could the define be renamed (preferably to something containing the word wchar)? Also, Nuklear supports unicode already right now (one can represent anything with utf8), so the point unicode support is actually somehow false :wink:.

dumblob avatar Mar 03 '18 11:03 dumblob

dumblob, whar_t is part of standart C (https://en.wikibooks.org/wiki/C_Programming/wchar.h) My point is to support unicode (wide strings) in Nuklear. It is not utf8 substitude, is is just step to support projects and/or libs that use wide strings instead utf8.

for example, code:

if(nk_begin(main_ctx, L"Options", nk_rect(panel_x, 50.0f, panel_width, 155.0f),
			NK_WINDOW_BORDER | NK_WINDOW_MOVABLE |
			NK_WINDOW_MINIMIZABLE | NK_WINDOW_TITLE))
{
	static const float ratio[] = {40, 160};
	nk_layout_row(main_ctx, NK_STATIC, 30, 2, ratio);
	nk_label(main_ctx, L"speed:", NK_TEXT_LEFT);
	nk_slider_float(main_ctx, 0.0f, &speed_slider, 15.0, 0.5f);
	nk_label(main_ctx, L"rotation:", NK_TEXT_LEFT);
	nk_slider_float(main_ctx, 0.0f, &rotation_slider, 360.f, 0.5f);
	nk_label(main_ctx, L"scale:", NK_TEXT_LEFT);
	nk_slider_float(main_ctx, 0.2f, &scale_slider, 5.0, 0.2f);
}

NK_INCLUDE_UNICODE_SUPPORT is on, result: unicode_on

NK_INCLUDE_UNICODE_SUPPORT is off, result: unicode_off

About renaming... Yes, you right, it make sense.

pascualle avatar Mar 04 '18 08:03 pascualle

About renaming... Yes, you right, it make sense.

Yes, it's about renaming.

dumblob avatar Mar 04 '18 11:03 dumblob