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 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 { type Object interface {
Box () Box Box () Box
} }
// Box is a basic styled box.
type Box interface { type Box interface {
Object Object
@ -136,28 +139,38 @@ type Box interface {
OnScroll (func (deltaX, deltaY float64)) event.Cookie OnScroll (func (deltaX, deltaY float64)) event.Cookie
OnKeyDown (func (key input.Key, numberPad bool)) event.Cookie OnKeyDown (func (key input.Key, numberPad bool)) event.Cookie
OnKeyUp (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 { type CanvasBox interface {
Box Box
SetDrawer (canvas.Drawer) SetDrawer (canvas.Drawer)
Invalidate () 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 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) SetGap (Gap)
Add (Object) Add (Object)
Delete (Object) Delete (Object)
@ -168,6 +181,12 @@ type ContainerBox interface {
SetLayout (Layout) 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 { type Window interface {
SetRoot (Object) SetRoot (Object)
SetTitle (string) SetTitle (string)
@ -183,11 +202,8 @@ type Window interface {
OnClose (func ()) event.Cookie OnClose (func ()) event.Cookie
} }
// MainWindow is a top-level operating system window.
type MainWindow interface { type MainWindow interface {
Window Window
NewChild (image.Rectangle) (Window, error) NewChild (image.Rectangle) (Window, error)
} }
type Layout interface {
Arrange (image.Rectangle, Gap, []Box)
}