mirror of
https://github.com/mum4k/termdash.git
synced 2025-04-27 13:48:49 +08:00
Guarantee some spacing between donut and its label.
This commit is contained in:
parent
8414868440
commit
e9b4ba3613
@ -196,7 +196,7 @@ func (d *Donut) drawText(cvs *canvas.Canvas, donutAr image.Rectangle, mid image.
|
||||
|
||||
// drawLabel draws the text label in the area.
|
||||
func (d *Donut) drawLabel(cvs *canvas.Canvas, labelAr image.Rectangle) error {
|
||||
start, err := alignfor.Text(labelAr, d.opts.label, d.opts.labelAlign, align.VerticalMiddle)
|
||||
start, err := alignfor.Text(labelAr, d.opts.label, d.opts.labelAlign, align.VerticalBottom)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -310,20 +310,14 @@ func (d *Donut) Options() widgetapi.Options {
|
||||
}
|
||||
}
|
||||
|
||||
// donutAndLabel splits the canvas area into square area for the donut and an
|
||||
// donutAndLabel splits the canvas area into an area for the donut and an
|
||||
// area under the donut for the text label.
|
||||
func donutAndLabel(cvsAr image.Rectangle) (donAr, labelAr image.Rectangle, err error) {
|
||||
height := cvsAr.Dy()
|
||||
// One line for the text label at the bottom.
|
||||
top, labelAr, err := area.HSplitCells(cvsAr, height-1)
|
||||
if err != nil {
|
||||
return image.ZR, image.ZR, err
|
||||
}
|
||||
|
||||
// Remove one line from the top too so the donut area remains square.
|
||||
// When using braille, this effectively removes 4 pixels from both the top
|
||||
// and the bottom. See braille.RowMult.
|
||||
donAr, err = area.Shrink(top, 1, 0, 0, 0)
|
||||
// Two lines for the text label at the bottom.
|
||||
// One for the text itself and one for visual space between the donut and
|
||||
// the label.
|
||||
donAr, labelAr, err = area.HSplitCells(cvsAr, height-2)
|
||||
if err != nil {
|
||||
return image.ZR, image.ZR, err
|
||||
}
|
||||
|
@ -338,8 +338,8 @@ func TestDonut(t *testing.T) {
|
||||
c := testcanvas.MustNew(ft.Area())
|
||||
bc := testbraille.MustNew(ft.Area())
|
||||
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 3,
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 5, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 3,
|
||||
draw.BrailleCircleFilled(),
|
||||
draw.BrailleCircleClearPixels(),
|
||||
)
|
||||
@ -642,14 +642,14 @@ func TestDonut(t *testing.T) {
|
||||
c := testcanvas.MustNew(ft.Area())
|
||||
bc := testbraille.MustNew(c.Area())
|
||||
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 6, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5,
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 6, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 5,
|
||||
draw.BrailleCircleFilled(),
|
||||
draw.BrailleCircleClearPixels(),
|
||||
)
|
||||
testbraille.MustCopyTo(bc, c)
|
||||
|
||||
testdraw.MustText(c, "100%", image.Point{2, 3})
|
||||
testdraw.MustText(c, "100%", image.Point{2, 2})
|
||||
|
||||
testdraw.MustText(c, "hi", image.Point{2, 6})
|
||||
|
||||
@ -672,14 +672,14 @@ func TestDonut(t *testing.T) {
|
||||
c := testcanvas.MustNew(ft.Area())
|
||||
bc := testbraille.MustNew(c.Area())
|
||||
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 6, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5,
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 6, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 5,
|
||||
draw.BrailleCircleFilled(),
|
||||
draw.BrailleCircleClearPixels(),
|
||||
)
|
||||
testbraille.MustCopyTo(bc, c)
|
||||
|
||||
testdraw.MustText(c, "100%", image.Point{2, 3})
|
||||
testdraw.MustText(c, "100%", image.Point{2, 2})
|
||||
|
||||
testdraw.MustText(c, "hi", image.Point{2, 6})
|
||||
|
||||
@ -702,14 +702,14 @@ func TestDonut(t *testing.T) {
|
||||
c := testcanvas.MustNew(ft.Area())
|
||||
bc := testbraille.MustNew(c.Area())
|
||||
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 6, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5,
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 6, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 5,
|
||||
draw.BrailleCircleFilled(),
|
||||
draw.BrailleCircleClearPixels(),
|
||||
)
|
||||
testbraille.MustCopyTo(bc, c)
|
||||
|
||||
testdraw.MustText(c, "100%", image.Point{2, 3})
|
||||
testdraw.MustText(c, "100%", image.Point{2, 2})
|
||||
|
||||
testdraw.MustText(c, "hi", image.Point{0, 6})
|
||||
|
||||
@ -732,14 +732,14 @@ func TestDonut(t *testing.T) {
|
||||
c := testcanvas.MustNew(ft.Area())
|
||||
bc := testbraille.MustNew(c.Area())
|
||||
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 6, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5,
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 6, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 5,
|
||||
draw.BrailleCircleFilled(),
|
||||
draw.BrailleCircleClearPixels(),
|
||||
)
|
||||
testbraille.MustCopyTo(bc, c)
|
||||
|
||||
testdraw.MustText(c, "100%", image.Point{2, 3})
|
||||
testdraw.MustText(c, "100%", image.Point{2, 2})
|
||||
|
||||
testdraw.MustText(c, "hi", image.Point{5, 6})
|
||||
|
||||
@ -765,14 +765,14 @@ func TestDonut(t *testing.T) {
|
||||
c := testcanvas.MustNew(ft.Area())
|
||||
bc := testbraille.MustNew(c.Area())
|
||||
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 6, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5,
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 6, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 5,
|
||||
draw.BrailleCircleFilled(),
|
||||
draw.BrailleCircleClearPixels(),
|
||||
)
|
||||
testbraille.MustCopyTo(bc, c)
|
||||
|
||||
testdraw.MustText(c, "100%", image.Point{2, 3})
|
||||
testdraw.MustText(c, "100%", image.Point{2, 2})
|
||||
|
||||
testdraw.MustText(
|
||||
c,
|
||||
@ -804,14 +804,14 @@ func TestDonut(t *testing.T) {
|
||||
c := testcanvas.MustNew(ft.Area())
|
||||
bc := testbraille.MustNew(c.Area())
|
||||
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 6, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 13}, 5,
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 6, draw.BrailleCircleFilled())
|
||||
testdraw.MustBrailleCircle(bc, image.Point{6, 9}, 5,
|
||||
draw.BrailleCircleFilled(),
|
||||
draw.BrailleCircleClearPixels(),
|
||||
)
|
||||
testbraille.MustCopyTo(bc, c)
|
||||
|
||||
testdraw.MustText(c, "100%", image.Point{2, 3})
|
||||
testdraw.MustText(c, "100%", image.Point{2, 2})
|
||||
|
||||
testdraw.MustText(c, "hello …", image.Point{0, 6})
|
||||
|
||||
|
@ -50,7 +50,7 @@ func playDonut(ctx context.Context, d *donut.Donut, start, step int, delay time.
|
||||
case <-ticker.C:
|
||||
switch pt {
|
||||
case playTypePercent:
|
||||
if err := d.Percent(progress); err != nil {
|
||||
if err := d.Percent(100); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
case playTypeAbsolute:
|
||||
@ -117,20 +117,22 @@ func main() {
|
||||
t,
|
||||
container.Border(linestyle.Light),
|
||||
container.BorderTitle("PRESS Q TO QUIT"),
|
||||
container.SplitVertical(
|
||||
container.Left(
|
||||
container.SplitVertical(
|
||||
container.Left(container.PlaceWidget(green)),
|
||||
container.Right(container.PlaceWidget(blue)),
|
||||
container.PlaceWidget(green),
|
||||
/*
|
||||
container.SplitVertical(
|
||||
container.Left(
|
||||
container.SplitVertical(
|
||||
container.Left(container.PlaceWidget(green)),
|
||||
container.Right(container.PlaceWidget(blue)),
|
||||
),
|
||||
),
|
||||
),
|
||||
container.Right(
|
||||
container.SplitVertical(
|
||||
container.Left(container.PlaceWidget(yellow)),
|
||||
container.Right(container.PlaceWidget(red)),
|
||||
container.Right(
|
||||
container.SplitVertical(
|
||||
container.Left(container.PlaceWidget(yellow)),
|
||||
container.Right(container.PlaceWidget(red)),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),*/
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user