Make password inputboxes display '#'s
This commit is contained in:
parent
ea4e335389
commit
0cf453f347
|
@ -373,15 +373,17 @@ static void djui_inputbox_render_char(struct DjuiInputbox* inputbox, char* c, f3
|
|||
f32 dW = font->charWidth * font->defaultFontScale;
|
||||
f32 dH = font->charHeight * font->defaultFontScale;
|
||||
|
||||
f32 charWidth = font->char_width(c);
|
||||
char* dc = inputbox->passwordChar[0] ? inputbox->passwordChar : c;
|
||||
|
||||
f32 charWidth = font->char_width(dc);
|
||||
*drawX += charWidth * font->defaultFontScale;
|
||||
|
||||
if (*c != ' ' && !djui_gfx_add_clipping_specific(&inputbox->base, dX, dY, dW, dH)) {
|
||||
if (*dc != ' ' && !djui_gfx_add_clipping_specific(&inputbox->base, dX, dY, dW, dH)) {
|
||||
if (*additionalShift > 0) {
|
||||
create_dl_translation_matrix(DJUI_MTX_NOPUSH, *additionalShift, 0, 0);
|
||||
*additionalShift = 0;
|
||||
}
|
||||
font->render_char(c);
|
||||
font->render_char(dc);
|
||||
}
|
||||
*additionalShift += charWidth;
|
||||
}
|
||||
|
@ -398,10 +400,11 @@ static void djui_inputbox_render_selection(struct DjuiInputbox* inputbox) {
|
|||
f32 x = 0;
|
||||
f32 width = 0;
|
||||
for (u16 i = 0; i < selection[1]; i++) {
|
||||
char* dc = inputbox->passwordChar[0] ? inputbox->passwordChar : c;
|
||||
if (i < selection[0]) {
|
||||
x += font->char_width(c);
|
||||
x += font->char_width(dc);
|
||||
} else {
|
||||
width += font->char_width(c);
|
||||
width += font->char_width(dc);
|
||||
}
|
||||
c = djui_unicode_next_char(c);
|
||||
}
|
||||
|
@ -458,7 +461,8 @@ static void djui_inputbox_keep_selection_in_view(struct DjuiInputbox* inputbox)
|
|||
char* c = inputbox->buffer;
|
||||
for (u16 i = 0; i < inputbox->selection[0]; i++) {
|
||||
if (*c == '\0') { break; }
|
||||
cursorX += font->char_width(c) * font->defaultFontScale;
|
||||
char* dc = inputbox->passwordChar[0] ? inputbox->passwordChar : c;
|
||||
cursorX += font->char_width(dc) * font->defaultFontScale;
|
||||
c = djui_unicode_next_char(c);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
struct DjuiInputbox {
|
||||
struct DjuiBase base;
|
||||
char* buffer;
|
||||
char passwordChar[2];
|
||||
u16 bufferSize;
|
||||
u16 selection[2];
|
||||
f32 viewX;
|
||||
|
|
|
@ -147,6 +147,7 @@ void djui_panel_host_create(struct DjuiBase* caller) {
|
|||
}
|
||||
|
||||
sInputboxPassword = djui_inputbox_create(&sRectPassword->base, 32);
|
||||
sInputboxPassword->passwordChar[0] = '#';
|
||||
djui_base_set_size_type(&sInputboxPassword->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&sInputboxPassword->base, 0.4f, 32);
|
||||
djui_base_set_alignment(&sInputboxPassword->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_TOP);
|
||||
|
|
|
@ -30,6 +30,7 @@ void djui_panel_join_private_create(struct DjuiBase* caller) {
|
|||
djui_base_set_color(&text1->base, 200, 200, 200, 255);
|
||||
|
||||
struct DjuiInputbox* inputbox1 = djui_inputbox_create(body, 256);
|
||||
inputbox1->passwordChar[0] = '#';
|
||||
djui_base_set_size_type(&inputbox1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&inputbox1->base, 1.0f, 32.0f);
|
||||
sInputboxPassword = inputbox1;
|
||||
|
|
Loading…
Reference in New Issue