Add a ton more doc comments
This commit is contained in:
parent
d1b62f5560
commit
2b99a98a8e
|
@ -8,24 +8,24 @@ import "image/color"
|
||||||
|
|
||||||
// Cap represents a stroke cap type.
|
// Cap represents a stroke cap type.
|
||||||
type Cap int; const (
|
type Cap int; const (
|
||||||
CapButt Cap = iota
|
CapButt Cap = iota // Square cap that ends at the point
|
||||||
CapRound
|
CapRound // Round cap that surrounds the point
|
||||||
CapSquare
|
CapSquare // square cap that surrounds the point
|
||||||
)
|
)
|
||||||
|
|
||||||
// Joint represents a stroke joint type.
|
// Joint represents a stroke joint type.
|
||||||
type Joint int; const (
|
type Joint int; const (
|
||||||
JointRount Joint = iota
|
JointRount Joint = iota // Rounded joint
|
||||||
JointSharp
|
JointSharp // Sharp joint
|
||||||
JointMiter
|
JointMiter // Clipped/beveled joint
|
||||||
)
|
)
|
||||||
|
|
||||||
// StrokeAlign determines whether a stroke is drawn inside, outside, or on a
|
// StrokeAlign determines whether a stroke is drawn inside, outside, or on a
|
||||||
// path.
|
// path.
|
||||||
type StrokeAlign int; const (
|
type StrokeAlign int; const (
|
||||||
StrokeAlignCenter StrokeAlign = iota
|
StrokeAlignCenter StrokeAlign = iota // Centered on the path
|
||||||
StrokeAlignInner
|
StrokeAlignInner // Inset into the path
|
||||||
StrokeAlignOuter
|
StrokeAlignOuter // Outset around the path
|
||||||
)
|
)
|
||||||
|
|
||||||
// Pen represents a drawing context that is linked to a canvas. Each canvas can
|
// Pen represents a drawing context that is linked to a canvas. Each canvas can
|
||||||
|
@ -44,9 +44,8 @@ type Pen interface {
|
||||||
StrokeWeight (int) // how thick the stroke is
|
StrokeWeight (int) // how thick the stroke is
|
||||||
StrokeAlign (StrokeAlign) // where the stroke is drawn
|
StrokeAlign (StrokeAlign) // where the stroke is drawn
|
||||||
|
|
||||||
// set the stroke/fill to a solid color
|
Stroke (color.Color) // Sets the stroke to a solid color
|
||||||
Stroke (color.Color)
|
Fill (color.Color) // Sets the fill to a solid color
|
||||||
Fill (color.Color)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Canvas is an image that supports drawing paths.
|
// Canvas is an image that supports drawing paths.
|
||||||
|
@ -62,6 +61,7 @@ type Canvas interface {
|
||||||
|
|
||||||
// Drawer is an object that can draw to a canvas.
|
// Drawer is an object that can draw to a canvas.
|
||||||
type Drawer interface {
|
type Drawer interface {
|
||||||
|
// Draw draws to the given canvas.
|
||||||
Draw (Canvas)
|
Draw (Canvas)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,10 @@ func (mime Mime) String () string {
|
||||||
return mime.Type + "/" + mime.Subtype
|
return mime.Type + "/" + mime.Subtype
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MimePlain returns the MIME type of plain text.
|
||||||
func MimePlain () Mime { return Mime { "text", "plain" } }
|
func MimePlain () Mime { return Mime { "text", "plain" } }
|
||||||
|
|
||||||
|
// MimeFile returns the MIME type of a file path/URI.
|
||||||
func MimeFile () Mime { return Mime { "text", "uri-list" } }
|
func MimeFile () Mime { return Mime { "text", "uri-list" } }
|
||||||
|
|
||||||
type byteReadCloser struct { *bytes.Reader }
|
type byteReadCloser struct { *bytes.Reader }
|
||||||
|
|
157
object.go
157
object.go
|
@ -111,25 +111,66 @@ type Object interface {
|
||||||
type Box interface {
|
type Box interface {
|
||||||
Object
|
Object
|
||||||
|
|
||||||
|
// Window returns the Window this Box is a part of.
|
||||||
Window () Window
|
Window () Window
|
||||||
|
// Bounds returns the outer bounding rectangle of the Box relative to
|
||||||
|
// the Window.
|
||||||
Bounds () image.Rectangle
|
Bounds () image.Rectangle
|
||||||
|
// InnerBounds returns the inner bounding rectangle of the box. It is
|
||||||
|
// the value of Bounds inset by the Box's border and padding.
|
||||||
InnerBounds () image.Rectangle
|
InnerBounds () image.Rectangle
|
||||||
|
// MinimumSize returns the minimum width and height this Box's bounds
|
||||||
|
// can be set to. This will return the value of whichever of these is
|
||||||
|
// greater:
|
||||||
|
// - The size as set by SetMinimumSize
|
||||||
|
// - The size taken up by the Box's border and padding. If there is
|
||||||
|
// internal content that does not overflow, the size of that is also
|
||||||
|
// taken into account here.
|
||||||
MinimumSize () image.Point
|
MinimumSize () image.Point
|
||||||
|
// SetBounds sets the bounding rectangle of this Box relative to the
|
||||||
|
// Window.
|
||||||
SetBounds (image.Rectangle)
|
SetBounds (image.Rectangle)
|
||||||
|
// SetColor sets the background color of this Box.
|
||||||
SetColor (color.Color)
|
SetColor (color.Color)
|
||||||
|
// SetBorder sets the Border(s) of the box. The first Border will be the
|
||||||
|
// most outset, and the last Border will be the most inset.
|
||||||
SetBorder (...Border)
|
SetBorder (...Border)
|
||||||
|
// SetMinimumSize sets the minimum width and height of the box, as
|
||||||
|
// described in MinimumSize.
|
||||||
SetMinimumSize (image.Point)
|
SetMinimumSize (image.Point)
|
||||||
|
// SetPadding sets the padding between the Box's innermost Border and
|
||||||
|
// its content.
|
||||||
SetPadding (Inset)
|
SetPadding (Inset)
|
||||||
|
|
||||||
|
// SetDNDData sets the data that will be picked up if this Box is
|
||||||
|
// dragged. If this is nil (which is the default), this Box will not be
|
||||||
|
// picked up.
|
||||||
SetDNDData (data.Data)
|
SetDNDData (data.Data)
|
||||||
|
// SetDNDAccept sets the type of data that can be dropped onto this Box.
|
||||||
|
// If this is nil (which is the default), this Box will reject all
|
||||||
|
// drops.
|
||||||
SetDNDAccept (...data.Mime)
|
SetDNDAccept (...data.Mime)
|
||||||
|
// SetFocused sets whether or not this Box has keyboard focus. If set to
|
||||||
|
// true, this method will steal focus away from whichever Object
|
||||||
|
// currently has focus.
|
||||||
SetFocused (bool)
|
SetFocused (bool)
|
||||||
|
// SetFocusable sets whether or not this Box can receive keyboard focus.
|
||||||
|
// If set to false and the Box is already focused. the focus is removed.
|
||||||
SetFocusable (bool)
|
SetFocusable (bool)
|
||||||
|
|
||||||
|
// Focused returns whether or not this Box has keyboard focus.
|
||||||
Focused () bool
|
Focused () bool
|
||||||
|
// Modifiers returns which modifier keys on the keyboard are currently
|
||||||
|
// being held down.
|
||||||
Modifiers () input.Modifiers
|
Modifiers () input.Modifiers
|
||||||
|
// MousePosition returns the position of the mouse pointer relative to
|
||||||
|
// the Window.
|
||||||
MousePosition () image.Point
|
MousePosition () image.Point
|
||||||
|
|
||||||
|
// These are event subscription functions that allow callbacks to be
|
||||||
|
// connected to particular events. Multiple callbacks may be connected
|
||||||
|
// to the same event at once. Callbacks can be removed by closing the
|
||||||
|
// returned cookie.
|
||||||
OnFocusEnter (func ()) event.Cookie
|
OnFocusEnter (func ()) event.Cookie
|
||||||
OnFocusLeave (func ()) event.Cookie
|
OnFocusLeave (func ()) event.Cookie
|
||||||
OnDNDEnter (func ()) event.Cookie
|
OnDNDEnter (func ()) event.Cookie
|
||||||
|
@ -148,7 +189,13 @@ type Box interface {
|
||||||
// CanvasBox is a box that can be drawn to.
|
// CanvasBox is a box that can be drawn to.
|
||||||
type CanvasBox interface {
|
type CanvasBox interface {
|
||||||
Box
|
Box
|
||||||
|
|
||||||
|
// SetDrawer sets the Drawer that will be called upon to draw the Box's
|
||||||
|
// content when it is invalidated.
|
||||||
SetDrawer (canvas.Drawer)
|
SetDrawer (canvas.Drawer)
|
||||||
|
|
||||||
|
// Invalidate causes the Box's area to be redrawn at the end of the
|
||||||
|
// event cycle, even if it wouldn't be otherwise.
|
||||||
Invalidate ()
|
Invalidate ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,77 +203,151 @@ type CanvasBox interface {
|
||||||
// is to be embedded into TextBox and ContainerBox.
|
// is to be embedded into TextBox and ContainerBox.
|
||||||
type ContentBox interface {
|
type ContentBox interface {
|
||||||
Box
|
Box
|
||||||
|
|
||||||
|
// SetOverflow sets whether or not the Box's content overflows
|
||||||
|
// horizontally and vertically. Overflowing content is clipped to the
|
||||||
|
// bounds of the Box inset by all Borders (but not padding).
|
||||||
SetOverflow (horizontal, vertical bool)
|
SetOverflow (horizontal, vertical bool)
|
||||||
ContentBounds () image.Rectangle
|
// SetAlign sets how the Box's content is distributed horizontally and
|
||||||
ScrollTo (image.Point)
|
// vertically.
|
||||||
OnContentBoundsChange (func ()) event.Cookie
|
|
||||||
SetAlign (x, y Align)
|
SetAlign (x, y Align)
|
||||||
|
// ContentBounds returns the bounds of the inner content of the Box
|
||||||
|
// relative to the window.
|
||||||
|
ContentBounds () image.Rectangle
|
||||||
|
// ScrollTo shifts the origin of the Box's content to the origin of the
|
||||||
|
// Box's InnerBounds, offset by the given point.
|
||||||
|
ScrollTo (image.Point)
|
||||||
|
// OnContentBoundsChange specifies a function to be called when the
|
||||||
|
// Box's ContentBounds or InnerBounds changes.
|
||||||
|
OnContentBoundsChange (func ()) event.Cookie
|
||||||
}
|
}
|
||||||
|
|
||||||
// TextBox is a box that contains text content.
|
// TextBox is a box that contains text content.
|
||||||
type TextBox interface {
|
type TextBox interface {
|
||||||
ContentBox
|
ContentBox
|
||||||
|
|
||||||
|
// SetText sets the text content of the Box.
|
||||||
SetText (string)
|
SetText (string)
|
||||||
|
// SetTextColor sets the text color.
|
||||||
SetTextColor (color.Color)
|
SetTextColor (color.Color)
|
||||||
|
// SetFace sets the font face text is rendered in.
|
||||||
SetFace (font.Face)
|
SetFace (font.Face)
|
||||||
|
// SetWrap sets whether or not the text wraps.
|
||||||
SetWrap (bool)
|
SetWrap (bool)
|
||||||
|
|
||||||
|
// SetSelectable sets whether or not the text content can be
|
||||||
|
// highlighted/selected.
|
||||||
SetSelectable (bool)
|
SetSelectable (bool)
|
||||||
|
// Select sets the text cursor or selection.
|
||||||
Select (text.Dot)
|
Select (text.Dot)
|
||||||
|
// Dot returns the text cursor or selection.
|
||||||
Dot () text.Dot
|
Dot () text.Dot
|
||||||
|
// OnDotChange specifies a function to be called when the text cursor or
|
||||||
|
// selection changes.
|
||||||
OnDotChange (func ()) event.Cookie
|
OnDotChange (func ()) event.Cookie
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContentBox is a box that can contain child objects. It arranges them
|
// ContentBox is a box that can contain child Objects. It arranges them
|
||||||
// according to a layout rule.
|
// according to a layout rule.
|
||||||
type ContainerBox interface {
|
type ContainerBox interface {
|
||||||
ContentBox
|
ContentBox
|
||||||
PropagateEvents (bool)
|
|
||||||
SetGap (image.Point)
|
// SetPropagateEvents specifies whether or not child Objects will
|
||||||
Add (Object)
|
// receive user input events. It is true by default. If it is false, all
|
||||||
Delete (Object)
|
// user input that would otherwise be directed to a child Box is
|
||||||
Insert (child Object, before Object)
|
// directed to this Box.
|
||||||
Clear ()
|
SetPropagateEvents (bool)
|
||||||
Length () int
|
// SetGap sets the gap between child Objects.
|
||||||
At (int) Object
|
SetGap (image.Point)
|
||||||
SetLayout (Layout)
|
// Add appends a child Object.
|
||||||
|
Add (Object)
|
||||||
|
// Delete removes a child Object, if it is a child of this Box.
|
||||||
|
Delete (Object)
|
||||||
|
// Insert inserts a child Object before a specified Object. If the
|
||||||
|
// before Object is nil or is not contained within this Box, the
|
||||||
|
// inserted Object is appended.
|
||||||
|
Insert (child Object, before Object)
|
||||||
|
// Clear removes all child Objects.
|
||||||
|
Clear ()
|
||||||
|
// Length returns the amount of child objects.
|
||||||
|
Length () int
|
||||||
|
// At returns the child Object at the specified index.
|
||||||
|
At (int) Object
|
||||||
|
// SetLayout sets the layout of this Box. Child Objects will be
|
||||||
|
// positioned according to it.
|
||||||
|
SetLayout (Layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LayoutHints are passed to a layout to tell it how to arrange child boxes.
|
// LayoutHints are passed to a layout to tell it how to arrange child boxes.
|
||||||
type LayoutHints struct {
|
type LayoutHints struct {
|
||||||
|
// Bounds is the bounding rectangle that children should be placed
|
||||||
|
// within. Any padding values are already applied.
|
||||||
Bounds image.Rectangle
|
Bounds image.Rectangle
|
||||||
|
// OverflowX and OverflowY control wether child Boxes may be positioned
|
||||||
|
// outside of Bounds.
|
||||||
OverflowX bool
|
OverflowX bool
|
||||||
OverflowY bool
|
OverflowY bool
|
||||||
|
// AlignX and AlignY control how child Boxes are aligned horizontally
|
||||||
|
// and vertically. The effect of this may vary depending on the Layout.
|
||||||
AlignX Align
|
AlignX Align
|
||||||
AlignY Align
|
AlignY Align
|
||||||
|
// Gap controls the amount of horizontal and vertical spacing in-between
|
||||||
|
// child Boxes.
|
||||||
Gap image.Point
|
Gap image.Point
|
||||||
}
|
}
|
||||||
|
|
||||||
// Layout can be given to a ContainerBox to arrange child objects.
|
// A Layout can be given to a ContainerBox to arrange child objects.
|
||||||
type Layout interface {
|
type Layout interface {
|
||||||
|
// MinimumSize returns the minimum width and height of
|
||||||
|
// LayoutHints.Bounds needed to properly lay out all child Boxes.
|
||||||
MinimumSize (LayoutHints, []Box) image.Point
|
MinimumSize (LayoutHints, []Box) image.Point
|
||||||
|
// Arrange arranges child boxes according to the given LayoutHints.
|
||||||
Arrange (LayoutHints, []Box)
|
Arrange (LayoutHints, []Box)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Window is an operating system window. It can contain one object.
|
// Window is an operating system window. It can contain one object.
|
||||||
type Window interface {
|
type Window interface {
|
||||||
|
// SetRoot sets the root child of the window. There can only be one at
|
||||||
|
// a time, and setting it will remove the current child if there is one.
|
||||||
SetRoot (Object)
|
SetRoot (Object)
|
||||||
|
// SetTitle sets the title of the window.
|
||||||
SetTitle (string)
|
SetTitle (string)
|
||||||
SetIcon (sizes []image.Image)
|
// SetIcon sets the icon of the window. When multiple icon sizes are
|
||||||
NewMenu (image.Rectangle) (Window, error)
|
// provided, the best fitting one is chosen for display.
|
||||||
NewModal (image.Rectangle) (Window, error)
|
SetIcon (... image.Image)
|
||||||
|
// Widget returns a window representing a smaller iconified form of this
|
||||||
|
// window. How exactly this window is used depends on the platform.
|
||||||
|
// Subsequent calls to this method on the same window will return the
|
||||||
|
// same window object.
|
||||||
Widget () (Window, error)
|
Widget () (Window, error)
|
||||||
|
// NewMenu creates a new menu window. This window is undecorated and
|
||||||
|
// will close once the user clicks outside of it.
|
||||||
|
NewMenu (image.Rectangle) (Window, error)
|
||||||
|
// NewModal creates a new modal window that blocks all input to this
|
||||||
|
// window until it is closed.
|
||||||
|
NewModal (image.Rectangle) (Window, error)
|
||||||
|
// Copy copies data to the clipboard.
|
||||||
Copy (data.Data)
|
Copy (data.Data)
|
||||||
|
// Paste reads data from the clipboard. When the data is available or an
|
||||||
|
// error has occurred, the provided function will be called.
|
||||||
Paste (callback func (data.Data, error), accept ...data.Mime)
|
Paste (callback func (data.Data, error), accept ...data.Mime)
|
||||||
|
// Show shows the window.
|
||||||
Show ()
|
Show ()
|
||||||
|
// Hide hides the window.
|
||||||
Hide ()
|
Hide ()
|
||||||
|
// Close closes the window.
|
||||||
Close ()
|
Close ()
|
||||||
|
// OnClose specifies a function to be called when the window is closed.
|
||||||
OnClose (func ()) event.Cookie
|
OnClose (func ()) event.Cookie
|
||||||
}
|
}
|
||||||
|
|
||||||
// MainWindow is a top-level operating system window.
|
// MainWindow is a top-level operating system window.
|
||||||
type MainWindow interface {
|
type MainWindow interface {
|
||||||
Window
|
Window
|
||||||
|
|
||||||
|
// NewChild creates a new window that is semantically a child of this
|
||||||
|
// window. It does not actually reside within this window, but it may be
|
||||||
|
// linked to it via some other means. This is intended for things like
|
||||||
|
// toolboxes and tear-off menus.
|
||||||
NewChild (image.Rectangle) (Window, error)
|
NewChild (image.Rectangle) (Window, error)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue