github.com/utopiagio/gio@v0.0.8/io/semantic/semantic.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 // Package semantic provides operations for semantic descriptions of a user 4 // interface, to facilitate presentation and interaction in external software 5 // such as screen readers. 6 // 7 // Semantic descriptions are organized in a tree, with clip operations as 8 // nodes. Operations in this package are associated with the current semantic 9 // node, that is the most recent pushed clip operation. 10 package semantic 11 12 import ( 13 "github.com/utopiagio/gio/internal/ops" 14 "github.com/utopiagio/gio/op" 15 ) 16 17 // LabelOp provides the content of a textual component. 18 type LabelOp string 19 20 // DescriptionOp describes a component. 21 type DescriptionOp string 22 23 // ClassOp provides the component class. 24 type ClassOp int 25 26 const ( 27 Unknown ClassOp = iota 28 Button 29 CheckBox 30 Editor 31 RadioButton 32 Switch 33 ) 34 35 // SelectedOp describes the selected state for components that have 36 // boolean state. 37 type SelectedOp bool 38 39 // EnabledOp describes the enabled state. 40 type EnabledOp bool 41 42 func (l LabelOp) Add(o *op.Ops) { 43 data := ops.Write1String(&o.Internal, ops.TypeSemanticLabelLen, string(l)) 44 data[0] = byte(ops.TypeSemanticLabel) 45 } 46 47 func (d DescriptionOp) Add(o *op.Ops) { 48 data := ops.Write1String(&o.Internal, ops.TypeSemanticDescLen, string(d)) 49 data[0] = byte(ops.TypeSemanticDesc) 50 } 51 52 func (c ClassOp) Add(o *op.Ops) { 53 data := ops.Write(&o.Internal, ops.TypeSemanticClassLen) 54 data[0] = byte(ops.TypeSemanticClass) 55 data[1] = byte(c) 56 } 57 58 func (s SelectedOp) Add(o *op.Ops) { 59 data := ops.Write(&o.Internal, ops.TypeSemanticSelectedLen) 60 data[0] = byte(ops.TypeSemanticSelected) 61 if s { 62 data[1] = 1 63 } 64 } 65 66 func (e EnabledOp) Add(o *op.Ops) { 67 data := ops.Write(&o.Internal, ops.TypeSemanticEnabledLen) 68 data[0] = byte(ops.TypeSemanticEnabled) 69 if e { 70 data[1] = 1 71 } 72 } 73 74 func (c ClassOp) String() string { 75 switch c { 76 case Unknown: 77 return "Unknown" 78 case Button: 79 return "Button" 80 case CheckBox: 81 return "CheckBox" 82 case Editor: 83 return "Editor" 84 case RadioButton: 85 return "RadioButton" 86 case Switch: 87 return "Switch" 88 default: 89 panic("invalid ClassOp") 90 } 91 }