90 lines
4.4 KiB
Go
90 lines
4.4 KiB
Go
package objects
|
|
|
|
import "git.tebibyte.media/tomo/tomo"
|
|
import "git.tebibyte.media/tomo/objects/layouts"
|
|
|
|
var _ tomo.ContentObject = new(Segment)
|
|
|
|
// Segment is an object that can contain other objects, and provides a way to
|
|
// categorize the functionality of a window. Segments are typically laid out
|
|
// vertically in a window. There are several variants, the main one being
|
|
// the content segment. They can all be created using specialized constructors.
|
|
//
|
|
// The following is a brief visual discription of how they are typically used,
|
|
// and in what order:
|
|
//
|
|
// ┌──────────────────────────┐
|
|
// │ ┌──┐ ┌──┐ ┌────────────┐ ├─ command
|
|
// │ │◄─│ │─►│ │/foo/bar/baz│ │
|
|
// │ └──┘ └──┘ └────────────┘ │
|
|
// ├──────────────────────────┤
|
|
// │ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ├─ content
|
|
// │ │ │ │ │ │ │ │ │ │
|
|
// │ └───┘ └───┘ └───┘ └───┘ │
|
|
// │ ┌───┐ │
|
|
// │ │ │ │
|
|
// │ └───┘ │
|
|
// ├──────────────────────────┤
|
|
// │ 5 items, 4KiB ├─ status
|
|
// └──────────────────────────┘
|
|
// ┌─────────────────┐
|
|
// │ ┌───┐ │
|
|
// │ │ ! │ Continue? │
|
|
// │ └───┘ │
|
|
// ├─────────────────┤
|
|
// │ ┌──┐ ┌───┐ ├────────── option
|
|
// │ │No│ │Yes│ │
|
|
// │ └──┘ └───┘ │
|
|
// └─────────────────┘
|
|
//
|
|
// Tags:
|
|
// - [command] The segment is a command segment.
|
|
// - [content] The segment is a content segment.
|
|
// - [status] The segment is a status segment.
|
|
// - [option] The segment is an option segment.
|
|
type Segment struct {
|
|
abstractContainer
|
|
}
|
|
|
|
func newSegment (kind string, layout tomo.Layout, children ...tomo.Object) *Segment {
|
|
segment := &Segment { }
|
|
segment.init(layout, children...)
|
|
segment.box.SetRole(tomo.R("objects", "Segment"))
|
|
segment.box.SetTag(kind, true)
|
|
return segment
|
|
}
|
|
|
|
// NewCommandSegment creates a new segment intended to hold the window's
|
|
// navigational controls and command functionality. If the provided layout is
|
|
// nil, it will use a ContractHorizontal layout.
|
|
func NewCommandSegment (layout tomo.Layout, children ...tomo.Object) *Segment {
|
|
if layout == nil { layout = layouts.ContractHorizontal }
|
|
return newSegment("command", layout, children...)
|
|
}
|
|
|
|
// NewContentSegment creates a new segment intended to hold the window's main
|
|
// content. If the provided layout is nil, it will use a ContractVertical
|
|
// layout.
|
|
func NewContentSegment (layout tomo.Layout, children ...tomo.Object) *Segment {
|
|
if layout == nil { layout = layouts.ContractVertical }
|
|
return newSegment("content", layout, children...)
|
|
}
|
|
|
|
// NewStatusSegment creates a new segment intended to display the window's
|
|
// status. If the provided layout is nil, it will use a ContractHorizontal
|
|
// layout.
|
|
func NewStatusSegment (layout tomo.Layout, children ...tomo.Object) *Segment {
|
|
if layout == nil { layout = layouts.ContractHorizontal }
|
|
return newSegment("status", layout, children...)
|
|
}
|
|
|
|
// NewOptionSegment creates a new segment intended to hold the window's options.
|
|
// This is typically used for dialog boxes. If the provided layout is nil, it
|
|
// will use a ContractHorizontal layout. By default, it is end-aligned.
|
|
func NewOptionSegment (layout tomo.Layout, children ...tomo.Object) *Segment {
|
|
if layout == nil { layout = layouts.ContractHorizontal }
|
|
segment := newSegment("option", layout, children...)
|
|
segment.GetBox().SetAttr(tomo.AAlign(tomo.AlignEnd, tomo.AlignMiddle))
|
|
return segment
|
|
}
|