static unsigned int SpinControlWidth(txt_spincontrol_t *spincontrol) { unsigned int minw, maxw; switch (spincontrol->type) { case TXT_SPINCONTROL_FLOAT: minw = FloatWidth(spincontrol->min.f, spincontrol->step.f); maxw = FloatWidth(spincontrol->max.f, spincontrol->step.f); break; default: case TXT_SPINCONTROL_INT: minw = IntWidth(spincontrol->min.i); maxw = IntWidth(spincontrol->max.i); break; } // Choose the wider of the two values. Add one so that there is always // space for the cursor when editing. if (minw > maxw) { return minw; } else { return maxw; } }
void TextFormat::SetCoordFormat(size_t maxFrames, double min, double step, int default_width, int default_precision) { int col_precision = default_precision; // Determine maximum coordinate. double maxCoord = (step * (double)maxFrames) + min; // Determine character width necessary to hold largest coordinate. int col_width = DigitWidth( (long int)maxCoord ); // Check if the precision is enough to support the step size. if (step < 1.0) { int prec_exp_width = FloatWidth( step ); if (prec_exp_width > col_precision) col_precision = prec_exp_width; } // If the width for the column plus the characters needed for precision // (plus 1 for decimal point) would be greated than default_width, increment // the column width by (precision+1). if (col_precision != 0) { int precision_width = col_width + col_precision + 1; if (precision_width > default_width) col_width = precision_width; } // Default width for column is at least default_width. if (col_width < default_width) col_width = default_width; // Set column data format string, left-aligned (no leading space). type_ = DOUBLE; width_ = col_width; precision_ = col_precision; align_ = RIGHT; SetFormatString(); }