| 22638 | }} |
| 22639 | } |
| 22640 | NK_LIB nk_flags |
| 22641 | nk_do_edit(nk_flags *state, struct nk_command_buffer *out, |
| 22642 | struct nk_rect bounds, nk_flags flags, nk_plugin_filter filter, |
| 22643 | struct nk_text_edit *edit, const struct nk_style_edit *style, |
| 22644 | struct nk_input *in, const struct nk_user_font *font) |
| 22645 | { |
| 22646 | struct nk_rect area; |
| 22647 | nk_flags ret = 0; |
| 22648 | float row_height; |
| 22649 | char prev_state = 0; |
| 22650 | char is_hovered = 0; |
| 22651 | char select_all = 0; |
| 22652 | char cursor_follow = 0; |
| 22653 | struct nk_rect old_clip; |
| 22654 | struct nk_rect clip; |
| 22655 | |
| 22656 | NK_ASSERT(state); |
| 22657 | NK_ASSERT(out); |
| 22658 | NK_ASSERT(style); |
| 22659 | if (!state || !out || !style) |
| 22660 | return ret; |
| 22661 | |
| 22662 | /* visible text area calculation */ |
| 22663 | area.x = bounds.x + style->padding.x + style->border; |
| 22664 | area.y = bounds.y + style->padding.y + style->border; |
| 22665 | area.w = bounds.w - (2.0f * style->padding.x + 2 * style->border); |
| 22666 | area.h = bounds.h - (2.0f * style->padding.y + 2 * style->border); |
| 22667 | if (flags & NK_EDIT_MULTILINE) |
| 22668 | area.w = NK_MAX(0, area.w - style->scrollbar_size.x); |
| 22669 | row_height = (flags & NK_EDIT_MULTILINE)? font->height + style->row_padding: area.h; |
| 22670 | |
| 22671 | /* calculate clipping rectangle */ |
| 22672 | old_clip = out->clip; |
| 22673 | nk_unify(&clip, &old_clip, area.x, area.y, area.x + area.w, area.y + area.h); |
| 22674 | |
| 22675 | /* update edit state */ |
| 22676 | prev_state = (char)edit->active; |
| 22677 | is_hovered = (char)nk_input_is_mouse_hovering_rect(in, bounds); |
| 22678 | if (in && in->mouse.buttons[NK_BUTTON_LEFT].clicked && in->mouse.buttons[NK_BUTTON_LEFT].down) { |
| 22679 | edit->active = NK_INBOX(in->mouse.pos.x, in->mouse.pos.y, |
| 22680 | bounds.x, bounds.y, bounds.w, bounds.h); |
| 22681 | } |
| 22682 | |
| 22683 | /* (de)activate text editor */ |
| 22684 | if (!prev_state && edit->active) { |
| 22685 | const enum nk_text_edit_type type = (flags & NK_EDIT_MULTILINE) ? |
| 22686 | NK_TEXT_EDIT_MULTI_LINE: NK_TEXT_EDIT_SINGLE_LINE; |
| 22687 | nk_textedit_clear_state(edit, type, filter); |
| 22688 | if (flags & NK_EDIT_AUTO_SELECT) |
| 22689 | select_all = nk_true; |
| 22690 | if (flags & NK_EDIT_GOTO_END_ON_ACTIVATE) { |
| 22691 | edit->cursor = edit->string.len; |
| 22692 | in = 0; |
| 22693 | } |
| 22694 | } else if (!edit->active) edit->mode = NK_TEXT_EDIT_MODE_VIEW; |
| 22695 | if (flags & NK_EDIT_READ_ONLY) |
| 22696 | edit->mode = NK_TEXT_EDIT_MODE_VIEW; |
| 22697 | else if (flags & NK_EDIT_ALWAYS_INSERT_MODE) |
no test coverage detected