Merged #198 with bottom-left corner scaler

This commit is contained in:
vurtun 2017-01-14 15:22:22 +01:00
parent be7ac9b903
commit 34d0fcd43d
4 changed files with 33 additions and 12 deletions

View File

@ -1,5 +1,6 @@
# Changelog
- 2016/01/11 (1.21) - Added additional row layouting method to combine both
- 2017/01/11 (1.22) - Added flag to put scaler into the bottom left corner
- 2017/01/11 (1.21) - Added additional row layouting method to combine both
dynamic and static widgets.
- 2016/12/31 (1.20) - Extended scrollbar offset from 16-bit to 32-bit
- 2016/12/31 (1.192)- Fixed closing window bug of minimized windows

View File

@ -9,6 +9,7 @@ overview(struct nk_context *ctx)
static int resize = nk_true;
static int movable = nk_true;
static int no_scrollbar = nk_false;
static int scale_left = nk_false;
static nk_flags window_flags = 0;
static int minimizable = nk_true;
@ -23,6 +24,7 @@ overview(struct nk_context *ctx)
if (resize) window_flags |= NK_WINDOW_SCALABLE;
if (movable) window_flags |= NK_WINDOW_MOVABLE;
if (no_scrollbar) window_flags |= NK_WINDOW_NO_SCROLLBAR;
if (scale_left) window_flags |= NK_WINDOW_SCALE_LEFT;
if (minimizable) window_flags |= NK_WINDOW_MINIMIZABLE;
if (nk_begin(ctx, "Overview", nk_rect(10, 10, 400, 600), window_flags))
@ -84,6 +86,7 @@ overview(struct nk_context *ctx)
nk_checkbox_label(ctx, "Movable", &movable);
nk_checkbox_label(ctx, "No Scrollbar", &no_scrollbar);
nk_checkbox_label(ctx, "Minimizable", &minimizable);
nk_checkbox_label(ctx, "Scale Left", &scale_left);
nk_tree_pop(ctx);
}

View File

@ -91,8 +91,8 @@ sleep_for(long t)
* and the corresponding function. */
/*#include "../style.c"*/
/*#include "../calculator.c"*/
#include "../overview.c"
#include "../node_editor.c"
/*#include "../overview.c"*/
/*#include "../node_editor.c"*/
/* ===============================================================
*
@ -157,7 +157,8 @@ main(void)
/* GUI */
if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
NK_WINDOW_CLOSABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE|
NK_WINDOW_SCALE_LEFT))
{
enum {EASY, HARD};
static int op = EASY;
@ -177,8 +178,8 @@ main(void)
/* -------------- EXAMPLES ---------------- */
/*calculator(ctx);*/
overview(ctx);
node_editor(ctx);
/*overview(ctx);*/
/*node_editor(ctx);*/
/* ----------------------------------------- */
/* Draw */

View File

@ -688,7 +688,8 @@ enum nk_panel_flags {
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_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 */
@ -16824,7 +16825,9 @@ nk_panel_end(struct nk_context *ctx)
scaler.w = scrollbar_size.x;
scaler.h = scrollbar_size.y;
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)
scaler.x -= scaler.w;
@ -16832,9 +16835,16 @@ nk_panel_end(struct nk_context *ctx)
{const struct nk_style_item *item = &style->window.scaler;
if (item->type == NK_STYLE_ITEM_IMAGE)
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,
scaler.y + scaler.h, scaler.x, scaler.y + scaler.h, item->data.color);
}
else {
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 */
if (!(window->flags & NK_WINDOW_ROM)) {
@ -16844,7 +16854,13 @@ nk_panel_end(struct nk_context *ctx)
NK_BUTTON_LEFT, scaler, nk_true);
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 */
if (!(layout->flags & NK_WINDOW_DYNAMIC))
window->bounds.h = NK_MAX(window_size.y, window->bounds.h + in->mouse.delta.y);