mirror of
https://github.com/anotherhadi/ilovetui.git
synced 2026-08-21 12:05:49 +02:00
init layout, notifications, tabs & more
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package notification
|
||||
|
||||
// Position anchors the toast stack to one of six spots on the rendered
|
||||
// background. There's no center/middle variant: toasts always hug an edge or
|
||||
// a corner, never the middle of the screen.
|
||||
type Position int
|
||||
|
||||
const (
|
||||
Top Position = iota
|
||||
TopLeft
|
||||
TopRight
|
||||
Bottom
|
||||
BottomLeft
|
||||
BottomRight
|
||||
)
|
||||
|
||||
// margin is the fixed gap, in cells, kept between the toast stack and the
|
||||
// edge(s) of the background it's anchored to.
|
||||
const margin = 1
|
||||
|
||||
// placement resolves the top-left (x, y) coordinate to draw a stack of size
|
||||
// (sw, sh) at, given a background of size (w, h) and the anchor position.
|
||||
func placement(pos Position, w, h, sw, sh int) (x, y int) {
|
||||
switch pos {
|
||||
case Top:
|
||||
x = (w - sw) / 2
|
||||
y = margin
|
||||
case TopLeft:
|
||||
x = margin
|
||||
y = margin
|
||||
case TopRight:
|
||||
x = w - sw - margin
|
||||
y = margin
|
||||
case Bottom:
|
||||
x = (w - sw) / 2
|
||||
y = h - sh - margin
|
||||
case BottomLeft:
|
||||
x = margin
|
||||
y = h - sh - margin
|
||||
case BottomRight:
|
||||
x = w - sw - margin
|
||||
y = h - sh - margin
|
||||
}
|
||||
if x < 0 {
|
||||
x = 0
|
||||
}
|
||||
if y < 0 {
|
||||
y = 0
|
||||
}
|
||||
return x, y
|
||||
}
|
||||
|
||||
// anchoredTop reports whether pos hugs the top edge, which decides both the
|
||||
// stacking order (see Model.orderedToasts) and which side of an overflowing
|
||||
// stack gets clipped (see clipToHeight).
|
||||
func (pos Position) anchoredTop() bool {
|
||||
return pos == Top || pos == TopLeft || pos == TopRight
|
||||
}
|
||||
Reference in New Issue
Block a user