forked from joejulian/gio
io/semantic: [API] replace DisabledOp with EnabledOp
The double-negative DisabledOp is harder to understand than a straightforward EnabledOp. Note that the absence of an EnabledOp implies still means that the widget is enabled. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+3
-3
@@ -84,7 +84,7 @@ const (
|
||||
TypeSemanticDesc
|
||||
TypeSemanticClass
|
||||
TypeSemanticSelected
|
||||
TypeSemanticDisabled
|
||||
TypeSemanticEnabled
|
||||
TypeSnippet
|
||||
TypeSelection
|
||||
TypeActionInput
|
||||
@@ -170,7 +170,7 @@ const (
|
||||
TypeSemanticDescLen = 1
|
||||
TypeSemanticClassLen = 2
|
||||
TypeSemanticSelectedLen = 2
|
||||
TypeSemanticDisabledLen = 2
|
||||
TypeSemanticEnabledLen = 2
|
||||
TypeSnippetLen = 1 + 4 + 4
|
||||
TypeSelectionLen = 1 + 2*4 + 2*4 + 4 + 4
|
||||
TypeActionInputLen = 1 + 1
|
||||
@@ -454,7 +454,7 @@ var opProps = [0x100]opProp{
|
||||
TypeSemanticDesc: {Size: TypeSemanticDescLen, NumRefs: 1},
|
||||
TypeSemanticClass: {Size: TypeSemanticClassLen, NumRefs: 0},
|
||||
TypeSemanticSelected: {Size: TypeSemanticSelectedLen, NumRefs: 0},
|
||||
TypeSemanticDisabled: {Size: TypeSemanticDisabledLen, NumRefs: 0},
|
||||
TypeSemanticEnabled: {Size: TypeSemanticEnabledLen, NumRefs: 0},
|
||||
TypeSnippet: {Size: TypeSnippetLen, NumRefs: 2},
|
||||
TypeSelection: {Size: TypeSelectionLen, NumRefs: 1},
|
||||
TypeActionInput: {Size: TypeActionInputLen, NumRefs: 0},
|
||||
|
||||
@@ -309,11 +309,11 @@ func (c *pointerCollector) semanticSelected(selected bool) {
|
||||
area.semantic.content.selected = selected
|
||||
}
|
||||
|
||||
func (c *pointerCollector) semanticDisabled(disabled bool) {
|
||||
func (c *pointerCollector) semanticEnabled(enabled bool) {
|
||||
areaID := c.currentArea()
|
||||
area := &c.q.areas[areaID]
|
||||
area.semantic.valid = true
|
||||
area.semantic.content.disabled = disabled
|
||||
area.semantic.content.disabled = !enabled
|
||||
}
|
||||
|
||||
func (c *pointerCollector) cursor(cursor pointer.Cursor) {
|
||||
|
||||
+3
-3
@@ -546,11 +546,11 @@ func (q *Router) collect() {
|
||||
} else {
|
||||
pc.semanticSelected(false)
|
||||
}
|
||||
case ops.TypeSemanticDisabled:
|
||||
case ops.TypeSemanticEnabled:
|
||||
if encOp.Data[1] != 0 {
|
||||
pc.semanticDisabled(true)
|
||||
pc.semanticEnabled(true)
|
||||
} else {
|
||||
pc.semanticDisabled(false)
|
||||
pc.semanticEnabled(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func TestSemanticDescription(t *testing.T) {
|
||||
semantic.DescriptionOp("description").Add(&ops)
|
||||
semantic.LabelOp("label").Add(&ops)
|
||||
semantic.Button.Add(&ops)
|
||||
semantic.DisabledOp(true).Add(&ops)
|
||||
semantic.EnabledOp(false).Add(&ops)
|
||||
semantic.SelectedOp(true).Add(&ops)
|
||||
var r Router
|
||||
r.Frame(&ops)
|
||||
|
||||
@@ -36,8 +36,8 @@ const (
|
||||
// boolean state.
|
||||
type SelectedOp bool
|
||||
|
||||
// DisabledOp describes the disabled state.
|
||||
type DisabledOp bool
|
||||
// EnabledOp describes the enabled state.
|
||||
type EnabledOp bool
|
||||
|
||||
func (l LabelOp) Add(o *op.Ops) {
|
||||
data := ops.Write1String(&o.Internal, ops.TypeSemanticLabelLen, string(l))
|
||||
@@ -63,10 +63,10 @@ func (s SelectedOp) Add(o *op.Ops) {
|
||||
}
|
||||
}
|
||||
|
||||
func (d DisabledOp) Add(o *op.Ops) {
|
||||
data := ops.Write(&o.Internal, ops.TypeSemanticDisabledLen)
|
||||
data[0] = byte(ops.TypeSemanticDisabled)
|
||||
if d {
|
||||
func (e EnabledOp) Add(o *op.Ops) {
|
||||
data := ops.Write(&o.Internal, ops.TypeSemanticEnabledLen)
|
||||
data[0] = byte(ops.TypeSemanticEnabled)
|
||||
if e {
|
||||
data[1] = 1
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ func (b *Bool) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
|
||||
b.changed = true
|
||||
}
|
||||
semantic.SelectedOp(b.Value).Add(gtx.Ops)
|
||||
semantic.DisabledOp(gtx.Queue == nil).Add(gtx.Ops)
|
||||
semantic.EnabledOp(gtx.Queue != nil).Add(gtx.Ops)
|
||||
return w(gtx)
|
||||
})
|
||||
return dims
|
||||
|
||||
+3
-3
@@ -113,10 +113,10 @@ func (b *Clickable) Layout(gtx layout.Context, w layout.Widget) layout.Dimension
|
||||
dims := w(gtx)
|
||||
c := m.Stop()
|
||||
defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop()
|
||||
disabled := gtx.Queue == nil
|
||||
semantic.DisabledOp(disabled).Add(gtx.Ops)
|
||||
enabled := gtx.Queue != nil
|
||||
semantic.EnabledOp(enabled).Add(gtx.Ops)
|
||||
b.click.Add(gtx.Ops)
|
||||
if !disabled {
|
||||
if enabled {
|
||||
keys := key.Set("⏎|Space")
|
||||
if !b.focused {
|
||||
keys = ""
|
||||
|
||||
+3
-3
@@ -116,14 +116,14 @@ func (e *Enum) Layout(gtx layout.Context, k string, content layout.Widget) layou
|
||||
}
|
||||
|
||||
clk.Add(gtx.Ops)
|
||||
disabled := gtx.Queue == nil
|
||||
if !disabled {
|
||||
enabled := gtx.Queue != nil
|
||||
if enabled {
|
||||
key.InputOp{Tag: &state.tag, Keys: "⏎|Space"}.Add(gtx.Ops)
|
||||
} else if e.focus == k {
|
||||
e.focused = false
|
||||
}
|
||||
semantic.SelectedOp(k == e.Value).Add(gtx.Ops)
|
||||
semantic.DisabledOp(disabled).Add(gtx.Ops)
|
||||
semantic.EnabledOp(enabled).Add(gtx.Ops)
|
||||
c.Add(gtx.Ops)
|
||||
|
||||
return dims
|
||||
|
||||
Reference in New Issue
Block a user