* Fix for [#19488] Small slider = hidden values

Now number fields use a new method of clipping text when the available space is small:
http://vimeo.com/7545600
This commit is contained in:
2009-11-11 10:27:25 +00:00
parent e4f10565ea
commit 4157e51a25

View File

@@ -806,6 +806,46 @@ static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
}
}
static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
{
int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10;
int okwidth= rect->xmax-rect->xmin - border;
char *cpoin=NULL;
char *end = but->drawstr + strlen(but->drawstr);
/* need to set this first */
uiStyleFontSet(fstyle);
but->strwidth= BLF_width(but->drawstr);
but->ofs= 0;
/* find the space after ':' separator */
cpoin= strchr(but->drawstr, ':');
cpoin += 2;
if (cpoin >= end) cpoin = NULL;
/* chop off the text label, with ofs */
if (cpoin) {
while ((but->drawstr + but->ofs < cpoin) && (but->strwidth > okwidth))
{
but->ofs++;
but->strwidth= BLF_width(but->drawstr+but->ofs);
}
}
/* once the label's gone, chop off the least significant digits */
while(but->strwidth > okwidth ) {
int pos= strlen(but->drawstr);
but->drawstr[ pos-1 ] = 0;
pos--;
but->strwidth= BLF_width(but->drawstr+but->ofs);
if(but->strwidth < 10) break;
}
}
static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
{
// int transopts;
@@ -893,9 +933,12 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
{
if(but==NULL) return;
/* cutting off from left part */
if ELEM5(but->type, NUM, NUMABS, NUMSLI, SLI, TEX) {
/* clip but->drawstr to fit in available space */
if (ELEM4(but->type, NUM, NUMABS, NUMSLI, SLI)) {
ui_text_label_rightclip(fstyle, but, rect);
}
else if (but->type == TEX) {
ui_text_leftclip(fstyle, but, rect);
}
else but->ofs= 0;
@@ -1666,7 +1709,7 @@ static void widget_numbut(uiWidgetColors *wcol, rcti *rect, int state, int round
{
uiWidgetBase wtb;
float rad= 0.5f*(rect->ymax - rect->ymin);
widget_init(&wtb);
/* fully rounded */
@@ -1888,7 +1931,6 @@ static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int s
rcti rect1;
double value;
float offs, fac;
int textoffs;
char outline[3];
widget_init(&wtb);
@@ -1898,7 +1940,6 @@ static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int s
/* fully rounded */
offs= 0.5f*(rect->ymax - rect->ymin);
textoffs= offs;
round_box_edges(&wtb, roundboxalign, rect, offs);
wtb.outline= 0;
@@ -1940,8 +1981,8 @@ static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int s
widgetbase_draw(&wtb, wcol);
/* text space */
rect->xmin += textoffs;
rect->xmax -= textoffs;
rect->xmin += offs*0.75f;
rect->xmax -= offs*0.75f;
}
static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)