1package common
2
3import (
4 "image"
5
6 "github.com/charmbracelet/crush/internal/config"
7 "github.com/charmbracelet/crush/internal/ui/styles"
8 uv "github.com/charmbracelet/ultraviolet"
9)
10
11// Common defines common UI options and configurations.
12type Common struct {
13 Config *config.Config
14 Styles styles.Styles
15}
16
17// DefaultCommon returns the default common UI configurations.
18func DefaultCommon(cfg *config.Config) *Common {
19 return &Common{
20 Config: cfg,
21 Styles: styles.DefaultStyles(),
22 }
23}
24
25// CenterRect returns a new [Rectangle] centered within the given area with the
26// specified width and height.
27func CenterRect(area uv.Rectangle, width, height int) uv.Rectangle {
28 centerX := area.Min.X + area.Dx()/2
29 centerY := area.Min.Y + area.Dy()/2
30 minX := centerX - width/2
31 minY := centerY - height/2
32 maxX := minX + width
33 maxY := minY + height
34 return image.Rect(minX, minY, maxX, maxY)
35}