The beginnings of a layout system

This commit is contained in:
Sasha Koshka
2023-01-10 16:39:37 -05:00
parent b1fd021120
commit 6eed70e79e
4 changed files with 244 additions and 123 deletions

22
tomo.go
View File

@@ -150,6 +150,28 @@ type Window interface {
OnClose (func ())
}
// LayoutEntry associates an element with layout and positioning information so
// it can be arranged by a Layout.
type LayoutEntry struct {
Element
Position image.Point
Expand bool
}
// Layout is capable of arranging elements within a container. It is also able
// to determine the minimum amount of room it needs to do so.
type Layout interface {
// Arrange takes in a slice of entries and a bounding width and height,
// and changes the position of the entiries in the slice so that they
// are properly laid out. The given width and height should not be less
// than what is returned by MinimumSize.
Arrange (entries []LayoutEntry, width, height int)
// MinimumSize returns the minimum width and height that the layout
// needs to properly arrange the given slice of layout entries.
MinimumSize (entries []LayoutEntry) (width, height int)
}
var backend Backend
// Run initializes a backend, calls the callback function, and begins the event