Reorganized the box interfaces somewhat

This commit is contained in:
Sasha Koshka 2023-07-02 02:46:12 -04:00
parent 8b78d16506
commit 66e1caeebf
1 changed files with 33 additions and 17 deletions

View File

@ -98,10 +98,13 @@ type Align int; const (
AlignEven // similar to justified text
)
// Object is any obscreen object. Each object must be linked to a box, even if
// it is that box.
type Object interface {
Box () Box
}
// Box is a basic styled box.
type Box interface {
Object
@ -136,28 +139,38 @@ type Box interface {
OnScroll (func (deltaX, deltaY float64)) event.Cookie
OnKeyDown (func (key input.Key, numberPad bool)) event.Cookie
OnKeyUp (func (key input.Key, numberPad bool)) event.Cookie
ContentBounds () image.Rectangle
ScrollTo (image.Point)
OnContentBoundsChange (func ()) event.Cookie
}
type TextBox interface {
Box
SetTextColor (color.Color)
SetFace (font.Face)
SetHAlign (Align)
SetVAlign (Align)
}
// CanvasBox is a box that can be drawn to.
type CanvasBox interface {
Box
SetDrawer (canvas.Drawer)
Invalidate ()
}
type ContainerBox interface {
// ContentBox is an abstract box that has some kind of content. Its only purpose
// is to be embedded into TextBox and ContainerBox.
type ContentBox interface {
Box
SetOverflow (horizontal, vertical bool)
ContentBounds () image.Rectangle
ScrollTo (image.Point)
OnContentBoundsChange (func ()) event.Cookie
}
// TextBox is a box that contains text content.
type TextBox interface {
ContentBox
SetTextColor (color.Color)
SetFace (font.Face)
SetHAlign (Align)
SetVAlign (Align)
}
// ContentBox is a box that can contain child objects. It arranges them
// according to a layout rule.
type ContainerBox interface {
ContentBox
SetGap (Gap)
Add (Object)
Delete (Object)
@ -168,6 +181,12 @@ type ContainerBox interface {
SetLayout (Layout)
}
// Layout can be given to a ContainerBox to arrange child objects.
type Layout interface {
Arrange (image.Rectangle, Gap, []Box)
}
// Window is an operating system window. It can contain one object.
type Window interface {
SetRoot (Object)
SetTitle (string)
@ -183,11 +202,8 @@ type Window interface {
OnClose (func ()) event.Cookie
}
// MainWindow is a top-level operating system window.
type MainWindow interface {
Window
NewChild (image.Rectangle) (Window, error)
}
type Layout interface {
Arrange (image.Rectangle, Gap, []Box)
}