ui: move macro recording from Ops to MacroOp

Move the Record and Stop methods from Ops to MacroOp itself.

Before this change, Ops.Stop stopped the recording of the most
recent macro, which could be a different macro than intended.
After this change, there is no such confusion.

As a bonus, the Ops API becomes less cluttered.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-07-16 13:00:56 +02:00
parent ba9ffe846e
commit 94a913a371
6 changed files with 67 additions and 62 deletions
+4 -3
View File
@@ -11,6 +11,7 @@ import (
type Stack struct {
Alignment Direction
macro ui.MacroOp
ops *ui.Ops
constrained bool
cs Constraints
@@ -54,7 +55,7 @@ func (s *Stack) begin() {
panic("must End before adding a child")
}
s.begun = true
s.ops.Record()
s.macro.Record(s.ops)
}
func (s *Stack) Rigid() Constraints {
@@ -71,7 +72,7 @@ func (s *Stack) Expand() Constraints {
}
func (s *Stack) End(dims Dimens) StackChild {
b := s.ops.Stop()
s.macro.Stop()
s.begun = false
if w := dims.Size.X; w > s.maxSZ.X {
s.maxSZ.X = w
@@ -84,7 +85,7 @@ func (s *Stack) End(dims Dimens) StackChild {
s.baseline = b
}
}
return StackChild{b, dims}
return StackChild{s.macro, dims}
}
func (s *Stack) Layout(children ...StackChild) Dimens {