Skip to content

Commit

Permalink
Fixed non-blocking popup closing behavior
Browse files Browse the repository at this point in the history
This is a breaking change which fixes bad closing behavior in
non-blocking popups. If the maximum size of a non-blocking popup was
not reached and you clicked to close the popup under it could happen
that it wouldn't be closed. This is now fixed in combination with
more popup control by allowing to set both the maximum height as
well as popup width.
  • Loading branch information
vurtun committed Sep 15, 2016
1 parent 2a888b3 commit 85d109e
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 104 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

- 2016/09/13 (1.15) - !BREAKING! Fixed nonblocking popup behavior in menu, combo,
and contextual which prevented closing in y-direction if
popup did not reach max height.
In addition the height parameter was changed into vec2
for width and height to have more control over the popup size.
- 2016/09/13 (1.15) - Cleaned up and extended type selection
- 2016/09/13 (1.141)- Fixed slider behavior hopefully for the last time. This time
all calculation are correct so no more hackery.
- 2016/09/13 (1.141)- Internal change to divide window/panel flags into panel flags and types.
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Java: https://github.com/glegris/nuklear4j
Developed by Micha Mettke and every direct or indirect contributor to the GitHub.
Embeds `stb_texedit`, `stb_truetype` and `stb_rectpack` by Sean Barret (public domain)
Embeds `stb_texedit`, `stb_truetype` and `stb_rectpack` by Sean Barret (public domain)
Embeds `ProggyClean.ttf` font by Tristan Grimmer (MIT license).
Expand Down
21 changes: 10 additions & 11 deletions demo/overview.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ overview(struct nk_context *ctx)
nk_menubar_begin(ctx);
nk_layout_row_begin(ctx, NK_STATIC, 25, 2);
nk_layout_row_push(ctx, 45);
if (nk_menu_begin_label(ctx, &menu, "MENU", NK_TEXT_LEFT, 120))
if (nk_menu_begin_label(ctx, &menu, "MENU", NK_TEXT_LEFT, nk_vec2(120, 200)))
{
static size_t prog = 40;
static int slider = 10;
Expand Down Expand Up @@ -276,10 +276,10 @@ overview(struct nk_context *ctx)

/* default combobox */
nk_layout_row_static(ctx, 25, 200, 1);
current_weapon = nk_combo(ctx, weapons, LEN(weapons), current_weapon, 25, 200);
current_weapon = nk_combo(ctx, weapons, LEN(weapons), current_weapon, 25, nk_vec2(200,200));

/* slider color combobox */
if (nk_combo_begin_color(ctx, &combo, combo_color, 200)) {
if (nk_combo_begin_color(ctx, &combo, combo_color, nk_vec2(200,200))) {
float ratios[] = {0.15f, 0.85f};
nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratios);
nk_label(ctx, "R:", NK_TEXT_LEFT);
Expand All @@ -294,7 +294,7 @@ overview(struct nk_context *ctx)
}

/* complex color combobox */
if (nk_combo_begin_color(ctx, &combo, combo_color2, 400)) {
if (nk_combo_begin_color(ctx, &combo, combo_color2, nk_vec2(200,400))) {
enum color_mode {COL_RGB, COL_HSV};
static int col_mode = COL_RGB;
#ifndef DEMO_DO_NOT_USE_COLOR_PICKER
Expand Down Expand Up @@ -327,7 +327,7 @@ overview(struct nk_context *ctx)
/* progressbar combobox */
sum = prog_a + prog_b + prog_c + prog_d;
sprintf(buffer, "%lu", sum);
if (nk_combo_begin_label(ctx, &combo, buffer, 200)) {
if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,200))) {
nk_layout_row_dynamic(ctx, 30, 1);
nk_progress(ctx, &prog_a, 100, NK_MODIFIABLE);
nk_progress(ctx, &prog_b, 100, NK_MODIFIABLE);
Expand All @@ -339,7 +339,7 @@ overview(struct nk_context *ctx)
/* checkbox combobox */
sum = (size_t)(check_values[0] + check_values[1] + check_values[2] + check_values[3] + check_values[4]);
sprintf(buffer, "%lu", sum);
if (nk_combo_begin_label(ctx, &combo, buffer, 200)) {
if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,200))) {
nk_layout_row_dynamic(ctx, 30, 1);
nk_checkbox_label(ctx, weapons[0], &check_values[0]);
nk_checkbox_label(ctx, weapons[1], &check_values[1]);
Expand All @@ -350,7 +350,7 @@ overview(struct nk_context *ctx)

/* complex text combobox */
sprintf(buffer, "%.2f, %.2f, %.2f", position[0], position[1],position[2]);
if (nk_combo_begin_label(ctx, &combo, buffer, 200)) {
if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,200))) {
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_float(ctx, "#X:", -1024.0f, &position[0], 1024.0f, 1,0.5f);
nk_property_float(ctx, "#Y:", -1024.0f, &position[1], 1024.0f, 1,0.5f);
Expand All @@ -360,7 +360,7 @@ overview(struct nk_context *ctx)

/* chart combobox */
sprintf(buffer, "%.1f", chart_selection);
if (nk_combo_begin_label(ctx, &combo, buffer, 250)) {
if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,250))) {
size_t i = 0;
static const float values[]={26.0f,13.0f,30.0f,15.0f,25.0f,10.0f,20.0f,40.0f, 12.0f, 8.0f, 22.0f, 28.0f, 5.0f};
nk_layout_row_dynamic(ctx, 150, 1);
Expand Down Expand Up @@ -393,7 +393,7 @@ overview(struct nk_context *ctx)

/* time combobox */
sprintf(buffer, "%02d:%02d:%02d", sel_time.tm_hour, sel_time.tm_min, sel_time.tm_sec);
if (nk_combo_begin_label(ctx, &combo, buffer, 250)) {
if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(200,250))) {
time_selected = 1;
nk_layout_row_dynamic(ctx, 25, 1);
sel_time.tm_sec = nk_propertyi(ctx, "#S:", 0, sel_time.tm_sec, 60, 1, 1);
Expand All @@ -403,9 +403,8 @@ overview(struct nk_context *ctx)
}

