mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
app,io/system,layout: [API] move FrameEvent and Insets to package app
In the early days of Gio, FrameEvent was part of package app. It was moved to package system to enable layout.NewContext be a convenient short-hand for constructing a layout. However, it seems the better design to leave FrameEvent (and Insets) in package app, and move layout.NewContext there as well. More importantly, the move allows us to replace the event.Queue interface with a concrete type. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
package layout
|
||||
|
||||
import (
|
||||
"image"
|
||||
"time"
|
||||
|
||||
"gioui.org/io/event"
|
||||
@@ -35,43 +34,6 @@ type Context struct {
|
||||
*op.Ops
|
||||
}
|
||||
|
||||
// NewContext is a shorthand for
|
||||
//
|
||||
// Context{
|
||||
// Ops: ops,
|
||||
// Now: e.Now,
|
||||
// Queue: e.Queue,
|
||||
// Config: e.Config,
|
||||
// Constraints: Exact(e.Size),
|
||||
// }
|
||||
//
|
||||
// NewContext calls ops.Reset and adjusts ops for e.Insets.
|
||||
func NewContext(ops *op.Ops, e system.FrameEvent) Context {
|
||||
ops.Reset()
|
||||
|
||||
size := e.Size
|
||||
|
||||
if e.Insets != (system.Insets{}) {
|
||||
left := e.Metric.Dp(e.Insets.Left)
|
||||
top := e.Metric.Dp(e.Insets.Top)
|
||||
op.Offset(image.Point{
|
||||
X: left,
|
||||
Y: top,
|
||||
}).Add(ops)
|
||||
|
||||
size.X -= left + e.Metric.Dp(e.Insets.Right)
|
||||
size.Y -= top + e.Metric.Dp(e.Insets.Bottom)
|
||||
}
|
||||
|
||||
return Context{
|
||||
Ops: ops,
|
||||
Now: e.Now,
|
||||
Queue: e.Queue,
|
||||
Metric: e.Metric,
|
||||
Constraints: Exact(size),
|
||||
}
|
||||
}
|
||||
|
||||
// Dp converts v to pixels.
|
||||
func (c Context) Dp(v unit.Dp) int {
|
||||
return c.Metric.Dp(v)
|
||||
|
||||
Reference in New Issue
Block a user