MCPcopy
hub / github.com/mum4k/termdash / Rectangle

Function Rectangle

private/alignfor/alignfor.go:74–88  ·  view source on GitHub ↗

Rectangle aligns the area within the rectangle returning the aligned area. The area must fall within the rectangle.

(rect image.Rectangle, ar image.Rectangle, h align.Horizontal, v align.Vertical)

Source from the content-addressed store, hash-verified

72// Rectangle aligns the area within the rectangle returning the
73// aligned area. The area must fall within the rectangle.
74func Rectangle(rect image.Rectangle, ar image.Rectangle, h align.Horizontal, v align.Vertical) (image.Rectangle, error) {
75 if !ar.In(rect) {
76 return image.ZR, fmt.Errorf("cannot align area %v inside rectangle %v, the area falls outside of the rectangle", ar, rect)
77 }
78
79 aligned, err := hAlign(rect, ar, h)
80 if err != nil {
81 return image.ZR, err
82 }
83 aligned, err = vAlign(rect, aligned, v)
84 if err != nil {
85 return image.ZR, err
86 }
87 return aligned, nil
88}
89
90// Text aligns the text within the given rectangle, returns the start point for the text.
91// For the purposes of the alignment this assumes that text will be trimmed if

Callers 5

widgetAreaMethod · 0.92
segAreaMethod · 0.92
DrawMethod · 0.92
TextFunction · 0.70
TestRectangleFunction · 0.70

Calls 2

hAlignFunction · 0.85
vAlignFunction · 0.85

Tested by 1

TestRectangleFunction · 0.56