preprocess determines the size of individual segments maximizing their height or the amount of displayed characters based on the specified options. Returns the area required for a single segment, the text that we can fit and size of gaps between segments in cells.
(cvsAr image.Rectangle)
| 184 | // Returns the area required for a single segment, the text that we can fit and |
| 185 | // size of gaps between segments in cells. |
| 186 | func (sd *SegmentDisplay) preprocess(cvsAr image.Rectangle) (*segArea, error) { |
| 187 | textLen := sd.buff.Len() // We're guaranteed by Write to only have ASCII characters. |
| 188 | segAr, err := newSegArea(cvsAr, textLen, sd.opts.gapPercent) |
| 189 | if err != nil { |
| 190 | return nil, err |
| 191 | } |
| 192 | |
| 193 | need := sd.buff.Len() |
| 194 | if (need > 0 && need <= segAr.canFit) || sd.opts.maximizeSegSize { |
| 195 | return segAr, nil |
| 196 | } |
| 197 | |
| 198 | bestAr, err := maximizeFit(cvsAr, textLen, sd.opts.gapPercent) |
| 199 | if err != nil { |
| 200 | return nil, err |
| 201 | } |
| 202 | return bestAr, nil |
| 203 | } |
| 204 | |
| 205 | // Draw draws the SegmentDisplay widget onto the canvas. |
| 206 | // Implements widgetapi.Widget.Draw. |
no test coverage detected