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:
Elias Naur
2023-10-06 18:07:22 -05:00
parent b66dcc436c
commit e1b3928819
8 changed files with 22 additions and 22 deletions
+3 -3
View File
@@ -84,7 +84,7 @@ const (
TypeSemanticDesc TypeSemanticDesc
TypeSemanticClass TypeSemanticClass
TypeSemanticSelected TypeSemanticSelected
TypeSemanticDisabled TypeSemanticEnabled
TypeSnippet TypeSnippet
TypeSelection TypeSelection
TypeActionInput TypeActionInput
@@ -170,7 +170,7 @@ const (
TypeSemanticDescLen = 1 TypeSemanticDescLen = 1
TypeSemanticClassLen = 2 TypeSemanticClassLen = 2
TypeSemanticSelectedLen = 2 TypeSemanticSelectedLen = 2
TypeSemanticDisabledLen = 2 TypeSemanticEnabledLen = 2
TypeSnippetLen = 1 + 4 + 4 TypeSnippetLen = 1 + 4 + 4
TypeSelectionLen = 1 + 2*4 + 2*4 + 4 + 4 TypeSelectionLen = 1 + 2*4 + 2*4 + 4 + 4
TypeActionInputLen = 1 + 1 TypeActionInputLen = 1 + 1
@@ -454,7 +454,7 @@ var opProps = [0x100]opProp{
TypeSemanticDesc: {Size: TypeSemanticDescLen, NumRefs: 1}, TypeSemanticDesc: {Size: TypeSemanticDescLen, NumRefs: 1},
TypeSemanticClass: {Size: TypeSemanticClassLen, NumRefs: 0}, TypeSemanticClass: {Size: TypeSemanticClassLen, NumRefs: 0},
TypeSemanticSelected: {Size: TypeSemanticSelectedLen, NumRefs: 0}, TypeSemanticSelected: {Size: TypeSemanticSelectedLen, NumRefs: 0},
TypeSemanticDisabled: {Size: TypeSemanticDisabledLen, NumRefs: 0}, TypeSemanticEnabled: {Size: TypeSemanticEnabledLen, NumRefs: 0},
TypeSnippet: {Size: TypeSnippetLen, NumRefs: 2}, TypeSnippet: {Size: TypeSnippetLen, NumRefs: 2},
TypeSelection: {Size: TypeSelectionLen, NumRefs: 1}, TypeSelection: {Size: TypeSelectionLen, NumRefs: 1},
TypeActionInput: {Size: TypeActionInputLen, NumRefs: 0}, TypeActionInput: {Size: TypeActionInputLen, NumRefs: 0},
+2 -2
View File
@@ -309,11 +309,11 @@ func (c *pointerCollector) semanticSelected(selected bool) {
area.semantic.content.selected = selected area.semantic.content.selected = selected
} }
func (c *pointerCollector) semanticDisabled(disabled bool) { func (c *pointerCollector) semanticEnabled(enabled bool) {
areaID := c.currentArea() areaID := c.currentArea()
area := &c.q.areas[areaID] area := &c.q.areas[areaID]
area.semantic.valid = true area.semantic.valid = true
area.semantic.content.disabled = disabled area.semantic.content.disabled = !enabled
} }
func (c *pointerCollector) cursor(cursor pointer.Cursor) { func (c *pointerCollector) cursor(cursor pointer.Cursor) {
+3 -3
View File
@@ -546,11 +546,11 @@ func (q *Router) collect() {
} else { } else {
pc.semanticSelected(false) pc.semanticSelected(false)
} }
case ops.TypeSemanticDisabled: case ops.TypeSemanticEnabled:
if encOp.Data[1] != 0 { if encOp.Data[1] != 0 {
pc.semanticDisabled(true) pc.semanticEnabled(true)
} else { } else {
pc.semanticDisabled(false) pc.semanticEnabled(false)
} }
} }
} }
+1 -1
View File
@@ -78,7 +78,7 @@ func TestSemanticDescription(t *testing.T) {
semantic.DescriptionOp("description").Add(&ops) semantic.DescriptionOp("description").Add(&ops)
semantic.LabelOp("label").Add(&ops) semantic.LabelOp("label").Add(&ops)
semantic.Button.Add(&ops) semantic.Button.Add(&ops)
semantic.DisabledOp(true).Add(&ops) semantic.EnabledOp(false).Add(&ops)
semantic.SelectedOp(true).Add(&ops) semantic.SelectedOp(true).Add(&ops)
var r Router var r Router
r.Frame(&ops) r.Frame(&ops)
+6 -6
View File
@@ -36,8 +36,8 @@ const (
// boolean state. // boolean state.
type SelectedOp bool type SelectedOp bool
// DisabledOp describes the disabled state. // EnabledOp describes the enabled state.
type DisabledOp bool type EnabledOp bool
func (l LabelOp) Add(o *op.Ops) { func (l LabelOp) Add(o *op.Ops) {
data := ops.Write1String(&o.Internal, ops.TypeSemanticLabelLen, string(l)) 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) { func (e EnabledOp) Add(o *op.Ops) {
data := ops.Write(&o.Internal, ops.TypeSemanticDisabledLen) data := ops.Write(&o.Internal, ops.TypeSemanticEnabledLen)
data[0] = byte(ops.TypeSemanticDisabled) data[0] = byte(ops.TypeSemanticEnabled)
if d { if e {
data[1] = 1 data[1] = 1
} }
} }
+1 -1
View File
@@ -49,7 +49,7 @@ func (b *Bool) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
b.changed = true b.changed = true
} }
semantic.SelectedOp(b.Value).Add(gtx.Ops) 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 w(gtx)
}) })
return dims return dims
+3 -3
View File
@@ -113,10 +113,10 @@ func (b *Clickable) Layout(gtx layout.Context, w layout.Widget) layout.Dimension
dims := w(gtx) dims := w(gtx)
c := m.Stop() c := m.Stop()
defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop() defer clip.Rect(image.Rectangle{Max: dims.Size}).Push(gtx.Ops).Pop()
disabled := gtx.Queue == nil enabled := gtx.Queue != nil
semantic.DisabledOp(disabled).Add(gtx.Ops) semantic.EnabledOp(enabled).Add(gtx.Ops)
b.click.Add(gtx.Ops) b.click.Add(gtx.Ops)
if !disabled { if enabled {
keys := key.Set("⏎|Space") keys := key.Set("⏎|Space")
if !b.focused { if !b.focused {
keys = "" keys = ""
+3 -3
View File
@@ -116,14 +116,14 @@ func (e *Enum) Layout(gtx layout.Context, k string, content layout.Widget) layou
} }
clk.Add(gtx.Ops) clk.Add(gtx.Ops)
disabled := gtx.Queue == nil enabled := gtx.Queue != nil
if !disabled { if enabled {
key.InputOp{Tag: &state.tag, Keys: "⏎|Space"}.Add(gtx.Ops) key.InputOp{Tag: &state.tag, Keys: "⏎|Space"}.Add(gtx.Ops)
} else if e.focus == k { } else if e.focus == k {
e.focused = false e.focused = false
} }
semantic.SelectedOp(k == e.Value).Add(gtx.Ops) semantic.SelectedOp(k == e.Value).Add(gtx.Ops)
semantic.DisabledOp(disabled).Add(gtx.Ops) semantic.EnabledOp(enabled).Add(gtx.Ops)
c.Add(gtx.Ops) c.Add(gtx.Ops)
return dims return dims