summaryrefslogtreecommitdiffstats
path: root/runtime/ui/layout
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/ui/layout')
-rw-r--r--runtime/ui/layout/vertical.go58
-rw-r--r--runtime/ui/layout/view.go10
2 files changed, 68 insertions, 0 deletions
diff --git a/runtime/ui/layout/vertical.go b/runtime/ui/layout/vertical.go
new file mode 100644
index 0000000..67d12f4
--- /dev/null
+++ b/runtime/ui/layout/vertical.go
@@ -0,0 +1,58 @@
+package layout
+
+import (
+ "fmt"
+ "github.com/wagoodman/dive/runtime/ui/view"
+)
+
+type Vertical struct {
+ visible bool
+ width int
+ elements []View
+}
+
+// how does overrun work? which view gets precidence? how does max possible height work?
+
+func NewVerticalLayout() *Vertical {
+ return &Vertical{
+ visible: true,
+ width: view.WidthFull,
+ elements: make([]View, 0),
+ }
+}
+
+func (v Vertical) SetWidth(w int) {
+ v.width = w
+}
+
+func (v *Vertical) AddView(sub View) error {
+ for _, element := range v.elements {
+ if element.Name() == sub.Name() {
+ return fmt.Errorf("view already added")
+ }
+ }
+ v.elements = append(v.elements, sub)
+ return nil
+}
+
+func (v *Vertical) Name() string {
+ return view.IdentityNone
+}
+
+func (v *Vertical) IsVisible() bool {
+ return v.visible
+}
+
+func (v *Vertical) Height() (height int) {
+ for _, element := range v.elements {
+ height += element.Height()
+ if height == view.HeightFull {
+ return view.HeightFull
+ }
+ }
+ return
+}
+
+func (v *Vertical) Width() int {
+ return v.width
+}
diff --git a/runtime/ui/layout/view.go b/runtime/ui/layout/view.go
new file mode 100644
index 0000000..62c5ef0
--- /dev/null
+++ b/runtime/ui/layout/view.go
@@ -0,0 +1,10 @@
+package layout
+
+import (
+ "github.com/wagoodman/dive/runtime/ui/view"
+)
+
+type View interface {
+ view.Identifiable
+ view.Dimensional
+}