public static bool ToggleBehavior(nk_input _in_, RectangleF select, ref uint state, bool active) { if ((state & NK_WIDGET_STATE_MODIFIED) != 0) { state = NK_WIDGET_STATE_INACTIVE | NK_WIDGET_STATE_MODIFIED; } else { state = NK_WIDGET_STATE_INACTIVE; } if (ButtonBehavior(ref state, select, _in_, NK_BUTTON_DEFAULT)) { state = NK_WIDGET_STATE_ACTIVE; active = !active; } if ((state & NK_WIDGET_STATE_HOVER) != 0 && !nk_input_is_mouse_prev_hovering_rect(_in_, select)) { state |= NK_WIDGET_STATE_ENTERED; } else if (nk_input_is_mouse_prev_hovering_rect(_in_, select)) { state |= NK_WIDGET_STATE_LEFT; } return(active); }
public static bool DoToggle(ref uint state, CommandBuffer _out_, RectangleF r, ref bool active, string str, int type, nk_style_toggle style, nk_input _in_, nk_font font) { bool was_active; var bounds = new RectangleF(); var select = new RectangleF(); var cursor = new RectangleF(); var label = new RectangleF(); if (_out_ == null || style == null || font == null || active == null) { return(false); } r.Width = r.Width < font.Size + 2 * style.padding.X ? font.Size + 2 * style.padding.X : r.Width; r.Height = r.Height < font.Size + 2 * style.padding.Y ? font.Size + 2 * style.padding.Y : r.Height; bounds.X = r.X - style.touch_padding.X; bounds.Y = r.Y - style.touch_padding.Y; bounds.Width = r.Width + 2 * style.touch_padding.X; bounds.Height = r.Height + 2 * style.touch_padding.Y; select.Width = font.Size; select.Height = select.Width; select.Y = r.Y + r.Height / 2.0f - select.Height / 2.0f; select.X = r.X; cursor.X = select.X + style.padding.X + style.border; cursor.Y = select.Y + style.padding.Y + style.border; cursor.Width = select.Width - (2 * style.padding.X + 2 * style.border); cursor.Height = select.Height - (2 * style.padding.Y + 2 * style.border); label.X = select.X + select.Width + style.spacing; label.Y = select.Y; label.Width = (r.X + r.Width < label.X ? label.X : r.X + r.Width) - label.X; label.Height = select.Width; was_active = active; active = ToggleBehavior(_in_, bounds, ref state, active); if (style.draw_begin != null) { style.draw_begin(_out_); } if (type == NK_TOGGLE_CHECK) { _out_.DrawCheckBox(state, style, active, &label, &select, &cursor, str, font); } else { _out_.DrawOption(state, style, active, &label, &select, &cursor, str, font); } if (style.draw_end != null) { style.draw_end(_out_); } return(was_active != active); }
public static float nk_scrollbar_behavior(ref uint state, nk_input _in_, bool has_scrolling, RectangleF *scroll, ref RectangleF cursor, RectangleF *empty0, RectangleF *empty1, float scroll_offset, float target, float scroll_step, int o) { var ws = (uint)0; bool left_mouse_down; bool left_mouse_click_in_cursor; float scroll_delta; if ((state & NK_WIDGET_STATE_MODIFIED) != 0) { state = NK_WIDGET_STATE_INACTIVE | NK_WIDGET_STATE_MODIFIED; } else { state = NK_WIDGET_STATE_INACTIVE; } if (_in_ == null) { return(scroll_offset); } left_mouse_down = _in_.mouse.buttons[NK_BUTTON_LEFT].down; left_mouse_click_in_cursor = nk_input_has_mouse_click_down_in_rect(_in_, NK_BUTTON_LEFT, cursor, true); if (nk_input_is_mouse_hovering_rect(_in_, *scroll)) { state = NK_WIDGET_STATE_HOVERED; } scroll_delta = o == NK_VERTICAL ? _in_.mouse.scroll_delta.Y : _in_.mouse.scroll_delta.X; if (left_mouse_down && left_mouse_click_in_cursor) { float pixel; float delta; state = NK_WIDGET_STATE_ACTIVE; if (o == NK_VERTICAL) { float cursor_y; pixel = _in_.mouse.delta.Y; delta = pixel / scroll->Height * target; scroll_offset = (scroll_offset + delta < target - scroll->Height ? scroll_offset + delta : target - scroll->Height) < 0 ? 0 : scroll_offset + delta < target - scroll->Height ? scroll_offset + delta : target - scroll->Height; cursor_y = scroll->Y + scroll_offset / target * scroll->Height; _in_.mouse.buttons[NK_BUTTON_LEFT].clicked_pos.Y = cursor_y + cursor.Height / 2.0f; } else { float cursor_x; pixel = _in_.mouse.delta.X; delta = pixel / scroll->Width * target; scroll_offset = (scroll_offset + delta < target - scroll->Width ? scroll_offset + delta : target - scroll->Width) < 0 ? 0 : scroll_offset + delta < target - scroll->Width ? scroll_offset + delta : target - scroll->Width; cursor_x = scroll->X + scroll_offset / target * scroll->Width; _in_.mouse.buttons[NK_BUTTON_LEFT].clicked_pos.X = cursor_x + cursor.Width / 2.0f; } } else if (nk_input_is_key_pressed(_in_, NK_KEY_SCROLL_UP) && o == NK_VERTICAL && has_scrolling || ButtonBehavior(ref ws, *empty0, _in_, NK_BUTTON_DEFAULT)) { if (o == NK_VERTICAL) { scroll_offset = 0 < scroll_offset - scroll->Height ? scroll_offset - scroll->Height : 0; } else { scroll_offset = 0 < scroll_offset - scroll->Width ? scroll_offset - scroll->Width : 0; } } else if (nk_input_is_key_pressed(_in_, NK_KEY_SCROLL_DOWN) && o == NK_VERTICAL && has_scrolling || ButtonBehavior(ref ws, *empty1, _in_, NK_BUTTON_DEFAULT)) { if (o == NK_VERTICAL) { scroll_offset = scroll_offset + scroll->Height < target - scroll->Height ? scroll_offset + scroll->Height : target - scroll->Height; } else { scroll_offset = scroll_offset + scroll->Width < target - scroll->Width ? scroll_offset + scroll->Width : target - scroll->Width; } } else if (has_scrolling) { if (scroll_delta < 0 || scroll_delta > 0) { scroll_offset = scroll_offset + scroll_step * -scroll_delta; if (o == NK_VERTICAL) { scroll_offset = (scroll_offset < target - scroll->Height ? scroll_offset : target - scroll->Height) < 0 ? 0 : scroll_offset < target - scroll->Height ? scroll_offset : target - scroll->Height; } else { scroll_offset = (scroll_offset < target - scroll->Width ? scroll_offset : target - scroll->Width) < 0 ? 0 : scroll_offset < target - scroll->Width ? scroll_offset : target - scroll->Width; } } else if (nk_input_is_key_pressed(_in_, NK_KEY_SCROLL_START)) { if (o == NK_VERTICAL) { scroll_offset = 0; } } else if (nk_input_is_key_pressed(_in_, NK_KEY_SCROLL_END)) { if (o == NK_VERTICAL) { scroll_offset = target - scroll->Height; } } } if ((state & NK_WIDGET_STATE_HOVER) != 0 && !nk_input_is_mouse_prev_hovering_rect(_in_, *scroll)) { state |= NK_WIDGET_STATE_ENTERED; } else if (nk_input_is_mouse_prev_hovering_rect(_in_, *scroll)) { state |= NK_WIDGET_STATE_LEFT; } return(scroll_offset); }
public static float nk_do_scrollbarh(ref uint state, CommandBuffer _out_, RectangleF scroll, bool has_scrolling, float offset, float target, float step, float button_pixel_inc, nk_style_scrollbar style, nk_input _in_, nk_font font) { var cursor = new RectangleF(); var empty_west = new RectangleF(); var empty_east = new RectangleF(); float scroll_step; float scroll_offset; float scroll_off; float scroll_ratio; if (_out_ == null || style == null) { return(0); } scroll.Height = scroll.Height < 1 ? 1 : scroll.Height; scroll.Width = scroll.Width < 2 * scroll.Height ? 2 * scroll.Height : scroll.Width; if (target <= scroll.Width) { return(0); } if (style.show_buttons != 0) { uint ws = 0; float scroll_w; var button = new RectangleF(); button.Y = scroll.Y; button.Width = scroll.Height; button.Height = scroll.Height; scroll_w = scroll.Width - 2 * button.Width; scroll_step = step < button_pixel_inc ? step : button_pixel_inc; button.X = scroll.X; if ( DoButtonSymbol(ref ws, _out_, button, style.dec_symbol, NK_BUTTON_REPEATER, style.dec_button, _in_, font)) { offset = offset - scroll_step; } button.X = scroll.X + scroll.Width - button.Width; if ( DoButtonSymbol(ref ws, _out_, button, style.inc_symbol, NK_BUTTON_REPEATER, style.inc_button, _in_, font)) { offset = offset + scroll_step; } scroll.X = scroll.X + button.Width; scroll.Width = scroll_w; } scroll_step = step < scroll.Width ? step : scroll.Width; scroll_offset = (offset < target - scroll.Width ? offset : target - scroll.Width) < 0 ? 0 : offset < target - scroll.Width ? offset : target - scroll.Width; scroll_ratio = scroll.Width / target; scroll_off = scroll_offset / target; cursor.Width = scroll_ratio * scroll.Width - (2 * style.border + 2 * style.padding.X); cursor.X = scroll.X + scroll_off * scroll.Width + style.border + style.padding.X; cursor.Height = scroll.Height - (2 * style.border + 2 * style.padding.Y); cursor.Y = scroll.Y + style.border + style.padding.Y; empty_west.X = scroll.X; empty_west.Y = scroll.Y; empty_west.Width = cursor.X - scroll.X; empty_west.Height = scroll.Height; empty_east.X = cursor.X + cursor.Width; empty_east.Y = scroll.Y; empty_east.Width = scroll.X + scroll.Width - (cursor.X + cursor.Width); empty_east.Height = scroll.Height; scroll_offset = nk_scrollbar_behavior(ref state, _in_, has_scrolling, &scroll, ref cursor, &empty_west, &empty_east, scroll_offset, target, scroll_step, NK_HORIZONTAL); scroll_off = scroll_offset / target; cursor.X = scroll.X + scroll_off * scroll.Width; if (style.draw_begin != null) { style.draw_begin(_out_); } _out_.DrawScrollbar(state, style, &scroll, &cursor); if (style.draw_end != null) { style.draw_end(_out_); } return(scroll_offset); }