Fix issue #21 by not drawing chars that don't fit
This commit is contained in:
parent
8ef53a8582
commit
97abb638fe
19
libs/draw.c
19
libs/draw.c
|
@ -473,10 +473,23 @@ int drawinput(int x, int y, int w) {
|
||||||
free(censort);
|
free(censort);
|
||||||
} else if (!passwd) {
|
} else if (!passwd) {
|
||||||
if (strlen(tx.text)) {
|
if (strlen(tx.text)) {
|
||||||
apply_fribidi(tx.text);
|
char ptext[BUFSIZ];
|
||||||
draw_text(draw, x, y, w, sp.bh, sp.lrpad / 2, isrtl ? fribidi_text : tx.text, 0, pango_input ? True : False, col_inputfg, col_inputbg, alpha_inputfg, alpha_inputbg);
|
char *p;
|
||||||
|
|
||||||
curpos = TEXTW(tx.text) - TEXTW(&tx.text[sp.cursor]);
|
memcpy(ptext, tx.text, BUFSIZ);
|
||||||
|
|
||||||
|
p = ptext;
|
||||||
|
|
||||||
|
while (TEXTW(p) > sp.maxlen) {
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
memmove(ptext, p, strlen(p) + 1);
|
||||||
|
|
||||||
|
apply_fribidi(ptext);
|
||||||
|
draw_text(draw, x, y, w, sp.bh, sp.lrpad / 2, isrtl ? fribidi_text : ptext, 0, pango_input ? True : False, col_inputfg, col_inputbg, alpha_inputfg, alpha_inputbg);
|
||||||
|
|
||||||
|
curpos = TEXTW(ptext) - TEXTW(&ptext[sp.cursor]);
|
||||||
} else if (!hidepretext && pretext != NULL) {
|
} else if (!hidepretext && pretext != NULL) {
|
||||||
apply_fribidi(pretext);
|
apply_fribidi(pretext);
|
||||||
draw_text(draw, x + fw, y, w, sp.bh, sp.lrpad / 2, isrtl ? fribidi_text : pretext, 0, pango_pretext ? True : False, col_pretextfg, col_pretextbg, alpha_pretextfg, alpha_pretextbg);
|
draw_text(draw, x + fw, y, w, sp.bh, sp.lrpad / 2, isrtl ? fribidi_text : pretext, 0, pango_pretext ? True : False, col_pretextfg, col_pretextbg, alpha_pretextfg, alpha_pretextbg);
|
||||||
|
|
31
spmenu.c
31
spmenu.c
|
@ -141,6 +141,8 @@ struct sp {
|
||||||
int listcount;
|
int listcount;
|
||||||
int listchanged;
|
int listchanged;
|
||||||
|
|
||||||
|
int maxlen; // max length of text
|
||||||
|
|
||||||
size_t cursor; // cursor width
|
size_t cursor; // cursor width
|
||||||
|
|
||||||
int ignoreconfkeys; // can be set globally if you don't want to override keybinds with config file keys
|
int ignoreconfkeys; // can be set globally if you don't want to override keybinds with config file keys
|
||||||
|
@ -363,10 +365,6 @@ void recalculatenumbers(void) {
|
||||||
|
|
||||||
void calcoffsets(void) {
|
void calcoffsets(void) {
|
||||||
int i, offset;
|
int i, offset;
|
||||||
|
|
||||||
if (lines > 0) {
|
|
||||||
offset = lines * columns * sp.bh;
|
|
||||||
} else { // no lines, therefore the size of items must be decreased to fit the menu elements
|
|
||||||
int numberw = 0;
|
int numberw = 0;
|
||||||
int modew = 0;
|
int modew = 0;
|
||||||
int larroww = 0;
|
int larroww = 0;
|
||||||
|
@ -383,9 +381,14 @@ void calcoffsets(void) {
|
||||||
capsw = 0;
|
capsw = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lines > 0) {
|
||||||
|
offset = lines * columns * sp.bh;
|
||||||
|
} else { // no lines, therefore the size of items must be decreased to fit the menu elements
|
||||||
offset = sp.mw - (sp.promptw + sp.inputw + larroww + rarroww + modew + numberw + capsw + menumarginh);
|
offset = sp.mw - (sp.promptw + sp.inputw + larroww + rarroww + modew + numberw + capsw + menumarginh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sp.maxlen = sp.mw - (sp.promptw + modew + numberw + capsw + menumarginh);
|
||||||
|
|
||||||
// calculate which items will begin the next page
|
// calculate which items will begin the next page
|
||||||
for (i = 0, nextitem = currentitem; nextitem; nextitem = nextitem->right) {
|
for (i = 0, nextitem = currentitem; nextitem; nextitem = nextitem->right) {
|
||||||
nextitem->nsgrtext = get_text_n_sgr(nextitem);
|
nextitem->nsgrtext = get_text_n_sgr(nextitem);
|
||||||
|
@ -463,26 +466,6 @@ void insert(const char *str, ssize_t n) {
|
||||||
if (strlen(tx.text) + n > sizeof tx.text - 1)
|
if (strlen(tx.text) + n > sizeof tx.text - 1)
|
||||||
return; // length of text should not exceed size
|
return; // length of text should not exceed size
|
||||||
|
|
||||||
int numberw = 0;
|
|
||||||
int modew = 0;
|
|
||||||
int larroww = 0;
|
|
||||||
int rarroww = 0;
|
|
||||||
int capsw = 0;
|
|
||||||
|
|
||||||
// add width
|
|
||||||
if (!hidelarrow) larroww = TEXTW(leftarrow);
|
|
||||||
if (!hiderarrow) rarroww = TEXTW(rightarrow);
|
|
||||||
if (!hidemode) modew = MAX(MAX(TEXTW(normtext), TEXTW(instext)), TEXTW(regextext));
|
|
||||||
if (!hiderarrow) rarroww = TEXTW(rightarrow);
|
|
||||||
if (!hidematchcount) numberw = TEXTW(tx.numbers);
|
|
||||||
if (!hidecaps) capsw = MAX(TEXTW(capslockontext), TEXTW(capslockofftext));
|
|
||||||
|
|
||||||
if (TEXTW(str) + TEXTW(tx.text) >= sp.inputw && selecteditem) {
|
|
||||||
return;
|
|
||||||
} else if (TEXTW(str) + TEXTW(tx.text) >= sp.mw - (sp.promptw + (!lines ? larroww : 0) + (!lines ? rarroww : 0) + modew + numberw + capsw + menumarginh)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char l[BUFSIZ] = "";
|
static char l[BUFSIZ] = "";
|
||||||
|
|
||||||
if (requirematch) {
|
if (requirematch) {
|
||||||
|
|
Loading…
Reference in a new issue