/* date combobox */
nk_layout_row_static(ctx, 25, 350, 1);
sprintf(buffer, "%02d-%02d-%02d", sel_date.tm_mday, sel_date.tm_mon+1, sel_date.tm_year+1900);
if (nk_combo_begin_label(ctx, &combo, buffer, 400))
if (nk_combo_begin_label(ctx, &combo, buffer, nk_vec2(350,400)))
{
int i = 0;
const char *month[] = {"January", "February", "March", "Apil", "May", "June", "July", "August", "September", "Ocotober", "November", "December"};
Expand Down
9 changes: 4 additions & 5 deletions example/extended.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ grid_demo(struct nk_context *ctx, struct media *media)
nk_label(ctx, "Checkbox:", NK_TEXT_RIGHT);
nk_checkbox_label(ctx, "Check me", &check);
nk_label(ctx, "Combobox:", NK_TEXT_RIGHT);

if (nk_combo_begin_label(ctx, &combo, items[selected_item], 200)) {
if (nk_combo_begin_label(ctx, &combo, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) {
nk_layout_row_dynamic(ctx, 25, 1);
for (i = 0; i < 3; ++i)
if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT))
Expand Down Expand Up @@ -272,7 +271,7 @@ button_demo(struct nk_context *ctx, struct media *media)
{
/* toolbar */
nk_layout_row_static(ctx, 40, 40, 4);
if (nk_menu_begin_image(ctx, &menu, "Music", media->play, 120))
if (nk_menu_begin_image(ctx, &menu, "Music", media->play, nk_vec2(110,120)))
{
/* settings */
nk_layout_row_dynamic(ctx, 25, 1);
Expand Down Expand Up @@ -421,7 +420,7 @@ basic_demo(struct nk_context *ctx, struct media *media)
*------------------------------------------------*/
ui_header(ctx, media, "Combo box");
ui_widget(ctx, media, 40);
if (nk_combo_begin_label(ctx, &combo, items[selected_item], 200)) {
if (nk_combo_begin_label(ctx, &combo, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) {
nk_layout_row_dynamic(ctx, 35, 1);
for (i = 0; i < 3; ++i)
if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT))
Expand All @@ -430,7 +429,7 @@ basic_demo(struct nk_context *ctx, struct media *media)
}

ui_widget(ctx, media, 40);
if (nk_combo_begin_image_label(ctx, &combo, items[selected_icon], media->images[selected_icon], 200)) {
if (nk_combo_begin_image_label(ctx, &combo, items[selected_icon], media->images[selected_icon], nk_vec2(nk_widget_width(ctx), 200))) {
nk_layout_row_dynamic(ctx, 35, 1);
for (i = 0; i < 3; ++i)
if (nk_combo_item_image_label(ctx, media->images[i], items[i], NK_TEXT_RIGHT))
Expand Down
2 changes: 1 addition & 1 deletion example/skinning.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ int main(int argc, char *argv[])
nk_layout_row_dynamic(&ctx, 25, 1);
nk_edit_string(&ctx, NK_EDIT_FIELD, field_buffer, &field_len, 64, nk_filter_default);
nk_property_float(&ctx, "#X:", -1024.0f, &pos, 1024.0f, 1, 1);
current_weapon = nk_combo(&ctx, weapons, LEN(weapons), current_weapon, 25, 200);
current_weapon = nk_combo(&ctx, weapons, LEN(weapons), current_weapon, 25, nk_vec2(nk_widget_width(&ctx),200));

nk_layout_row_dynamic(&ctx, 100, 1);
if (nk_chart_begin_colored(&ctx, NK_CHART_LINES, nk_rgb(255,0,0), nk_rgb(150,0,0), 32, 0.0f, 1.0f)) {
Expand Down
Loading

0 comments on commit 85d109e

Please sign in to comment.