| 1 |
package app |
| 2 |
|
| 3 |
import ( |
| 4 |
"git.sr.ht/~rjarry/aerc/lib/ui" |
| 5 |
) |
| 6 |
|
| 7 |
type Dialog interface { |
| 8 |
ui.DrawableInteractive |
| 9 |
ContextWidth() (func(int) int, func(int) int) |
| 10 |
ContextHeight() (func(int) int, func(int) int) |
| 11 |
} |
| 12 |
|
| 13 |
type dialog struct { |
| 14 |
ui.DrawableInteractive |
| 15 |
x func(int) int |
| 16 |
y func(int) int |
| 17 |
w func(int) int |
| 18 |
h func(int) int |
| 19 |
} |
| 20 |
|
| 21 |
func (d *dialog) ContextWidth() (func(int) int, func(int) int) { |
| 22 |
return d.x, d.w |
| 23 |
} |
| 24 |
|
| 25 |
func (d *dialog) ContextHeight() (func(int) int, func(int) int) { |
| 26 |
return d.y, d.h |
| 27 |
} |
| 28 |
|
| 29 |
func NewDialog( |
| 30 |
d ui.DrawableInteractive, |
| 31 |
x func(int) int, y func(int) int, |
| 32 |
w func(int) int, h func(int) int, |
| 33 |
) *dialog { |
| 34 |
return &dialog{DrawableInteractive: d, x: x, y: y, w: w, h: h} |
| 35 |
} |
| 36 |
|
| 37 |
// DefaultDialog creates a dialog window spanning half of the screen |
| 38 |
func DefaultDialog(d ui.DrawableInteractive) Dialog { |
| 39 |
position := SelectedAccountUiConfig().DialogPosition |
| 40 |
width := SelectedAccountUiConfig().DialogWidth |
| 41 |
height := SelectedAccountUiConfig().DialogHeight |
| 42 |
return NewDialog(d, |
| 43 |
// horizontal starting position in columns from the left |
| 44 |
func(w int) int { |
| 45 |
return (w * (100 - width)) / 200 |
| 46 |
}, |
| 47 |
// vertical starting position in lines from the top |
| 48 |
func(h int) int { |
| 49 |
switch position { |
| 50 |
case "center": |
| 51 |
return (h * (100 - height)) / 200 |
| 52 |
case "bottom": |
| 53 |
return h - (h * height / 100) |
| 54 |
default: |
| 55 |
return 1 |
| 56 |
} |
| 57 |
}, |
| 58 |
// dialog width from the starting column |
| 59 |
func(w int) int { |
| 60 |
return w * width / 100 |
| 61 |
}, |
| 62 |
// dialog height from the starting line |
| 63 |
func(h int) int { |
| 64 |
if position == "bottom" { |
| 65 |
return h*height/100 - 1 |
| 66 |
} |
| 67 |
return h * height / 100 |
| 68 |
}, |
| 69 |
) |
| 70 |
} |