From e1b39288198c1a440a121f274275d9e7e2dc8014 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 6 Oct 2023 18:07:22 -0500 Subject: [PATCH] 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 --- internal/ops/ops.go | 6 +++--- io/router/pointer.go | 4 ++-- io/router/router.go | 6 +++--- io/router/semantic_test.go | 2 +- io/semantic/semantic.go | 12 ++++++------ widget/bool.go | 2 +- widget/button.go | 6 +++--- widget/enum.go | 6 +++--- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/internal/ops/ops.go b/internal/ops/ops.go index 2d69bca84..068c9ee09 100644 --- a/internal/ops/ops.go +++ b/internal/ops/ops.go @@ -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}, diff --git a/io/router/pointer.go b/io/router/pointer.go index dd3269b0a..7d2034bbb 100644 --- a/io/router/pointer.go +++ b/io/router/pointer.go @@ -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) { diff --git a/io/router/router.go b/io/router/router.go index 0c691c7cf..181e0ae99 100644 --- a/io/router/router.go +++ b/io/router/router.go @@ -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) } } } diff --git a/io/router/semantic_test.go b/io/router/semantic_test.go index edc5dfbcc..bb6abd8f4 100644 --- a/io/router/semantic_test.go +++ b/io/router/semantic_test.go @@ -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) diff --git a/io/semantic/semantic.go b/io/semantic/semantic.go index 569446a2a..2562fe2d0 100644 --- a/io/semantic/semantic.go +++ b/io/semantic/semantic.go @@ -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 } } diff --git a/widget/bool.go b/widget/bool.go index ec8efaa9c..55045dc71 100644 --- a/widget/bool.go +++ b/widget/bool.go @@ -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 diff --git a/widget/button.go b/widget/button.go index 410ba2014..c45bc929f 100644 --- a/widget/button.go +++ b/widget/button.go @@ -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 = "" diff --git a/widget/enum.go b/widget/enum.go index 655bf4e09..97118bf94 100644 --- a/widget/enum.go +++ b/widget/enum.go @@ -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