Draw draws the current state of the segment display onto the canvas. The canvas must be at least MinCols x MinRows cells, or an error will be returned. Any options provided to draw overwrite the values provided to New.
(cvs *canvas.Canvas, opts ...Option)
| 378 | // returned. |
| 379 | // Any options provided to draw overwrite the values provided to New. |
| 380 | func (d *Display) Draw(cvs *canvas.Canvas, opts ...Option) error { |
| 381 | for _, o := range opts { |
| 382 | o.set(d) |
| 383 | } |
| 384 | |
| 385 | bc, bcAr, err := segdisp.ToBraille(cvs) |
| 386 | if err != nil { |
| 387 | return err |
| 388 | } |
| 389 | |
| 390 | attr := NewAttributes(bcAr) |
| 391 | var sOpts []segment.Option |
| 392 | if len(d.cellOpts) > 0 { |
| 393 | sOpts = append(sOpts, segment.CellOpts(d.cellOpts...)) |
| 394 | } |
| 395 | for _, segArg := range []struct { |
| 396 | s Segment |
| 397 | opts []segment.Option |
| 398 | }{ |
| 399 | {A1, nil}, |
| 400 | {A2, nil}, |
| 401 | |
| 402 | {F, nil}, |
| 403 | {J, []segment.Option{segment.SkipSlopesLTE(2)}}, |
| 404 | {B, []segment.Option{segment.ReverseSlopes()}}, |
| 405 | |
| 406 | {G1, []segment.Option{segment.SkipSlopesLTE(2)}}, |
| 407 | {G2, []segment.Option{segment.SkipSlopesLTE(2)}}, |
| 408 | |
| 409 | {E, nil}, |
| 410 | {M, []segment.Option{segment.SkipSlopesLTE(2)}}, |
| 411 | {C, []segment.Option{segment.ReverseSlopes()}}, |
| 412 | |
| 413 | {D1, []segment.Option{segment.ReverseSlopes()}}, |
| 414 | {D2, []segment.Option{segment.ReverseSlopes()}}, |
| 415 | } { |
| 416 | if !d.segments[segArg.s] { |
| 417 | continue |
| 418 | } |
| 419 | sOpts := append(sOpts, segArg.opts...) |
| 420 | ar := attr.hvSegArea(segArg.s) |
| 421 | if err := segment.HV(bc, ar, hvSegType[segArg.s], sOpts...); err != nil { |
| 422 | return fmt.Errorf("failed to draw segment %v, segment.HV => %v", segArg.s, err) |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | var dsOpts []segment.DiagonalOption |
| 427 | if len(d.cellOpts) > 0 { |
| 428 | dsOpts = append(dsOpts, segment.DiagonalCellOpts(d.cellOpts...)) |
| 429 | } |
| 430 | for _, seg := range []Segment{H, K, N, L} { |
| 431 | if !d.segments[seg] { |
| 432 | continue |
| 433 | } |
| 434 | ar := attr.diaSegArea(seg) |
| 435 | if err := segment.Diagonal(bc, ar, attr.segSize, diaSegType[seg], dsOpts...); err != nil { |
| 436 | return fmt.Errorf("failed to draw segment %v, segment.Diagonal => %v", seg, err) |
| 437 | } |
nothing calls this directly
no test coverage detected