This repository has been archived by the owner on May 18, 2023. It is now read-only.
forked from gowebapi/webapi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
orientation.go
234 lines (199 loc) · 6.71 KB
/
orientation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// Code generated by webidl-bind. DO NOT EDIT.
// +build !js
package orientation
import js "github.com/gowebapi/webapi/core/js"
import (
"github.com/gowebapi/webapi/dom/domcore"
"github.com/gowebapi/webapi/javascript"
)
// using following types:
// domcore.Event
// domcore.EventHandler
// domcore.EventTarget
// javascript.PromiseVoid
// source idl files:
// screen-orientation.idl
// transform files:
// screen-orientation.go.md
// workaround for compiler error
func unused(value interface{}) {
// TODO remove this method
}
type Union struct {
Value js.Value
}
func (u *Union) JSValue() js.Value {
return u.Value
}
func UnionFromJS(value js.Value) *Union {
return &Union{Value: value}
}
// enum: OrientationLockType
type OrientationLockType int
const (
AnyOrientationLockType OrientationLockType = iota
NaturalOrientationLockType
LandscapeOrientationLockType
PortraitOrientationLockType
PortraitPrimaryOrientationLockType
PortraitSecondaryOrientationLockType
LandscapePrimaryOrientationLockType
LandscapeSecondaryOrientationLockType
)
var orientationLockTypeToWasmTable = []string{
"any", "natural", "landscape", "portrait", "portrait-primary", "portrait-secondary", "landscape-primary", "landscape-secondary",
}
var orientationLockTypeFromWasmTable = map[string]OrientationLockType{
"any": AnyOrientationLockType, "natural": NaturalOrientationLockType, "landscape": LandscapeOrientationLockType, "portrait": PortraitOrientationLockType, "portrait-primary": PortraitPrimaryOrientationLockType, "portrait-secondary": PortraitSecondaryOrientationLockType, "landscape-primary": LandscapePrimaryOrientationLockType, "landscape-secondary": LandscapeSecondaryOrientationLockType,
}
// JSValue is converting this enum into a javascript object
func (this *OrientationLockType) JSValue() js.Value {
return js.ValueOf(this.Value())
}
// Value is converting this into javascript defined
// string value
func (this OrientationLockType) Value() string {
idx := int(this)
if idx >= 0 && idx < len(orientationLockTypeToWasmTable) {
return orientationLockTypeToWasmTable[idx]
}
panic("unknown input value")
}
// OrientationLockTypeFromJS is converting a javascript value into
// a OrientationLockType enum value.
func OrientationLockTypeFromJS(value js.Value) OrientationLockType {
key := value.String()
conv, ok := orientationLockTypeFromWasmTable[key]
if !ok {
panic("unable to convert '" + key + "'")
}
return conv
}
// enum: OrientationType
type OrientationType int
const (
PortraitPrimaryOrientationType OrientationType = iota
PortraitSecondaryOrientationType
LandscapePrimaryOrientationType
LandscapeSecondaryOrientationType
)
var orientationTypeToWasmTable = []string{
"portrait-primary", "portrait-secondary", "landscape-primary", "landscape-secondary",
}
var orientationTypeFromWasmTable = map[string]OrientationType{
"portrait-primary": PortraitPrimaryOrientationType, "portrait-secondary": PortraitSecondaryOrientationType, "landscape-primary": LandscapePrimaryOrientationType, "landscape-secondary": LandscapeSecondaryOrientationType,
}
// JSValue is converting this enum into a javascript object
func (this *OrientationType) JSValue() js.Value {
return js.ValueOf(this.Value())
}
// Value is converting this into javascript defined
// string value
func (this OrientationType) Value() string {
idx := int(this)
if idx >= 0 && idx < len(orientationTypeToWasmTable) {
return orientationTypeToWasmTable[idx]
}
panic("unknown input value")
}
// OrientationTypeFromJS is converting a javascript value into
// a OrientationType enum value.
func OrientationTypeFromJS(value js.Value) OrientationType {
key := value.String()
conv, ok := orientationTypeFromWasmTable[key]
if !ok {
panic("unable to convert '" + key + "'")
}
return conv
}
// class: ScreenOrientation
type ScreenOrientation struct {
domcore.EventTarget
}
// ScreenOrientationFromJS is casting a js.Wrapper into ScreenOrientation.
func ScreenOrientationFromJS(value js.Wrapper) *ScreenOrientation {
input := value.JSValue()
if typ := input.Type(); typ == js.TypeNull || typ == js.TypeUndefined {
return nil
}
ret := &ScreenOrientation{}
ret.Value_JS = input
return ret
}
// Type returning attribute 'type' with
// type OrientationType (idl: OrientationType).
func (_this *ScreenOrientation) Type() OrientationType {
var ret OrientationType
value := _this.Value_JS.Get("type")
ret = OrientationTypeFromJS(value)
return ret
}
// Angle returning attribute 'angle' with
// type int (idl: unsigned short).
func (_this *ScreenOrientation) Angle() int {
var ret int
value := _this.Value_JS.Get("angle")
ret = (value).Int()
return ret
}
// OnChange returning attribute 'onchange' with
// type domcore.EventHandler (idl: EventHandlerNonNull).
func (_this *ScreenOrientation) OnChange() domcore.EventHandlerFunc {
var ret domcore.EventHandlerFunc
value := _this.Value_JS.Get("onchange")
if value.Type() != js.TypeNull && value.Type() != js.TypeUndefined {
ret = domcore.EventHandlerFromJS(value)
}
return ret
}
// event attribute: domcore.Event
func eventFuncScreenOrientation_domcore_Event(listener func(event *domcore.Event, target *ScreenOrientation)) js.Func {
fn := func(this js.Value, args []js.Value) interface{} {
var ret *domcore.Event
value := args[0]
incoming := value.Get("target")
ret = domcore.EventFromJS(value)
src := ScreenOrientationFromJS(incoming)
listener(ret, src)
return js.Undefined
}
return js.FuncOf(fn)
}
// AddChange is adding doing AddEventListener for 'Change' on target.
// This method is returning allocated javascript function that need to be released.
func (_this *ScreenOrientation) AddEventChange(listener func(event *domcore.Event, currentTarget *ScreenOrientation)) js.Func {
cb := eventFuncScreenOrientation_domcore_Event(listener)
_this.Value_JS.Call("addEventListener", "change", cb)
return cb
}
// SetOnChange is assigning a function to 'onchange'. This
// This method is returning allocated javascript function that need to be released.
func (_this *ScreenOrientation) SetOnChange(listener func(event *domcore.Event, currentTarget *ScreenOrientation)) js.Func {
cb := eventFuncScreenOrientation_domcore_Event(listener)
_this.Value_JS.Set("onchange", cb)
return cb
}
func (_this *ScreenOrientation) Lock(orientation OrientationLockType) (_result *javascript.PromiseVoid) {
var (
_args [1]interface{}
_end int
)
_p0 := orientation.JSValue()
_args[0] = _p0
_end++
_returned := _this.Value_JS.Call("lock", _args[0:_end]...)
var (
_converted *javascript.PromiseVoid // javascript: PromiseVoid _what_return_name
)
_converted = javascript.PromiseVoidFromJS(_returned)
_result = _converted
return
}
func (_this *ScreenOrientation) Unlock() {
var (
_args [0]interface{}
_end int
)
_this.Value_JS.Call("unlock", _args[0:_end]...)
return
}