Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

Commit

Permalink
Added a way to query if text input is required
Browse files Browse the repository at this point in the history
  • Loading branch information
namandixit committed Oct 29, 2024
1 parent 0850aba commit 2a2891d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/microui.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,10 @@ int mu_textbox_raw(mu_Context *ctx, char *buf, int bufsz, mu_Id id, mu_Rect r,
mu_update_control(ctx, id, r, opt | MU_OPT_HOLDFOCUS);

if (ctx->focus == id) {
ctx->text_edit_enable = 1;
ctx->text_edit_last_focus = id;
ctx->text_edit_rect = r;

/* handle text input */
int len = strlen(buf);
int n = mu_min(bufsz - len - 1, (int) strlen(ctx->input_text));
Expand All @@ -797,6 +801,8 @@ int mu_textbox_raw(mu_Context *ctx, char *buf, int bufsz, mu_Id id, mu_Rect r,
mu_set_focus(ctx, 0);
res |= MU_RES_SUBMIT;
}
} else if (ctx->text_edit_last_focus == id) {
ctx->text_edit_enable = 0;
}

/* draw */
Expand All @@ -805,6 +811,7 @@ int mu_textbox_raw(mu_Context *ctx, char *buf, int bufsz, mu_Id id, mu_Rect r,
mu_Color color = ctx->style->colors[MU_COLOR_TEXT];
mu_Font font = ctx->style->font;
int textw = ctx->text_width(font, buf, -1);
ctx->text_edit_cursor_relative_to_rect = textw;
int texth = ctx->text_height(font);
int ofx = r.w - ctx->style->padding - textw - 1;
int textx = r.x + mu_min(ofx, ctx->style->padding);
Expand Down
5 changes: 5 additions & 0 deletions src/microui.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ struct mu_Context {
mu_Container *scroll_target;
char number_edit_buf[MU_MAX_FMT];
mu_Id number_edit;

int text_edit_enable;
mu_Id text_edit_last_focus;
mu_Rect text_edit_rect;
int text_edit_cursor_relative_to_rect;
/* stacks */
mu_stack(char, MU_COMMANDLIST_SIZE) command_list;
mu_stack(mu_Container*, MU_ROOTLIST_SIZE) root_list;
Expand Down

0 comments on commit 2a2891d

Please sign in to comment.