@ -147,7 +147,7 @@
/// NK_ASSERT | If you don't define this, nuklear will use <assert.h> with assert().
/// NK_MEMSET | You can define this to 'memset' or your own memset implementation replacement. If not nuklear will use its own version.
/// NK_MEMCPY | You can define this to 'memcpy' or your own memcpy implementation replacement. If not nuklear will use its own version.
/// NK_ SQRT | You can define this to 'sqrt' or your own sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate version.
/// NK_ INV_ SQRT | You can define this to your own inverse sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate version.
/// NK_SIN | You can define this to 'sinf' or your own sine implementation replacement. If not nuklear will use its own approximation implementation.
/// NK_COS | You can define this to 'cosf' or your own cosine implementation replacement. If not nuklear will use its own approximation implementation.
/// NK_STRTOD | You can define this to `strtod` or your own string to double conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!).
@ -372,7 +372,7 @@ extern "C" {
# elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER)
# define NK_SIZE_TYPE unsigned __int32
# elif defined(__GNUC__) || defined(__clang__)
# if defined(__x86_64__) || defined(__ppc64__)
# if defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__)
# define NK_SIZE_TYPE unsigned long
# else
# define NK_SIZE_TYPE unsigned int
@ -387,7 +387,7 @@ extern "C" {
# elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER)
# define NK_POINTER_TYPE unsigned __int32
# elif defined(__GNUC__) || defined(__clang__)
# if defined(__x86_64__) || defined(__ppc64__)
# if defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__)
# define NK_POINTER_TYPE unsigned long
# else
# define NK_POINTER_TYPE unsigned int
@ -1127,7 +1127,7 @@ NK_API void nk_input_end(struct nk_context*);
/// cfg.curve_segment_count = 22;
/// cfg.arc_segment_count = 22;
/// cfg.global_alpha = 1.0f;
/// cfg. null = dev->null;
/// cfg. tex_ null = dev->tex_ null;
/// //
/// // setup buffers and convert
/// struct nk_buffer cmds, verts, idx;
@ -1177,7 +1177,7 @@ struct nk_convert_config {
unsigned circle_segment_count ; /* number of segments used for circles: default to 22 */
unsigned arc_segment_count ; /* number of segments used for arcs: default to 22 */
unsigned curve_segment_count ; /* number of segments used for curves: default to 22 */
struct nk_draw_null_texture null; /* handle to texture with a white pixel for shape drawing */
struct nk_draw_null_texture tex_ null; /* handle to texture with a white pixel for shape drawing */
const struct nk_draw_vertex_layout_element * vertex_layout ; /* describes the vertex output format and packing */
nk_size vertex_size ; /* sizeof one vertex for vertex packing */
nk_size vertex_alignment ; /* vertex alignment: Can be obtained by NK_ALIGNOF */
@ -4654,6 +4654,9 @@ struct nk_mouse_button {
struct nk_mouse {
struct nk_mouse_button buttons [ NK_BUTTON_MAX ] ;
struct nk_vec2 pos ;
# ifdef NK_BUTTON_TRIGGER_ON_RELEASE
struct nk_vec2 down_pos ;
# endif
struct nk_vec2 prev ;
struct nk_vec2 delta ;
struct nk_vec2 scroll_delta ;
@ -4679,6 +4682,7 @@ struct nk_input {
NK_API nk_bool nk_input_has_mouse_click ( const struct nk_input * , enum nk_buttons ) ;
NK_API nk_bool nk_input_has_mouse_click_in_rect ( const struct nk_input * , enum nk_buttons , struct nk_rect ) ;
NK_API nk_bool nk_input_has_mouse_click_in_button_rect ( const struct nk_input * , enum nk_buttons , struct nk_rect ) ;
NK_API nk_bool nk_input_has_mouse_click_down_in_rect ( const struct nk_input * , enum nk_buttons , struct nk_rect , nk_bool down ) ;
NK_API nk_bool nk_input_is_mouse_click_in_rect ( const struct nk_input * , enum nk_buttons , struct nk_rect ) ;
NK_API nk_bool nk_input_is_mouse_click_down_in_rect ( const struct nk_input * i , enum nk_buttons id , struct nk_rect b , nk_bool down ) ;
@ -5838,7 +5842,9 @@ NK_GLOBAL const struct nk_color nk_yellow = {255,255,0,255};
else ( * ( s ) ) = NK_WIDGET_STATE_INACTIVE ;
/* math */
# ifndef NK_INV_SQRT
NK_LIB float nk_inv_sqrt ( float n ) ;
# endif
# ifndef NK_SIN
NK_LIB float nk_sin ( float x ) ;
# endif
@ -6132,6 +6138,8 @@ nk_stbtt_free(void *ptr, void *user_data) {
( it can actually approximate a lot more functions ) can be
found here : www . lolengine . net / wiki / oss / lolremez
*/
# ifndef NK_INV_SQRT
# define NK_INV_SQRT nk_inv_sqrt
NK_LIB float
nk_inv_sqrt ( float n )
{
@ -6144,6 +6152,7 @@ nk_inv_sqrt(float n)
conv . f = conv . f * ( threehalfs - ( x2 * conv . f * conv . f ) ) ;
return conv . f ;
}
# endif
# ifndef NK_SIN
# define NK_SIN nk_sin
NK_LIB float
@ -8430,7 +8439,6 @@ nk_str_append_text_utf8(struct nk_str *str, const char *text, int len)
NK_API int
nk_str_append_str_utf8 ( struct nk_str * str , const char * text )
{
int runes = 0 ;
int byte_len = 0 ;
int num_runes = 0 ;
int glyph_len = 0 ;
@ -8444,7 +8452,7 @@ nk_str_append_str_utf8(struct nk_str *str, const char *text)
num_runes + + ;
}
nk_str_append_text_char ( str , text , byte_len ) ;
return runes;
return num_ runes;
}
NK_API int
nk_str_append_text_runes ( struct nk_str * str , const nk_rune * text , int len )
@ -8559,7 +8567,6 @@ nk_str_insert_text_utf8(struct nk_str *str, int pos, const char *text, int len)
NK_API int
nk_str_insert_str_utf8 ( struct nk_str * str , int pos , const char * text )
{
int runes = 0 ;
int byte_len = 0 ;
int num_runes = 0 ;
int glyph_len = 0 ;
@ -8573,7 +8580,7 @@ nk_str_insert_str_utf8(struct nk_str *str, int pos, const char *text)
num_runes + + ;
}
nk_str_insert_at_rune ( str , pos , text , byte_len ) ;
return runes;
return num_ runes;
}
NK_API int
nk_str_insert_text_runes ( struct nk_str * str , int pos , const nk_rune * runes , int len )
@ -9554,7 +9561,7 @@ nk_draw_list_add_clip(struct nk_draw_list *list, struct nk_rect rect)
NK_ASSERT ( list ) ;
if ( ! list ) return ;
if ( ! list - > cmd_count ) {
nk_draw_list_push_command ( list , rect , list - > config . null. texture ) ;
nk_draw_list_push_command ( list , rect , list - > config . tex_ null. texture ) ;
} else {
struct nk_draw_command * prev = nk_draw_list_command_last ( list ) ;
if ( prev - > elem_count = = 0 )
@ -9854,7 +9861,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
/* vec2 inverted length */
len = nk_vec2_len_sqr ( diff ) ;
if ( len ! = 0.0f )
len = nk_inv_sqrt ( len ) ;
len = NK_INV_SQRT ( len ) ;
else len = 1.0f ;
diff = nk_vec2_muls ( diff , len ) ;
@ -9909,7 +9916,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
/* fill vertices */
for ( i = 0 ; i < points_count ; + + i ) {
const struct nk_vec2 uv = list - > config . null. uv ;
const struct nk_vec2 uv = list - > config . tex_ null. uv ;
vtx = nk_draw_vertex ( vtx , & list - > config , points [ i ] , uv , col ) ;
vtx = nk_draw_vertex ( vtx , & list - > config , temp [ i * 2 + 0 ] , uv , col_trans ) ;
vtx = nk_draw_vertex ( vtx , & list - > config , temp [ i * 2 + 1 ] , uv , col_trans ) ;
@ -9974,7 +9981,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
/* add vertices */
for ( i = 0 ; i < points_count ; + + i ) {
const struct nk_vec2 uv = list - > config . null. uv ;
const struct nk_vec2 uv = list - > config . tex_ null. uv ;
vtx = nk_draw_vertex ( vtx , & list - > config , temp [ i * 4 + 0 ] , uv , col_trans ) ;
vtx = nk_draw_vertex ( vtx , & list - > config , temp [ i * 4 + 1 ] , uv , col ) ;
vtx = nk_draw_vertex ( vtx , & list - > config , temp [ i * 4 + 2 ] , uv , col ) ;
@ -9995,7 +10002,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
for ( i1 = 0 ; i1 < count ; + + i1 ) {
float dx , dy ;
const struct nk_vec2 uv = list - > config . null. uv ;
const struct nk_vec2 uv = list - > config . tex_ null. uv ;
const nk_size i2 = ( ( i1 + 1 ) = = points_count ) ? 0 : i1 + 1 ;
const struct nk_vec2 p1 = points [ i1 ] ;
const struct nk_vec2 p2 = points [ i2 ] ;
@ -10005,7 +10012,7 @@ nk_draw_list_stroke_poly_line(struct nk_draw_list *list, const struct nk_vec2 *p
/* vec2 inverted length */
len = nk_vec2_len_sqr ( diff ) ;
if ( len ! = 0.0f )
len = nk_inv_sqrt ( len ) ;
len = NK_INV_SQRT ( len ) ;
else len = 1.0f ;
diff = nk_vec2_muls ( diff , len ) ;
@ -10095,7 +10102,7 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list,
/* vec2 inverted length */
float len = nk_vec2_len_sqr ( diff ) ;
if ( len ! = 0.0f )
len = nk_inv_sqrt ( len ) ;
len = NK_INV_SQRT ( len ) ;
else len = 1.0f ;
diff = nk_vec2_muls ( diff , len ) ;
@ -10105,7 +10112,7 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list,
/* add vertices + indexes */
for ( i0 = points_count - 1 , i1 = 0 ; i1 < points_count ; i0 = i1 + + ) {
const struct nk_vec2 uv = list - > config . null. uv ;
const struct nk_vec2 uv = list - > config . tex_ null. uv ;
struct nk_vec2 n0 = normals [ i0 ] ;
struct nk_vec2 n1 = normals [ i1 ] ;
struct nk_vec2 dm = nk_vec2_muls ( nk_vec2_add ( n0 , n1 ) , 0.5f ) ;
@ -10142,7 +10149,7 @@ nk_draw_list_fill_poly_convex(struct nk_draw_list *list,
if ( ! vtx | | ! ids ) return ;
for ( i = 0 ; i < vtx_count ; + + i )
vtx = nk_draw_vertex ( vtx , & list - > config , points [ i ] , list - > config . null. uv , col ) ;
vtx = nk_draw_vertex ( vtx , & list - > config , points [ i ] , list - > config . tex_ null. uv , col ) ;
for ( i = 2 ; i < points_count ; + + i ) {
ids [ 0 ] = ( nk_draw_index ) index ;
ids [ 1 ] = ( nk_draw_index ) ( index + i - 1 ) ;
@ -10171,8 +10178,8 @@ nk_draw_list_path_line_to(struct nk_draw_list *list, struct nk_vec2 pos)
nk_draw_list_add_clip ( list , nk_null_rect ) ;
cmd = nk_draw_list_command_last ( list ) ;
if ( cmd & & cmd - > texture . ptr ! = list - > config . null. texture . ptr )
nk_draw_list_push_image ( list , list - > config . null. texture ) ;
if ( cmd & & cmd - > texture . ptr ! = list - > config . tex_ null. texture . ptr )
nk_draw_list_push_image ( list , list - > config . tex_ null. texture ) ;
points = nk_draw_list_alloc_path ( list , 1 ) ;
if ( ! points ) return ;
@ -10374,7 +10381,7 @@ nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list, struct nk_rect rec
NK_ASSERT ( list ) ;
if ( ! list ) return ;
nk_draw_list_push_image ( list , list - > config . null. texture ) ;
nk_draw_list_push_image ( list , list - > config . tex_ null. texture ) ;
index = ( nk_draw_index ) list - > vertex_count ;
vtx = nk_draw_list_alloc_vertices ( list , 4 ) ;
idx = nk_draw_list_alloc_elements ( list , 6 ) ;
@ -10384,10 +10391,10 @@ nk_draw_list_fill_rect_multi_color(struct nk_draw_list *list, struct nk_rect rec
idx [ 2 ] = ( nk_draw_index ) ( index + 2 ) ; idx [ 3 ] = ( nk_draw_index ) ( index + 0 ) ;
idx [ 4 ] = ( nk_draw_index ) ( index + 2 ) ; idx [ 5 ] = ( nk_draw_index ) ( index + 3 ) ;
vtx = nk_draw_vertex ( vtx , & list - > config , nk_vec2 ( rect . x , rect . y ) , list - > config . null. uv , col_left ) ;
vtx = nk_draw_vertex ( vtx , & list - > config , nk_vec2 ( rect . x + rect . w , rect . y ) , list - > config . null. uv , col_top ) ;
vtx = nk_draw_vertex ( vtx , & list - > config , nk_vec2 ( rect . x + rect . w , rect . y + rect . h ) , list - > config . null. uv , col_right ) ;
vtx = nk_draw_vertex ( vtx , & list - > config , nk_vec2 ( rect . x , rect . y + rect . h ) , list - > config . null. uv , col_bottom ) ;
vtx = nk_draw_vertex ( vtx , & list - > config , nk_vec2 ( rect . x , rect . y ) , list - > config . tex_ null. uv , col_left ) ;
vtx = nk_draw_vertex ( vtx , & list - > config , nk_vec2 ( rect . x + rect . w , rect . y ) , list - > config . tex_ null. uv , col_top ) ;
vtx = nk_draw_vertex ( vtx , & list - > config , nk_vec2 ( rect . x + rect . w , rect . y + rect . h ) , list - > config . tex_ null. uv , col_right ) ;
vtx = nk_draw_vertex ( vtx , & list - > config , nk_vec2 ( rect . x , rect . y + rect . h ) , list - > config . tex_ null. uv , col_bottom ) ;
}
NK_API void
nk_draw_list_fill_triangle ( struct nk_draw_list * list , struct nk_vec2 a ,
@ -16503,7 +16510,7 @@ nk_font_chinese_glyph_ranges(void)
0x3000 , 0x30FF ,
0x31F0 , 0x31FF ,
0xFF00 , 0xFFEF ,
0x4 e 00, 0x9FAF ,
0x4 E 00, 0x9FAF ,
0
} ;
return ranges ;
@ -16612,7 +16619,7 @@ nk_font_bake_pack(struct nk_font_baker *baker,
struct stbtt_fontinfo * font_info = & baker - > build [ i + + ] . info ;
font_info - > userdata = alloc ;
if ( ! stbtt_InitFont ( font_info , ( const unsigned char * ) it - > ttf_blob , 0 ) )
if ( ! stbtt_InitFont ( font_info , ( const unsigned char * ) it - > ttf_blob , stbtt_GetFontOffsetForIndex ( ( const unsigned char * ) it - > ttf_blob , 0 ) ) )
return nk_false ;
} while ( ( it = it - > n ) ! = config_iter ) ;
}
@ -17694,20 +17701,20 @@ failed:
}
NK_API void
nk_font_atlas_end ( struct nk_font_atlas * atlas , nk_handle texture ,
struct nk_draw_null_texture * null)
struct nk_draw_null_texture * tex_ null)
{
int i = 0 ;
struct nk_font * font_iter ;
NK_ASSERT ( atlas ) ;
if ( ! atlas ) {
if ( ! null) return ;
null- > texture = texture ;
null- > uv = nk_vec2 ( 0.5f , 0.5f ) ;
if ( ! tex_ null) return ;
tex_ null- > texture = texture ;
tex_ null- > uv = nk_vec2 ( 0.5f , 0.5f ) ;
}
if ( null) {
null- > texture = texture ;
null- > uv . x = ( atlas - > custom . x + 0.5f ) / ( float ) atlas - > tex_width ;
null- > uv . y = ( atlas - > custom . y + 0.5f ) / ( float ) atlas - > tex_height ;
if ( tex_ null) {
tex_ null- > texture = texture ;
tex_ null- > uv . x = ( atlas - > custom . x + 0.5f ) / ( float ) atlas - > tex_width ;
tex_ null- > uv . y = ( atlas - > custom . y + 0.5f ) / ( float ) atlas - > tex_height ;
}
for ( font_iter = atlas - > fonts ; font_iter ; font_iter = font_iter - > next ) {
font_iter - > texture = texture ;
@ -17876,6 +17883,13 @@ nk_input_button(struct nk_context *ctx, enum nk_buttons id, int x, int y, nk_boo
btn - > clicked_pos . y = ( float ) y ;
btn - > down = down ;
btn - > clicked + + ;
# ifdef NK_BUTTON_TRIGGER_ON_RELEASE
if ( down = = 1 & & id = = NK_BUTTON_LEFT )
{
in - > mouse . down_pos . x = btn - > clicked_pos . x ;
in - > mouse . down_pos . y = btn - > clicked_pos . y ;
}
# endif
}
NK_API void
nk_input_scroll ( struct nk_context * ctx , struct nk_vec2 val )
@ -17941,6 +17955,22 @@ nk_input_has_mouse_click_in_rect(const struct nk_input *i, enum nk_buttons id,
return nk_true ;
}
NK_API nk_bool
nk_input_has_mouse_click_in_button_rect ( const struct nk_input * i , enum nk_buttons id ,
struct nk_rect b )
{
const struct nk_mouse_button * btn ;
if ( ! i ) return nk_false ;
btn = & i - > mouse . buttons [ id ] ;
# ifdef NK_BUTTON_TRIGGER_ON_RELEASE
if ( ! NK_INBOX ( btn - > clicked_pos . x , btn - > clicked_pos . y , b . x , b . y , b . w , b . h )
| | ! NK_INBOX ( i - > mouse . down_pos . x , i - > mouse . down_pos . y , b . x , b . y , b . w , b . h ) )
# else
if ( ! NK_INBOX ( btn - > clicked_pos . x , btn - > clicked_pos . y , b . x , b . y , b . w , b . h ) )
# endif
return nk_false ;
return nk_true ;
}
NK_API nk_bool
nk_input_has_mouse_click_down_in_rect ( const struct nk_input * i , enum nk_buttons id ,
struct nk_rect b , nk_bool down )
{
@ -23750,7 +23780,7 @@ nk_button_behavior(nk_flags *state, struct nk_rect r,
* state = NK_WIDGET_STATE_HOVERED ;
if ( nk_input_is_mouse_down ( i , NK_BUTTON_LEFT ) )
* state = NK_WIDGET_STATE_ACTIVE ;
if ( nk_input_has_mouse_click_in_ rect( i , NK_BUTTON_LEFT , r ) ) {
if ( nk_input_has_mouse_click_in_ button_ rect( i , NK_BUTTON_LEFT , r ) ) {
ret = ( behavior ! = NK_BUTTON_DEFAULT ) ?
nk_input_is_mouse_down ( i , NK_BUTTON_LEFT ) :
# ifdef NK_BUTTON_TRIGGER_ON_RELEASE
@ -26130,7 +26160,7 @@ nk_textedit_text(struct nk_text_edit *state, const char *text, int total_len)
text + text_len , 1 ) )
{
nk_textedit_makeundo_insert ( state , state - > cursor , 1 ) ;
+ + state - > cursor ;
state - > cursor = NK_MIN ( state - > cursor + 1 , state - > string . len ) ;
state - > has_preferred_x = 0 ;
}
}
@ -29624,6 +29654,16 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
/// - [y]: Minor version with non-breaking API and library changes
/// - [z]: Patch version with no direct changes to the API
///
/// - 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly
/// - 2022/10/24 (4.10.4) - Fix nk_str_{append,insert}_str_utf8 always returning 0
/// - 2022/09/03 (4.10.3) - Renamed the `null` texture variable to `tex_null`
/// - 2022/08/01 (4.10.2) - Fix Apple Silicon with incorrect NK_SITE_TYPE and NK_POINTER_TYPE
/// - 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than
/// nk_edit_xxx limit
/// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug
/// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to
/// only trigger when the mouse position was inside the same button on down
/// - 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS
/// - 2021/12/22 (4.9.5) - Revert layout bounds not accounting for padding due to regressions
/// - 2021/12/22 (4.9.4) - Fix checking hovering when window is minimized
/// - 2021/12/22 (4.09.3) - Fix layout bounds not accounting for padding