> > If you have a label setup and use measure_label you don't get back the
> > proper values. The problem is that the alignment option (FL_ALIGN_WRAP
> > being an important one) aren't given to fl_measure, it just assumes if
> > there is a width that it will wrap even if the alignment doesn't have
> > FL_ALIGN_WRAP enable.
>
> Seeing as how I'll probably need to make a new fl_measure that takes an
> alignment parameter, I came accross this in the current fl_measure:
>
> strlcpy(symbol[1], p, sizeof(symbol[1]));
>
> which, unless I'm missing something, seems to not be used anywhere and just a
> big waste of time. ??
>
> In fact, maybe the whole notion of storing the symbol at symptr (symbol[0])
> is not needed. symwidth[] looks to be the only thing used in measure?
I threw something together below - I didn't test it in every condition, but
solves my problems with measure_label
void FltkMeasureWidgetLabel(Fl_Widget *widget, int& w, int& h, int
draw_symbols) {
// point to label
const char *str=widget->label();
// ensure label exists
if (!str || !*str) {
w = 0;
h = 0;
return;
}
// setup font
fl_font(widget->labelfont(), widget->labelsize());
// get standard hight of line
int H = fl_height();
#define MAXBUF 1024
#define MAXSYMLEN 255
// track with for symbols
int symtotalwidth=0;
// determine if symbols will be drawn and need measuring
if (draw_symbols) {
// measure symbols starting at beginning of string
if (str && str[0] == FL_SYMBOL_CHAR && str[1] && str[1] != FL_SYMBOL_CHAR) {
// Start with a symbol...
int symcount=0;
while (*str && !isspace(*str) && symcount < (MAXSYMLEN - 1)) {
str++;
symcount++;
}
if (isspace(*str)) str++;
symtotalwidth+=H;
}
const char *p;
if (str && (p = strrchr(str, FL_SYMBOL_CHAR)) != NULL && p > (str + 1) &&
p[-1]!=FL_SYMBOL_CHAR) {
symtotalwidth+=H;
}
}
// buffer for fl_expand_text
char buf[MAXBUF];
// count lines found
int lines=0;
// calculated width
int W = 0;
// loop through the various lines
for (const char *p = str;;) {
double width=0;
int charsputinbuf;
// extract text to buffer
const char *e = fl_expand_text(p, buf, MAXBUF, w - symtotalwidth,
charsputinbuf, width, (widget->align() & FL_ALIGN_WRAP)!=0, draw_symbols);
// track widest line
if ((int)ceil(width) > W) {
W = (int)ceil(width);
}
// track number of lines
lines++;
// determine if we exit lop due to end of string or symbol
if (!*e || (*e == FL_SYMBOL_CHAR && e[1] != FL_SYMBOL_CHAR &&
draw_symbols)) break;
// determine if we exit because no wrapping
if ((widget->align() & FL_ALIGN_WRAP)==0 && e[-1]!='\n') break;
// point to next text in buffer
p = e;
}
// adjust symbol width based number of lines (symbol size grows to cover each
line?)
if (symtotalwidth && lines) {
symtotalwidth*=lines;
}
// get total width
W+=symtotalwidth;
// adjust w if within draw range
if (!w || W<w || (widget->align() & FL_ALIGN_CLIP)==0) {
w = W;
}
// calc total height
H*=lines;
// adjust h if within draw range
if (!h || H<h || (widget->align() & FL_ALIGN_CLIP)==0) {
h=H;
}
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk