static void TXT_InputBoxDrawer(TXT_UNCAST_ARG(inputbox)) { TXT_CAST_ARG(txt_inputbox_t, inputbox); int focused; int i; int chars; int w; focused = inputbox->widget.focused; w = inputbox->widget.w; // Select the background color based on whether we are currently // editing, and if not, whether the widget is focused. if (inputbox->editing && focused) { TXT_BGColor(TXT_COLOR_BLACK, 0); } else { TXT_SetWidgetBG(inputbox); } if (!inputbox->editing) { // If not editing, use the current value from inputbox->value. SetBufferFromValue(inputbox); } // If string size exceeds the widget's width, show only the end. if (TXT_UTF8_Strlen(inputbox->buffer) > w - 1) { TXT_DrawString("\xae"); TXT_DrawUTF8String( TXT_UTF8_SkipChars(inputbox->buffer, TXT_UTF8_Strlen(inputbox->buffer) - w + 2)); chars = w - 1; } else { TXT_DrawUTF8String(inputbox->buffer); chars = TXT_UTF8_Strlen(inputbox->buffer); } if (chars < w && inputbox->editing && focused) { TXT_BGColor(TXT_COLOR_BLACK, 1); TXT_DrawString("_"); ++chars; } for (i=chars; i < w; ++i) { TXT_DrawString(" "); } }
static void TXT_LabelDrawer(TXT_UNCAST_ARG(label)) { TXT_CAST_ARG(txt_label_t, label); unsigned int x, y; int origin_x, origin_y; unsigned int align_indent = 0; unsigned int w; w = label->widget.w; if (label->bgcolor >= 0) { TXT_BGColor(label->bgcolor, 0); } if (label->fgcolor >= 0) { TXT_FGColor(label->fgcolor); } TXT_GetXY(&origin_x, &origin_y); for (y=0; y<label->h; ++y) { // Calculate the amount to indent this line due to the align // setting switch (label->widget.align) { case TXT_HORIZ_LEFT: align_indent = 0; break; case TXT_HORIZ_CENTER: align_indent = (label->w - strlen(label->lines[y])) / 2; break; case TXT_HORIZ_RIGHT: align_indent = label->w - strlen(label->lines[y]); break; } // Draw this line TXT_GotoXY(origin_x, origin_y + y); // Gap at the start for (x=0; x<align_indent; ++x) { TXT_DrawString(" "); } // The string itself TXT_DrawUTF8String(label->lines[y]); x += TXT_UTF8_Strlen(label->lines[y]); // Gap at the end for (; x<w; ++x) { TXT_DrawString(" "); } } }