gizak / termui

Golang terminal dashboard
MIT License
13.22k stars 786 forks source link

Feature Request: add containers for widgets #320

Open gospacedev opened 2 years ago

gospacedev commented 2 years ago

The way to set the positions of widgets is through the x1 y1 coordinates in func (*Block) SetRect:

p := widgets.NewParagraph()
    p.Title = "Lunar"
    p.Text = selectedAudio
    p.SetRect(0, 0, 40, 3)
    p.TitleStyle.Fg = ui.ColorYellow
    p.BorderStyle.Fg = ui.ColorCyan

    c := widgets.NewParagraph()
    c.Title = "Audio Controls"
    c.Text = `Pause and play music: [ENTER]
Volume: [↓ ↑]
Speed:  [← →]
Normal Speed: [Ctrl + N]
Back to menu: [BACKSPACE]
Quit Lunar: [ESC]
    `
    c.SetRect(0, 4, 40, 12)
    c.TitleStyle.Fg = ui.ColorYellow
    c.BorderStyle.Fg = ui.ColorCyan

    ui.Render(p, c)

But this can create overlap over widgets:

+-Lunar--------------------------------+
|Playing Charlie Puth                  |
+--------------------------------------+
|Normal Speed: [Ctrl + N]              |
|Back to menu: [BACKSPACE]             |
|Quit Lunar: [ESC]                     |
+--------------------------------------+

Preferred output:

+-Lunar--------------------------------+
|Playing Charlie Puth                  |
+--------------------------------------+

+-Audio Controls-----------------------+
|Pause and play music: [ENTER]         |
|Volume: [↓ ↑]                         |
|Speed:  [← →]                         |
|Normal Speed: [Ctrl + N]              |
|Back to menu: [BACKSPACE]             |
|Quit Lunar: [ESC]                     |
+--------------------------------------+

My idea is to create a container for the widgets like in the Fyne GUI to position the widgets and avoid widget overlap:

SetContent(NewVericalBox(c, p))