Projects STRLCPY termdash Commits 6e46b739
🤬
  • ■ ■ ■ ■ ■ ■
    widgets/gauge/gauge.go
    skipped 158 lines
    159 159   return cvs.Area()
    160 160  }
    161 161   
     162 +// thresholdVisible determines if the threshold line should be drawn.
     163 +func (g *Gauge) thresholdVisible() bool {
     164 + return g.opts.threshold > 0 && g.opts.threshold < g.total
     165 +}
     166 + 
    162 167  // progressText returns the textual representation of the current progress.
    163 168  func (g *Gauge) progressText() string {
    164 169   if g.opts.hideTextProgress {
    skipped 81 lines
    246 251   return nil
    247 252  }
    248 253   
     254 +// drawThreshold draws the threshold line.
     255 +func (g *Gauge) drawThreshold(cvs *canvas.Canvas) error {
     256 + ar := g.usable(cvs)
     257 + 
     258 + line := draw.HVLine{
     259 + Start: image.Point{
     260 + X: ar.Min.X + g.width(ar, g.opts.threshold),
     261 + Y: cvs.Area().Min.Y,
     262 + },
     263 + End: image.Point{
     264 + X: ar.Min.X + g.width(ar, g.opts.threshold),
     265 + Y: cvs.Area().Max.Y - 1,
     266 + },
     267 + }
     268 + return draw.HVLines(cvs, []draw.HVLine{line},
     269 + draw.HVLineStyle(g.opts.thresholdLineStyle),
     270 + draw.HVLineCellOpts(g.opts.thresholdCellOpts...),
     271 + )
     272 +}
     273 + 
    249 274  // Draw draws the Gauge widget onto the canvas.
    250 275  // Implements widgetapi.Widget.Draw.
    251 276  func (g *Gauge) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error {
    skipped 34 lines
    286 311   return err
    287 312   }
    288 313   }
    289  - if g.opts.threshold > 0 && g.opts.threshold < g.total {
    290  - line := draw.HVLine{
    291  - Start: image.Point{
    292  - X: usable.Min.X + g.width(usable, g.opts.threshold),
    293  - Y: cvs.Area().Min.Y,
    294  - },
    295  - End: image.Point{
    296  - X: usable.Min.X + g.width(usable, g.opts.threshold),
    297  - Y: cvs.Area().Max.Y - 1,
    298  - },
    299  - }
    300  - if err := draw.HVLines(cvs, []draw.HVLine{line},
    301  - draw.HVLineStyle(g.opts.thresholdLineStyle),
    302  - draw.HVLineCellOpts(g.opts.thresholdCellOpts...),
    303  - ); err != nil {
     314 + if g.thresholdVisible() {
     315 + if err := g.drawThreshold(cvs); err != nil {
    304 316   return err
    305 317   }
    306 318   }
    skipped 48 lines
Please wait...
Page is in error, reload to recover