@ -1,5 +1,5 @@
/*
/*
Nuklear - v1 .2 0 - public domain
Nuklear - 1.33 . 0 - public domain
no warrenty implied ; use at your own risk .
no warrenty implied ; use at your own risk .
authored from 2015 - 2016 by Micha Mettke
authored from 2015 - 2016 by Micha Mettke
@ -271,11 +271,17 @@ extern "C" {
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
*/
# ifndef NK_API
# ifndef NK_API
# ifdef NK_PRIVATE
# ifdef NK_PRIVATE
# define NK_API static
# if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199409L))
# else
# define NK_API static inline
# define NK_API extern
# elif defined(__cplusplus)
# endif
# define NK_API static inline
# else
# define NK_API static
# endif
# else
# define NK_API extern
# endif
# endif
# endif
# define NK_INTERN static
# define NK_INTERN static
@ -356,10 +362,10 @@ extern "C" {
# endif
# endif
# endif
# endif
# ifndef NK_SIZE_TYPE
# ifndef NK_SIZE_TYPE
# if (defined(__WIN32) || defined(WIN32) ) && defined(_MSC_VER)
# if defined(_WIN64 ) && defined(_MSC_VER)
# define NK_SIZE_TYPE __int32
# define NK_SIZE_TYPE unsigned __int64
# elif defined(__WIN64 ) && defined(_MSC_VER)
# elif (defined(_WIN32) || defined(WIN32) ) && defined(_MSC_VER)
# define NK_SIZE_TYPE __int64
# define NK_SIZE_TYPE unsigned __int32
# elif defined(__GNUC__) || defined(__clang__)
# elif defined(__GNUC__) || defined(__clang__)
# if defined(__x86_64__) || defined(__ppc64__)
# if defined(__x86_64__) || defined(__ppc64__)
# define NK_SIZE_TYPE unsigned long
# define NK_SIZE_TYPE unsigned long
@ -371,10 +377,10 @@ extern "C" {
# endif
# endif
# endif
# endif
# ifndef NK_POINTER_TYPE
# ifndef NK_POINTER_TYPE
# if (defined(__WIN32) || defined(WIN32)) && defined(_MSC_VER)
# if defined(_WIN64) && defined(_MSC_VER)
# define NK_POINTER_TYPE unsigned __int32
# elif defined(__WIN64) && defined(_MSC_VER)
# define NK_POINTER_TYPE unsigned __int64
# define NK_POINTER_TYPE unsigned __int64
# elif (defined(_WIN32) || defined(WIN32)) && defined(_MSC_VER)
# define NK_POINTER_TYPE unsigned __int32
# elif defined(__GNUC__) || defined(__clang__)
# elif defined(__GNUC__) || defined(__clang__)
# if defined(__x86_64__) || defined(__ppc64__)
# if defined(__x86_64__) || defined(__ppc64__)
# define NK_POINTER_TYPE unsigned long
# define NK_POINTER_TYPE unsigned long
@ -688,7 +694,8 @@ enum nk_panel_flags {
NK_WINDOW_NO_SCROLLBAR = NK_FLAG ( 5 ) , /* Removes the scrollbar from the window */
NK_WINDOW_NO_SCROLLBAR = NK_FLAG ( 5 ) , /* Removes the scrollbar from the window */
NK_WINDOW_TITLE = NK_FLAG ( 6 ) , /* Forces a header at the top at the window showing the title */
NK_WINDOW_TITLE = NK_FLAG ( 6 ) , /* Forces a header at the top at the window showing the title */
NK_WINDOW_SCROLL_AUTO_HIDE = NK_FLAG ( 7 ) , /* Automatically hides the window scrollbar if no user interaction: also requires delta time in `nk_context` to be set each frame */
NK_WINDOW_SCROLL_AUTO_HIDE = NK_FLAG ( 7 ) , /* Automatically hides the window scrollbar if no user interaction: also requires delta time in `nk_context` to be set each frame */
NK_WINDOW_BACKGROUND = NK_FLAG ( 8 ) /* Always keep window in the background */
NK_WINDOW_BACKGROUND = NK_FLAG ( 8 ) , /* Always keep window in the background */
NK_WINDOW_SCALE_LEFT = NK_FLAG ( 9 ) /* Puts window scaler in the left-ottom corner instead right-bottom*/
} ;
} ;
/* context */
/* context */
@ -751,10 +758,17 @@ NK_API void nk_layout_row_push(struct nk_context*, float val
NK_API void nk_layout_row_end ( struct nk_context * ) ;
NK_API void nk_layout_row_end ( struct nk_context * ) ;
NK_API void nk_layout_row ( struct nk_context * , enum nk_layout_format , float height , int cols , const float * ratio ) ;
NK_API void nk_layout_row ( struct nk_context * , enum nk_layout_format , float height , int cols , const float * ratio ) ;
NK_API void nk_layout_row_template_begin ( struct nk_context * , float height ) ;
NK_API void nk_layout_row_template_push_dynamic ( struct nk_context * ) ;
NK_API void nk_layout_row_template_push_variable ( struct nk_context * , float min_width ) ;
NK_API void nk_layout_row_template_push_static ( struct nk_context * , float width ) ;
NK_API void nk_layout_row_template_end ( struct nk_context * ) ;
NK_API void nk_layout_space_begin ( struct nk_context * , enum nk_layout_format , float height , int widget_count ) ;
NK_API void nk_layout_space_begin ( struct nk_context * , enum nk_layout_format , float height , int widget_count ) ;
NK_API void nk_layout_space_push ( struct nk_context * , struct nk_rect ) ;
NK_API void nk_layout_space_push ( struct nk_context * , struct nk_rect ) ;
NK_API void nk_layout_space_end ( struct nk_context * ) ;
NK_API void nk_layout_space_end ( struct nk_context * ) ;
/* Layout: Utility */
NK_API struct nk_rect nk_layout_space_bounds ( struct nk_context * ) ;
NK_API struct nk_rect nk_layout_space_bounds ( struct nk_context * ) ;
NK_API struct nk_vec2 nk_layout_space_to_screen ( struct nk_context * , struct nk_vec2 ) ;
NK_API struct nk_vec2 nk_layout_space_to_screen ( struct nk_context * , struct nk_vec2 ) ;
NK_API struct nk_vec2 nk_layout_space_to_local ( struct nk_context * , struct nk_vec2 ) ;
NK_API struct nk_vec2 nk_layout_space_to_local ( struct nk_context * , struct nk_vec2 ) ;
@ -885,7 +899,8 @@ NK_API float nk_propertyf(struct nk_context*, const char *nam
NK_API double nk_propertyd ( struct nk_context * , const char * name , double min , double val , double max , double step , float inc_per_pixel ) ;
NK_API double nk_propertyd ( struct nk_context * , const char * name , double min , double val , double max , double step , float inc_per_pixel ) ;
/* Widgets: TextEdit */
/* Widgets: TextEdit */
NK_API void nk_edit_focus ( struct nk_context * ctx , nk_flags flags ) ;
NK_API void nk_edit_focus ( struct nk_context * , nk_flags flags ) ;
NK_API void nk_edit_unfocus ( struct nk_context * ) ;
NK_API nk_flags nk_edit_string ( struct nk_context * , nk_flags , char * buffer , int * len , int max , nk_plugin_filter ) ;
NK_API nk_flags nk_edit_string ( struct nk_context * , nk_flags , char * buffer , int * len , int max , nk_plugin_filter ) ;
NK_API nk_flags nk_edit_buffer ( struct nk_context * , nk_flags , struct nk_text_edit * , nk_plugin_filter ) ;
NK_API nk_flags nk_edit_buffer ( struct nk_context * , nk_flags , struct nk_text_edit * , nk_plugin_filter ) ;
NK_API nk_flags nk_edit_string_zero_terminated ( struct nk_context * , nk_flags , char * buffer , int max , nk_plugin_filter ) ;
NK_API nk_flags nk_edit_string_zero_terminated ( struct nk_context * , nk_flags , char * buffer , int max , nk_plugin_filter ) ;
@ -2612,6 +2627,9 @@ NK_API struct nk_style_item nk_style_item_hide(void);
/*==============================================================
/*==============================================================
* PANEL
* PANEL
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
# ifndef NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS
# define NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS 16
# endif
# ifndef NK_CHART_MAX_SLOT
# ifndef NK_CHART_MAX_SLOT
# define NK_CHART_MAX_SLOT 4
# define NK_CHART_MAX_SLOT 4
# endif
# endif
@ -2647,8 +2665,20 @@ struct nk_chart {
struct nk_chart_slot slots [ NK_CHART_MAX_SLOT ] ;
struct nk_chart_slot slots [ NK_CHART_MAX_SLOT ] ;
} ;
} ;
enum nk_panel_row_layout_type {
NK_LAYOUT_DYNAMIC_FIXED = 0 ,
NK_LAYOUT_DYNAMIC_ROW ,
NK_LAYOUT_DYNAMIC_FREE ,
NK_LAYOUT_DYNAMIC ,
NK_LAYOUT_STATIC_FIXED ,
NK_LAYOUT_STATIC_ROW ,
NK_LAYOUT_STATIC_FREE ,
NK_LAYOUT_STATIC ,
NK_LAYOUT_TEMPLATE ,
NK_LAYOUT_COUNT
} ;
struct nk_row_layout {
struct nk_row_layout {
int type ;
enum nk_panel_row_layout_type type ;
int index ;
int index ;
float height ;
float height ;
int columns ;
int columns ;
@ -2659,6 +2689,7 @@ struct nk_row_layout {
float filled ;
float filled ;
struct nk_rect item ;
struct nk_rect item ;
int tree_depth ;
int tree_depth ;
float templates [ NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS ] ;
} ;
} ;
struct nk_popup_buffer {
struct nk_popup_buffer {
@ -3115,7 +3146,7 @@ template<typename T> struct nk_alignof{struct Big {T x; char c;}; enum {
# define NK_SINT_MIN (-2147483647)
# define NK_SINT_MIN (-2147483647)
# define NK_SINT_MAX 2147483647
# define NK_SINT_MAX 2147483647
# define NK_UINT_MIN 0
# define NK_UINT_MIN 0
# define NK_UINT_MAX 4294967295
# define NK_UINT_MAX 4294967295u
/* Make sure correct type size:
/* Make sure correct type size:
* This will fire with a negative subscript error if the type sizes
* This will fire with a negative subscript error if the type sizes
@ -3716,7 +3747,7 @@ nk_strmatch_fuzzy_text(const char *str, int str_len,
int next_match = * pattern_iter ! = ' \0 ' & &
int next_match = * pattern_iter ! = ' \0 ' & &
nk_to_lower ( pattern_letter ) = = nk_to_lower ( str_letter ) ;
nk_to_lower ( pattern_letter ) = = nk_to_lower ( str_letter ) ;
int rematch = best_letter & & nk_to_low er ( * best_letter ) = = nk_to_low er ( str_letter ) ;
int rematch = best_letter & & nk_to_upp er ( * best_letter ) = = nk_to_upp er ( str_letter ) ;
int advanced = next_match & & best_letter ;
int advanced = next_match & & best_letter ;
int pattern_repeat = best_letter & & * pattern_iter ! = ' \0 ' ;
int pattern_repeat = best_letter & & * pattern_iter ! = ' \0 ' ;
@ -13407,8 +13438,8 @@ nk_slider_behavior(nk_flags *state, struct nk_rect *logical_cursor,
if ( left_mouse_down & & left_mouse_click_in_cursor )
if ( left_mouse_down & & left_mouse_click_in_cursor )
{
{
float ratio = 0 ;
float ratio = 0 ;
const float d = in - > mouse . pos . x - ( visual_cursor - > x + visual_cursor - > w / 2.0 f ) ;
const float d = in - > mouse . pos . x - ( visual_cursor - > x + visual_cursor - > w * 0.5 f) ;
const float pxstep = ( bounds . w - ( 2 * style - > padding . x ) ) / slider_steps ;
const float pxstep = bounds . w / slider_steps ;
/* only update value if the next slider step is reached */
/* only update value if the next slider step is reached */
* state = NK_WIDGET_STATE_ACTIVE ;
* state = NK_WIDGET_STATE_ACTIVE ;
@ -13418,7 +13449,7 @@ nk_slider_behavior(nk_flags *state, struct nk_rect *logical_cursor,
slider_value = NK_CLAMP ( slider_min , slider_value , slider_max ) ;
slider_value = NK_CLAMP ( slider_min , slider_value , slider_max ) ;
ratio = ( slider_value - slider_min ) / slider_step ;
ratio = ( slider_value - slider_min ) / slider_step ;
logical_cursor - > x = bounds . x + ( logical_cursor - > w * ratio ) ;
logical_cursor - > x = bounds . x + ( logical_cursor - > w * ratio ) ;
in - > mouse . buttons [ NK_BUTTON_LEFT ] . clicked_pos . x = logical_cursor - > x + logical_cursor - > w / 2.0f ;
in - > mouse . buttons [ NK_BUTTON_LEFT ] . clicked_pos . x = logical_cursor - > x ;
}
}
}
}
@ -13548,6 +13579,10 @@ nk_do_slider(nk_flags *state,
bounds . w = bounds . w - ( 2 * button . w + 2 * style - > spacing . x ) ;
bounds . w = bounds . w - ( 2 * button . w + 2 * style - > spacing . x ) ;
}
}
/* remove one cursor size to support visual cursor */
bounds . x + = style - > cursor_size . x * 0.5f ;
bounds . w - = style - > cursor_size . x ;
/* make sure the provided values are correct */
/* make sure the provided values are correct */
slider_max = NK_MAX ( min , max ) ;
slider_max = NK_MAX ( min , max ) ;
slider_min = NK_MIN ( min , max ) ;
slider_min = NK_MIN ( min , max ) ;
@ -13556,10 +13591,6 @@ nk_do_slider(nk_flags *state,
slider_steps = slider_range / step ;
slider_steps = slider_range / step ;
cursor_offset = ( slider_value - slider_min ) / step ;
cursor_offset = ( slider_value - slider_min ) / step ;
/* remove one cursor size to support visual cursor */
bounds . x + = style - > cursor_size . x * 0.5f ;
bounds . w - = style - > cursor_size . x ;
/* calculate cursor
/* calculate cursor
Basically you have two cursors . One for visual representation and interaction
Basically you have two cursors . One for visual representation and interaction
and one for updating the actual cursor value . */
and one for updating the actual cursor value . */
@ -13571,7 +13602,7 @@ nk_do_slider(nk_flags *state,
visual_cursor . h = style - > cursor_size . y ;
visual_cursor . h = style - > cursor_size . y ;
visual_cursor . w = style - > cursor_size . x ;
visual_cursor . w = style - > cursor_size . x ;
visual_cursor . y = ( bounds . y + bounds . h * 0.5f ) - visual_cursor . h * 0.5f ;
visual_cursor . y = ( bounds . y + bounds . h * 0.5f ) - visual_cursor . h * 0.5f ;
visual_cursor . x = ( logical_cursor . x + logical_cursor . w * 0.5f ) - visual_cursor . w * 0.5f ;
visual_cursor . x = logical_cursor . x - visual_cursor . w * 0.5f ;
slider_value = nk_slider_behavior ( state , & logical_cursor , & visual_cursor ,
slider_value = nk_slider_behavior ( state , & logical_cursor , & visual_cursor ,
in , style , bounds , slider_min , slider_max , slider_value , step , slider_steps ) ;
in , style , bounds , slider_min , slider_max , slider_value , step , slider_steps ) ;
@ -16069,6 +16100,12 @@ nk_clear(struct nk_context *ctx)
continue ;
continue ;
}
}
/* remove hotness from hidden or closed windows*/
if ( ( ( iter - > flags & NK_WINDOW_HIDDEN ) | |
( iter - > flags & NK_WINDOW_CLOSED ) ) & &
iter = = ctx - > active )
ctx - > active = iter - > next ;
/* free unused popup windows */
/* free unused popup windows */
if ( iter - > popup . win & & iter - > popup . win - > seq ! = ctx - > seq ) {
if ( iter - > popup . win & & iter - > popup . win - > seq ! = ctx - > seq ) {
nk_free_window ( ctx , iter - > popup . win ) ;
nk_free_window ( ctx , iter - > popup . win ) ;
@ -16683,7 +16720,7 @@ nk_panel_end(struct nk_context *ctx)
scroll . w = scrollbar_size . x ;
scroll . w = scrollbar_size . x ;
scroll . h = layout - > bounds . h ;
scroll . h = layout - > bounds . h ;
scroll_offset = * layout - > offset_y ;
scroll_offset = ( float ) * layout - > offset_y ;
scroll_step = scroll . h * 0.10f ;
scroll_step = scroll . h * 0.10f ;
scroll_inc = scroll . h * 0.01f ;
scroll_inc = scroll . h * 0.01f ;
scroll_target = ( float ) ( int ) ( layout - > at_y - scroll . y ) ;
scroll_target = ( float ) ( int ) ( layout - > at_y - scroll . y ) ;
@ -16741,7 +16778,7 @@ nk_panel_end(struct nk_context *ctx)
scroll . w = layout - > bounds . w ;
scroll . w = layout - > bounds . w ;
scroll . h = scrollbar_size . y ;
scroll . h = scrollbar_size . y ;
scroll_offset = * layout - > offset_x ;
scroll_offset = ( float ) * layout - > offset_x ;
scroll_target = ( float ) ( int ) ( layout - > max_x - scroll . x ) ;
scroll_target = ( float ) ( int ) ( layout - > max_x - scroll . x ) ;
scroll_step = layout - > max_x * 0.05f ;
scroll_step = layout - > max_x * 0.05f ;
scroll_inc = layout - > max_x * 0.005f ;
scroll_inc = layout - > max_x * 0.005f ;
@ -16801,7 +16838,9 @@ nk_panel_end(struct nk_context *ctx)
scaler . w = scrollbar_size . x ;
scaler . w = scrollbar_size . x ;
scaler . h = scrollbar_size . y ;
scaler . h = scrollbar_size . y ;
scaler . y = layout - > bounds . y + layout - > bounds . h ;
scaler . y = layout - > bounds . y + layout - > bounds . h ;
scaler . x = layout - > bounds . x + layout - > bounds . w + panel_padding . x ;
if ( layout - > flags & NK_WINDOW_SCALE_LEFT )
scaler . x = layout - > bounds . x - panel_padding . x * 0.5f ;
else scaler . x = layout - > bounds . x + layout - > bounds . w + panel_padding . x ;
if ( layout - > flags & NK_WINDOW_NO_SCROLLBAR )
if ( layout - > flags & NK_WINDOW_NO_SCROLLBAR )
scaler . x - = scaler . w ;
scaler . x - = scaler . w ;
@ -16809,9 +16848,16 @@ nk_panel_end(struct nk_context *ctx)
{ const struct nk_style_item * item = & style - > window . scaler ;
{ const struct nk_style_item * item = & style - > window . scaler ;
if ( item - > type = = NK_STYLE_ITEM_IMAGE )
if ( item - > type = = NK_STYLE_ITEM_IMAGE )
nk_draw_image ( out , scaler , & item - > data . image , nk_white ) ;
nk_draw_image ( out , scaler , & item - > data . image , nk_white ) ;
else nk_fill_triangle ( out , scaler . x + scaler . w , scaler . y , scaler . x + scaler . w ,
else {
scaler . y + scaler . h , scaler . x , scaler . y + scaler . h , item - > data . color ) ;
if ( layout - > flags & NK_WINDOW_SCALE_LEFT ) {
}
nk_fill_triangle ( out , scaler . x , scaler . y , scaler . x ,
scaler . y + scaler . h , scaler . x + scaler . w ,
scaler . y + scaler . h , item - > data . color ) ;
} else {
nk_fill_triangle ( out , scaler . x + scaler . w , scaler . y , scaler . x + scaler . w ,
scaler . y + scaler . h , scaler . x , scaler . y + scaler . h , item - > data . color ) ;
}
} }
/* do window scaling */
/* do window scaling */
if ( ! ( window - > flags & NK_WINDOW_ROM ) ) {
if ( ! ( window - > flags & NK_WINDOW_ROM ) ) {
@ -16821,7 +16867,13 @@ nk_panel_end(struct nk_context *ctx)
NK_BUTTON_LEFT , scaler , nk_true ) ;
NK_BUTTON_LEFT , scaler , nk_true ) ;
if ( nk_input_is_mouse_down ( in , NK_BUTTON_LEFT ) & & left_mouse_down & & left_mouse_click_in_scaler ) {
if ( nk_input_is_mouse_down ( in , NK_BUTTON_LEFT ) & & left_mouse_down & & left_mouse_click_in_scaler ) {
window - > bounds . w = NK_MAX ( window_size . x , window - > bounds . w + in - > mouse . delta . x ) ;
float delta_x = in - > mouse . delta . x ;
if ( layout - > flags & NK_WINDOW_SCALE_LEFT ) {
delta_x = - delta_x ;
window - > bounds . x + = in - > mouse . delta . x ;
}
window - > bounds . w = NK_MAX ( window_size . x , window - > bounds . w + delta_x ) ;
/* dragging in y-direction is only possible if static window */
/* dragging in y-direction is only possible if static window */
if ( ! ( layout - > flags & NK_WINDOW_DYNAMIC ) )
if ( ! ( layout - > flags & NK_WINDOW_DYNAMIC ) )
window - > bounds . h = NK_MAX ( window_size . y , window - > bounds . h + in - > mouse . delta . y ) ;
window - > bounds . h = NK_MAX ( window_size . y , window - > bounds . h + in - > mouse . delta . y ) ;
@ -17266,7 +17318,7 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title,
* provided demo backends ) . */
* provided demo backends ) . */
NK_ASSERT ( win - > seq ! = ctx - > seq ) ;
NK_ASSERT ( win - > seq ! = ctx - > seq ) ;
win - > seq = ctx - > seq ;
win - > seq = ctx - > seq ;
if ( ! ctx - > active )
if ( ! ctx - > active & & ! ( win - > flags & NK_WINDOW_HIDDEN ) )
ctx - > active = win ;
ctx - > active = win ;
}
}
if ( win - > flags & NK_WINDOW_HIDDEN ) {
if ( win - > flags & NK_WINDOW_HIDDEN ) {
@ -17680,9 +17732,9 @@ nk_window_show(struct nk_context *ctx, const char *name, enum nk_show_states s)
title_hash = nk_murmur_hash ( name , ( int ) title_len , NK_WINDOW_TITLE ) ;
title_hash = nk_murmur_hash ( name , ( int ) title_len , NK_WINDOW_TITLE ) ;
win = nk_find_window ( ctx , title_hash , name ) ;
win = nk_find_window ( ctx , title_hash , name ) ;
if ( ! win ) return ;
if ( ! win ) return ;
if ( s = = NK_HIDDEN )
if ( s = = NK_HIDDEN ) {
win - > flags | = NK_WINDOW_HIDDEN ;
win - > flags | = NK_WINDOW_HIDDEN ;
else win - > flags & = ~ ( nk_flags ) NK_WINDOW_HIDDEN ;
} else win - > flags & = ~ ( nk_flags ) NK_WINDOW_HIDDEN ;
}
}
NK_API void
NK_API void
@ -17792,14 +17844,26 @@ nk_menubar_end(struct nk_context *ctx)
* LAYOUT
* LAYOUT
*
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
# define NK_LAYOUT_DYNAMIC_FIXED 0
NK_INTERN float
# define NK_LAYOUT_DYNAMIC_ROW 1
nk_layout_row_calculate_usable_space ( const struct nk_style * style , enum nk_panel_type type ,
# define NK_LAYOUT_DYNAMIC_FREE 2
float total_space , int columns )
# define NK_LAYOUT_DYNAMIC 3
{
# define NK_LAYOUT_STATIC_FIXED 4
float panel_padding ;
# define NK_LAYOUT_STATIC_ROW 5
float panel_spacing ;
# define NK_LAYOUT_STATIC_FREE 6
float panel_space ;
# define NK_LAYOUT_STATIC 7
struct nk_vec2 spacing ;
struct nk_vec2 padding ;
spacing = style - > window . spacing ;
padding = nk_panel_get_padding ( style , type ) ;
/* calculate the usable panel space */
panel_padding = 2 * padding . x ;
panel_spacing = ( float ) NK_MAX ( columns - 1 , 0 ) * spacing . x ;
panel_space = total_space - panel_padding - panel_spacing ;
return panel_space ;
}
NK_INTERN void
NK_INTERN void
nk_panel_layout ( const struct nk_context * ctx , struct nk_window * win ,
nk_panel_layout ( const struct nk_context * ctx , struct nk_window * win ,
@ -17939,6 +18003,10 @@ nk_layout_row_push(struct nk_context *ctx, float ratio_or_width)
win = ctx - > current ;
win = ctx - > current ;
layout = win - > layout ;
layout = win - > layout ;
NK_ASSERT ( layout - > row . type = = NK_LAYOUT_STATIC_ROW | | layout - > row . type = = NK_LAYOUT_DYNAMIC_ROW ) ;
if ( layout - > row . type ! = NK_LAYOUT_STATIC_ROW & & layout - > row . type ! = NK_LAYOUT_DYNAMIC_ROW )
return ;
if ( layout - > row . type = = NK_LAYOUT_DYNAMIC_ROW ) {
if ( layout - > row . type = = NK_LAYOUT_DYNAMIC_ROW ) {
float ratio = ratio_or_width ;
float ratio = ratio_or_width ;
if ( ( ratio + layout - > row . filled ) > 1.0f ) return ;
if ( ( ratio + layout - > row . filled ) > 1.0f ) return ;
@ -17962,6 +18030,9 @@ nk_layout_row_end(struct nk_context *ctx)
win = ctx - > current ;
win = ctx - > current ;
layout = win - > layout ;
layout = win - > layout ;
NK_ASSERT ( layout - > row . type = = NK_LAYOUT_STATIC_ROW | | layout - > row . type = = NK_LAYOUT_DYNAMIC_ROW ) ;
if ( layout - > row . type ! = NK_LAYOUT_STATIC_ROW & & layout - > row . type ! = NK_LAYOUT_DYNAMIC_ROW )
return ;
layout - > row . item_width = 0 ;
layout - > row . item_width = 0 ;
layout - > row . item_offset = 0 ;
layout - > row . item_offset = 0 ;
}
}
@ -18006,6 +18077,149 @@ nk_layout_row(struct nk_context *ctx, enum nk_layout_format fmt,
layout - > row . filled = 0 ;
layout - > row . filled = 0 ;
}
}
NK_API void
nk_layout_row_template_begin ( struct nk_context * ctx , float height )
{
struct nk_window * win ;
struct nk_panel * layout ;
NK_ASSERT ( ctx ) ;
NK_ASSERT ( ctx - > current ) ;
NK_ASSERT ( ctx - > current - > layout ) ;
if ( ! ctx | | ! ctx - > current | | ! ctx - > current - > layout )
return ;
win = ctx - > current ;
layout = win - > layout ;
nk_panel_layout ( ctx , win , height , 1 ) ;
layout - > row . type = NK_LAYOUT_TEMPLATE ;
layout - > row . columns = 0 ;
layout - > row . ratio = 0 ;
layout - > row . item_width = 0 ;
layout - > row . item_height = 0 ;
layout - > row . item_offset = 0 ;
layout - > row . filled = 0 ;
layout - > row . item . x = 0 ;
layout - > row . item . y = 0 ;
layout - > row . item . w = 0 ;
layout - > row . item . h = 0 ;
}
NK_API void
nk_layout_row_template_push_dynamic ( struct nk_context * ctx )
{
struct nk_window * win ;
struct nk_panel * layout ;
NK_ASSERT ( ctx ) ;
NK_ASSERT ( ctx - > current ) ;
NK_ASSERT ( ctx - > current - > layout ) ;
if ( ! ctx | | ! ctx - > current | | ! ctx - > current - > layout )
return ;
win = ctx - > current ;
layout = win - > layout ;
NK_ASSERT ( layout - > row . type = = NK_LAYOUT_TEMPLATE ) ;
NK_ASSERT ( layout - > row . columns < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS ) ;
if ( layout - > row . type ! = NK_LAYOUT_TEMPLATE ) return ;
if ( layout - > row . columns > = NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS ) return ;
layout - > row . templates [ layout - > row . columns + + ] = - 1.0f ;
}
NK_API void
nk_layout_row_template_push_variable ( struct nk_context * ctx , float min_width )
{
struct nk_window * win ;
struct nk_panel * layout ;
NK_ASSERT ( ctx ) ;
NK_ASSERT ( ctx - > current ) ;
NK_ASSERT ( ctx - > current - > layout ) ;
if ( ! ctx | | ! ctx - > current | | ! ctx - > current - > layout )
return ;
win = ctx - > current ;
layout = win - > layout ;
NK_ASSERT ( layout - > row . type = = NK_LAYOUT_TEMPLATE ) ;
NK_ASSERT ( layout - > row . columns < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS ) ;
if ( layout - > row . type ! = NK_LAYOUT_TEMPLATE ) return ;
if ( layout - > row . columns > = NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS ) return ;
layout - > row . templates [ layout - > row . columns + + ] = - min_width ;
}
NK_API void
nk_layout_row_template_push_static ( struct nk_context * ctx , float width )
{
struct nk_window * win ;
struct nk_panel * layout ;
NK_ASSERT ( ctx ) ;
NK_ASSERT ( ctx - > current ) ;
NK_ASSERT ( ctx - > current - > layout ) ;
if ( ! ctx | | ! ctx - > current | | ! ctx - > current - > layout )
return ;
win = ctx - > current ;
layout = win - > layout ;
NK_ASSERT ( layout - > row . type = = NK_LAYOUT_TEMPLATE ) ;
NK_ASSERT ( layout - > row . columns < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS ) ;
if ( layout - > row . type ! = NK_LAYOUT_TEMPLATE ) return ;
if ( layout - > row . columns > = NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS ) return ;
layout - > row . templates [ layout - > row . columns + + ] = width ;
}
NK_API void
nk_layout_row_template_end ( struct nk_context * ctx )
{
struct nk_window * win ;
struct nk_panel * layout ;
int i = 0 ;
int variable_count = 0 ;
int min_variable_count = 0 ;
float min_fixed_width = 0.0f ;
float total_fixed_width = 0.0f ;
float max_variable_width = 0.0f ;
NK_ASSERT ( ctx ) ;
NK_ASSERT ( ctx - > current ) ;
NK_ASSERT ( ctx - > current - > layout ) ;
if ( ! ctx | | ! ctx - > current | | ! ctx - > current - > layout )
return ;
win = ctx - > current ;
layout = win - > layout ;
NK_ASSERT ( layout - > row . type = = NK_LAYOUT_TEMPLATE ) ;
if ( layout - > row . type ! = NK_LAYOUT_TEMPLATE ) return ;
for ( i = 0 ; i < layout - > row . columns ; + + i ) {
float width = layout - > row . templates [ i ] ;
if ( width > = 0.0f ) {
total_fixed_width + = width ;
min_fixed_width + = width ;
} else if ( width < - 1.0f ) {
width = - width ;
total_fixed_width + = width ;
max_variable_width = NK_MAX ( max_variable_width , width ) ;
variable_count + + ;
} else {
min_variable_count + + ;
variable_count + + ;
}
}
if ( variable_count ) {
float space = nk_layout_row_calculate_usable_space ( & ctx - > style , layout - > type ,
layout - > bounds . w , layout - > row . columns ) ;
float var_width = ( NK_MAX ( space - min_fixed_width , 0.0f ) ) / ( float ) variable_count ;
int enough_space = var_width > = max_variable_width ;
if ( ! enough_space )
var_width = ( NK_MAX ( space - total_fixed_width , 0 ) ) / ( float ) min_variable_count ;
for ( i = 0 ; i < layout - > row . columns ; + + i ) {
float * width = & layout - > row . templates [ i ] ;
* width = ( * width > = 0.0f ) ? * width : ( * width < - 1.0f & & ! enough_space ) ? - ( * width ) : var_width ;
}
}
}
NK_API void
NK_API void
nk_layout_space_begin ( struct nk_context * ctx , enum nk_layout_format fmt ,
nk_layout_space_begin ( struct nk_context * ctx , enum nk_layout_format fmt ,
float height , int widget_count )
float height , int widget_count )
@ -18101,8 +18315,8 @@ nk_layout_space_to_screen(struct nk_context *ctx, struct nk_vec2 ret)
win = ctx - > current ;
win = ctx - > current ;
layout = win - > layout ;
layout = win - > layout ;
ret . x + = layout - > at_x - * layout - > offset_x ;
ret . x + = layout - > at_x - ( float ) * layout - > offset_x ;
ret . y + = layout - > at_y - * layout - > offset_y ;
ret . y + = layout - > at_y - ( float ) * layout - > offset_y ;
return ret ;
return ret ;
}
}
@ -18118,8 +18332,8 @@ nk_layout_space_to_local(struct nk_context *ctx, struct nk_vec2 ret)
win = ctx - > current ;
win = ctx - > current ;
layout = win - > layout ;
layout = win - > layout ;
ret . x + = - layout - > at_x + * layout - > offset_x ;
ret . x + = - layout - > at_x + ( float ) * layout - > offset_x ;
ret . y + = - layout - > at_y + * layout - > offset_y ;
ret . y + = - layout - > at_y + ( float ) * layout - > offset_y ;
return ret ;
return ret ;
}
}
@ -18135,8 +18349,8 @@ nk_layout_space_rect_to_screen(struct nk_context *ctx, struct nk_rect ret)
win = ctx - > current ;
win = ctx - > current ;
layout = win - > layout ;
layout = win - > layout ;
ret . x + = layout - > at_x - * layout - > offset_x ;
ret . x + = layout - > at_x - ( float ) * layout - > offset_x ;
ret . y + = layout - > at_y - * layout - > offset_y ;
ret . y + = layout - > at_y - ( float ) * layout - > offset_y ;
return ret ;
return ret ;
}
}
@ -18152,8 +18366,8 @@ nk_layout_space_rect_to_local(struct nk_context *ctx, struct nk_rect ret)
win = ctx - > current ;
win = ctx - > current ;
layout = win - > layout ;
layout = win - > layout ;
ret . x + = - layout - > at_x + * layout - > offset_x ;
ret . x + = - layout - > at_x + ( float ) * layout - > offset_x ;
ret . y + = - layout - > at_y + * layout - > offset_y ;
ret . y + = - layout - > at_y + ( float ) * layout - > offset_y ;
return ret ;
return ret ;
}
}
@ -18173,16 +18387,13 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
struct nk_panel * layout ;
struct nk_panel * layout ;
const struct nk_style * style ;
const struct nk_style * style ;
struct nk_vec2 spacing ;
struct nk_vec2 padding ;
float item_offset = 0 ;
float item_offset = 0 ;
float item_width = 0 ;
float item_width = 0 ;
float item_spacing = 0 ;
float item_spacing = 0 ;
float panel_space = 0 ;
float panel_padding ;
float panel_spacing ;
float panel_space ;
struct nk_vec2 spacing ;
struct nk_vec2 padding ;
NK_ASSERT ( ctx ) ;
NK_ASSERT ( ctx ) ;
NK_ASSERT ( ctx - > current ) ;
NK_ASSERT ( ctx - > current ) ;
@ -18191,18 +18402,14 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
return ;
return ;
win = ctx - > current ;
win = ctx - > current ;
style = & ctx - > style ;
layout = win - > layout ;
layout = win - > layout ;
style = & ctx - > style ;
NK_ASSERT ( bounds ) ;
NK_ASSERT ( bounds ) ;
/* cache some configuration data */
spacing = style - > window . spacing ;
spacing = ctx - > style . window . spacing ;
padding = nk_panel_get_padding ( style , layout - > type ) ;
padding = nk_panel_get_padding ( style , layout - > type ) ;
panel_space = nk_layout_row_calculate_usable_space ( & ctx - > style , layout - > type ,
/* calculate the usable panel space */
layout - > bounds . w , layout - > row . columns ) ;
panel_padding = 2 * padding . x ;
panel_spacing = ( float ) ( layout - > row . columns - 1 ) * spacing . x ;
panel_space = layout - > bounds . w - panel_padding - panel_spacing ;
/* calculate the width of one item inside the current layout space */
/* calculate the width of one item inside the current layout space */
switch ( layout - > row . type ) {
switch ( layout - > row . type ) {
@ -18227,13 +18434,13 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
case NK_LAYOUT_DYNAMIC_FREE : {
case NK_LAYOUT_DYNAMIC_FREE : {
/* panel width depended free widget placing */
/* panel width depended free widget placing */
bounds - > x = layout - > at_x + ( layout - > bounds . w * layout - > row . item . x ) ;
bounds - > x = layout - > at_x + ( layout - > bounds . w * layout - > row . item . x ) ;
bounds - > x - = * layout - > offset_x ;
bounds - > x - = ( float ) * layout - > offset_x ;
bounds - > y = layout - > at_y + ( layout - > row . height * layout - > row . item . y ) ;
bounds - > y = layout - > at_y + ( layout - > row . height * layout - > row . item . y ) ;
bounds - > y - = * layout - > offset_y ;
bounds - > y - = ( float ) * layout - > offset_y ;
bounds - > w = layout - > bounds . w * layout - > row . item . w ;
bounds - > w = layout - > bounds . w * layout - > row . item . w ;
bounds - > h = layout - > row . height * layout - > row . item . h ;
bounds - > h = layout - > row . height * layout - > row . item . h ;
return ;
return ;
} ;
} break ;
case NK_LAYOUT_DYNAMIC : {
case NK_LAYOUT_DYNAMIC : {
/* scaling arrays of panel width ratios for every widget */
/* scaling arrays of panel width ratios for every widget */
float ratio ;
float ratio ;
@ -18269,12 +18476,12 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
bounds - > w = layout - > row . item . w ;
bounds - > w = layout - > row . item . w ;
if ( ( ( bounds - > x + bounds - > w ) > layout - > max_x ) & & modify )
if ( ( ( bounds - > x + bounds - > w ) > layout - > max_x ) & & modify )
layout - > max_x = ( bounds - > x + bounds - > w ) ;
layout - > max_x = ( bounds - > x + bounds - > w ) ;
bounds - > x - = * layout - > offset_x ;
bounds - > x - = ( float ) * layout - > offset_x ;
bounds - > y = layout - > at_y + layout - > row . item . y ;
bounds - > y = layout - > at_y + layout - > row . item . y ;
bounds - > y - = * layout - > offset_y ;
bounds - > y - = ( float ) * layout - > offset_y ;
bounds - > h = layout - > row . item . h ;
bounds - > h = layout - > row . item . h ;
return ;
return ;
} ;
} break ;
case NK_LAYOUT_STATIC : {
case NK_LAYOUT_STATIC : {
/* non-scaling array of panel pixel width for every widget */
/* non-scaling array of panel pixel width for every widget */
item_spacing = ( float ) layout - > row . index * spacing . x ;
item_spacing = ( float ) layout - > row . index * spacing . x ;
@ -18282,17 +18489,26 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
item_offset = layout - > row . item_offset ;
item_offset = layout - > row . item_offset ;
if ( modify ) layout - > row . item_offset + = item_width ;
if ( modify ) layout - > row . item_offset + = item_width ;
} break ;
} break ;
case NK_LAYOUT_TEMPLATE : {
/* stretchy row layout with combined dynamic/static widget width*/
NK_ASSERT ( layout - > row . index < layout - > row . columns ) ;
NK_ASSERT ( layout - > row . index < NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS ) ;
item_width = layout - > row . templates [ layout - > row . index ] ;
item_offset = layout - > row . item_offset ;
item_spacing = ( float ) layout - > row . index * spacing . x ;
if ( modify ) layout - > row . item_offset + = item_width ;
} break ;
default : NK_ASSERT ( 0 ) ; break ;
default : NK_ASSERT ( 0 ) ; break ;
} ;
} ;
/* set the bounds of the newly allocated widget */
/* set the bounds of the newly allocated widget */
bounds - > w = item_width ;
bounds - > w = item_width ;
bounds - > h = layout - > row . height - spacing . y ;
bounds - > h = layout - > row . height - spacing . y ;
bounds - > y = layout - > at_y - * layout - > offset_y ;
bounds - > y = layout - > at_y - ( float ) * layout - > offset_y ;
bounds - > x = layout - > at_x + item_offset + item_spacing + padding . x ;
bounds - > x = layout - > at_x + item_offset + item_spacing + padding . x ;
if ( ( ( bounds - > x + bounds - > w ) > layout - > max_x ) & & modify )
if ( ( ( bounds - > x + bounds - > w ) > layout - > max_x ) & & modify )
layout - > max_x = bounds - > x + bounds - > w ;
layout - > max_x = bounds - > x + bounds - > w ;
bounds - > x - = * layout - > offset_x ;
bounds - > x - = ( float ) * layout - > offset_x ;
}
}
NK_INTERN void
NK_INTERN void
@ -18441,7 +18657,7 @@ nk_tree_state_base(struct nk_context *ctx, enum nk_tree_type type,
/* increase x-axis cursor widget position pointer */
/* increase x-axis cursor widget position pointer */
if ( * state = = NK_MAXIMIZED ) {
if ( * state = = NK_MAXIMIZED ) {
layout - > at_x = header . x + * layout - > offset_x + style - > tab . indent ;
layout - > at_x = header . x + ( float ) * layout - > offset_x + style - > tab . indent ;
layout - > bounds . w = NK_MAX ( layout - > bounds . w , style - > tab . indent ) ;
layout - > bounds . w = NK_MAX ( layout - > bounds . w , style - > tab . indent ) ;
layout - > bounds . w - = ( style - > tab . indent + style - > window . padding . x ) ;
layout - > bounds . w - = ( style - > tab . indent + style - > window . padding . x ) ;
layout - > row . tree_depth + + ;
layout - > row . tree_depth + + ;
@ -19602,6 +19818,19 @@ nk_edit_focus(struct nk_context *ctx, nk_flags flags)
win - > edit . mode = NK_TEXT_EDIT_MODE_INSERT ;
win - > edit . mode = NK_TEXT_EDIT_MODE_INSERT ;
}
}
NK_API void
nk_edit_unfocus ( struct nk_context * ctx )
{
struct nk_window * win ;
NK_ASSERT ( ctx ) ;
NK_ASSERT ( ctx - > current ) ;
if ( ! ctx | | ! ctx - > current ) return ;
win = ctx - > current ;
win - > edit . active = nk_false ;
win - > edit . name = 0 ;
}
NK_API nk_flags
NK_API nk_flags
nk_edit_string ( struct nk_context * ctx , nk_flags flags ,
nk_edit_string ( struct nk_context * ctx , nk_flags flags ,
char * memory , int * len , int max , nk_plugin_filter filter )
char * memory , int * len , int max , nk_plugin_filter filter )
@ -20349,7 +20578,6 @@ nk_group_scrolled_offset_begin(struct nk_context *ctx,
win - > layout = panel . layout ;
win - > layout = panel . layout ;
ctx - > current = win ;
ctx - > current = win ;
return 1 ;
return 1 ;
}
}
NK_API void
NK_API void
@ -20504,7 +20732,7 @@ nk_list_view_begin(struct nk_context *ctx, struct nk_list_view *view,
layout = win - > layout ;
layout = win - > layout ;
view - > total_height = row_height * NK_MAX ( row_count , 1 ) ;
view - > total_height = row_height * NK_MAX ( row_count , 1 ) ;
view - > begin = ( int ) NK_MAX ( ( view - > scroll_value / ( float ) row_height ) , 0.0f ) ;
view - > begin = ( int ) NK_MAX ( ( ( float ) view - > scroll_value / ( float ) row_height ) , 0.0f ) ;
view - > count = ( int ) NK_MAX ( nk_iceilf ( ( layout - > clip . h ) / ( float ) row_height ) , 0 ) ;
view - > count = ( int ) NK_MAX ( nk_iceilf ( ( layout - > clip . h ) / ( float ) row_height ) , 0 ) ;
view - > end = view - > begin + view - > count ;
view - > end = view - > begin + view - > count ;
view - > ctx = ctx ;
view - > ctx = ctx ;
@ -20558,6 +20786,7 @@ nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type,
win = ctx - > current ;
win = ctx - > current ;
panel = win - > layout ;
panel = win - > layout ;
NK_ASSERT ( ! ( panel - > type & NK_PANEL_SET_POPUP ) & & " popups are not allowed to have popups " ) ;
NK_ASSERT ( ! ( panel - > type & NK_PANEL_SET_POPUP ) & & " popups are not allowed to have popups " ) ;
( void ) panel ;
title_len = ( int ) nk_strlen ( title ) ;
title_len = ( int ) nk_strlen ( title ) ;
title_hash = nk_murmur_hash ( title , ( int ) title_len , NK_PANEL_POPUP ) ;
title_hash = nk_murmur_hash ( title , ( int ) title_len , NK_PANEL_POPUP ) ;
@ -20652,6 +20881,7 @@ nk_nonblock_begin(struct nk_context *ctx,
win = ctx - > current ;
win = ctx - > current ;
panel = win - > layout ;
panel = win - > layout ;
NK_ASSERT ( ! ( panel - > type & NK_PANEL_SET_POPUP ) ) ;
NK_ASSERT ( ! ( panel - > type & NK_PANEL_SET_POPUP ) ) ;
( void ) panel ;
popup = win - > popup . win ;
popup = win - > popup . win ;
if ( ! popup ) {
if ( ! popup ) {
/* create window for nonblocking popup */
/* create window for nonblocking popup */