-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
compound_border.go
42 lines (36 loc) · 1.28 KB
/
compound_border.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2021-2024 by Richard A. Wilkes. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, version 2.0.
package unison
var _ Border = &CompoundBorder{}
// CompoundBorder provides stacking of borders together.
type CompoundBorder struct {
borders []Border
}
// NewCompoundBorder creates a border that contains other borders. The first one will be drawn in the outermost
// position, with each successive one moving further into the interior.
func NewCompoundBorder(borders ...Border) *CompoundBorder {
return &CompoundBorder{borders: borders}
}
// Insets returns the insets describing the space the border occupies on each side.
func (b *CompoundBorder) Insets() Insets {
insets := Insets{}
for _, one := range b.borders {
insets = insets.Add(one.Insets())
}
return insets
}
// Draw the border into rect.
func (b *CompoundBorder) Draw(canvas *Canvas, rect Rect) {
for _, one := range b.borders {
canvas.Save()
one.Draw(canvas, rect)
canvas.Restore()
rect = rect.Inset(one.Insets())
}
}