misc.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. // Copyright 2018 visualfc. All rights reserved.
  2. package tk
  3. type Pos struct {
  4. X int
  5. Y int
  6. }
  7. type Pad struct {
  8. X int
  9. Y int
  10. }
  11. type Size struct {
  12. Width int
  13. Height int
  14. }
  15. type Geometry struct {
  16. X int
  17. Y int
  18. Width int
  19. Height int
  20. }
  21. type Orient int
  22. const (
  23. Vertical Orient = iota
  24. Horizontal
  25. )
  26. var (
  27. orientName = []string{"vertical", "horizontal"}
  28. )
  29. func (v Orient) String() string {
  30. if v >= 0 && int(v) < len(orientName) {
  31. return orientName[v]
  32. }
  33. return ""
  34. }
  35. func parserOrientResult(r string, err error) Orient {
  36. if err != nil {
  37. return -1
  38. }
  39. for n, s := range orientName {
  40. if s == r {
  41. return Orient(n)
  42. }
  43. }
  44. return -1
  45. }
  46. type Justify int
  47. const (
  48. JustifyCenter Justify = iota
  49. JustifyLeft
  50. JustifyRight
  51. )
  52. var (
  53. alignmentName = []string{"center", "left", "right"}
  54. )
  55. func (v Justify) String() string {
  56. if v >= 0 && int(v) < len(alignmentName) {
  57. return alignmentName[v]
  58. }
  59. return ""
  60. }
  61. func parserJustifyResult(r string, err error) Justify {
  62. if err != nil {
  63. return -1
  64. }
  65. for n, s := range alignmentName {
  66. if s == r {
  67. return Justify(n)
  68. }
  69. }
  70. return -1
  71. }
  72. type Side int
  73. const (
  74. SideLeft Side = iota
  75. SideRight
  76. SideTop
  77. SideBottom
  78. )
  79. var (
  80. sideName = []string{"left", "right", "top", "bottom"}
  81. )
  82. func (v Side) String() string {
  83. if v >= 0 && int(v) < len(sideName) {
  84. return sideName[v]
  85. }
  86. return ""
  87. }
  88. func parserSideResult(r string, err error) Side {
  89. if err != nil {
  90. return -1
  91. }
  92. for n, s := range sideName {
  93. if s == r {
  94. return Side(n)
  95. }
  96. }
  97. return -1
  98. }
  99. type BorderMode int
  100. const (
  101. BorderModeInside BorderMode = iota
  102. BorderModeOutside
  103. BorderModeIgnore
  104. )
  105. var (
  106. borderModeName = []string{"inside", "outside", "ignore"}
  107. )
  108. func (v BorderMode) String() string {
  109. if v >= 0 && int(v) < len(borderModeName) {
  110. return borderModeName[v]
  111. }
  112. return ""
  113. }
  114. func parserBorderModeResult(r string, err error) BorderMode {
  115. if err != nil {
  116. return -1
  117. }
  118. for n, s := range borderModeName {
  119. if s == r {
  120. return BorderMode(n)
  121. }
  122. }
  123. return -1
  124. }
  125. type Fill int
  126. const (
  127. FillNone Fill = iota
  128. FillX
  129. FillY
  130. FillBoth
  131. )
  132. var (
  133. fillName = []string{"none", "x", "y", "both"}
  134. )
  135. func (v Fill) String() string {
  136. if v >= 0 && int(v) < len(fillName) {
  137. return fillName[v]
  138. }
  139. return ""
  140. }
  141. func parserFillResult(r string, err error) Fill {
  142. if err != nil {
  143. return -1
  144. }
  145. for n, s := range fillName {
  146. if s == r {
  147. return Fill(n)
  148. }
  149. }
  150. return -1
  151. }
  152. type ReliefStyle int
  153. const (
  154. ReliefStyleFlat ReliefStyle = iota
  155. ReliefStyleGroove
  156. ReliefStyleRaised
  157. ReliefStyleRidge
  158. ReliefStyleSolid
  159. ReliefStyleSunken
  160. )
  161. var (
  162. borderStyleName = []string{"flat", "groove", "raised", "ridge", "solid", "sunken"}
  163. )
  164. func (v ReliefStyle) String() string {
  165. if v >= 0 && int(v) < len(borderStyleName) {
  166. return borderStyleName[v]
  167. }
  168. return ""
  169. }
  170. func parserReliefStyleResult(r string, err error) ReliefStyle {
  171. if err != nil {
  172. return -1
  173. }
  174. for n, s := range borderStyleName {
  175. if s == r {
  176. return ReliefStyle(n)
  177. }
  178. }
  179. return -1
  180. }
  181. type Anchor int
  182. const (
  183. AnchorCenter Anchor = iota
  184. AnchorNorth
  185. AnchorEast
  186. AnchorSouth
  187. AnchorWest
  188. AnchorNorthEast
  189. AnchorNorthWest
  190. AnchorSouthEast
  191. AnchorSouthWest
  192. )
  193. var (
  194. anchorName = []string{"center", "n", "e", "s", "w", "ne", "nw", "se", "sw"}
  195. )
  196. func (v Anchor) String() string {
  197. if v >= 0 && int(v) < len(anchorName) {
  198. return anchorName[v]
  199. }
  200. return ""
  201. }
  202. func parserAnchorResult(r string, err error) Anchor {
  203. if err != nil {
  204. return -1
  205. }
  206. for n, s := range anchorName {
  207. if s == r {
  208. return Anchor(n)
  209. }
  210. }
  211. return -1
  212. }
  213. type Sticky int
  214. const (
  215. StickyCenter Sticky = 1 << iota
  216. StickyN
  217. StickyS
  218. StickyE
  219. StickyW
  220. StickyNS = StickyN | StickyS
  221. StickyEW = StickyE | StickyW
  222. StickyAll = StickyN | StickyS | StickyE | StickyW
  223. )
  224. func (v Sticky) String() string {
  225. var s string
  226. if v&StickyN == StickyN {
  227. s += "n"
  228. }
  229. if v&StickyS == StickyS {
  230. s += "s"
  231. }
  232. if v&StickyE == StickyE {
  233. s += "e"
  234. }
  235. if v&StickyW == StickyW {
  236. s += "w"
  237. }
  238. return s
  239. }
  240. type Direction int
  241. const (
  242. DirectionBelow Direction = iota
  243. DirectionAbove
  244. DirectionLeft
  245. DirectionRight
  246. )
  247. var (
  248. directionName = []string{"below", "above", "left", "right"}
  249. )
  250. func (v Direction) String() string {
  251. if v >= 0 && int(v) < len(directionName) {
  252. return directionName[v]
  253. }
  254. return ""
  255. }
  256. func parserDirectionResult(r string, err error) Direction {
  257. if err != nil {
  258. return 0
  259. }
  260. for n, s := range directionName {
  261. if s == r {
  262. return Direction(n)
  263. }
  264. }
  265. return 0
  266. }
  267. type Compound int
  268. const (
  269. CompoundNone Compound = iota
  270. CompoundTop
  271. CompoundBottom
  272. CompoundLeft
  273. CompoundRight
  274. CompoundCenter
  275. )
  276. var (
  277. compoundName = []string{"none", "top", "bottom", "left", "right", "center"}
  278. )
  279. func (v Compound) String() string {
  280. if v >= 0 && int(v) < len(compoundName) {
  281. return compoundName[v]
  282. }
  283. return ""
  284. }
  285. func parserCompoundResult(r string, err error) Compound {
  286. if err != nil {
  287. return 0
  288. }
  289. for n, s := range compoundName {
  290. if s == r {
  291. return Compound(n)
  292. }
  293. }
  294. return 0
  295. }
  296. type State int
  297. const (
  298. StateNormal State = iota
  299. StateActive
  300. StateDisable
  301. StateReadOnly
  302. )
  303. var (
  304. stateName = []string{"normal", "active", "disabled", "readonly"}
  305. )
  306. func (v State) String() string {
  307. if v >= 0 && int(v) < len(stateName) {
  308. return stateName[v]
  309. }
  310. return ""
  311. }
  312. func parserStateResult(r string, err error) State {
  313. if err != nil {
  314. return 0
  315. }
  316. for n, s := range stateName {
  317. if s == r {
  318. return State(n)
  319. }
  320. }
  321. return 0
  322. }
  323. type ListSelectMode int
  324. const (
  325. ListSelectSingle ListSelectMode = iota
  326. ListSelectBrowse
  327. ListSelectMultiple
  328. ListSelectExtended
  329. )
  330. var (
  331. listSelectName = []string{"single", "browse", "multiple", "extended"}
  332. )
  333. func (v ListSelectMode) String() string {
  334. if v >= 0 && int(v) < len(listSelectName) {
  335. return listSelectName[v]
  336. }
  337. return ""
  338. }
  339. func parserListSelectModeResult(r string, err error) ListSelectMode {
  340. if err != nil {
  341. return 0
  342. }
  343. for n, s := range listSelectName {
  344. if s == r {
  345. return ListSelectMode(n)
  346. }
  347. }
  348. return 0
  349. }
  350. type DisplyCursor int
  351. const (
  352. DisplyCursorNone DisplyCursor = iota
  353. DisplyCursorHollow
  354. DisplyCursorSolid
  355. )
  356. var (
  357. displyCursorName = []string{"none", "hollow", "solid"}
  358. )
  359. func (v DisplyCursor) String() string {
  360. if v >= 0 && int(v) < len(displyCursorName) {
  361. return displyCursorName[v]
  362. }
  363. return ""
  364. }
  365. func parserDisplyCursorResult(r string, err error) DisplyCursor {
  366. if err != nil {
  367. return 0
  368. }
  369. for n, s := range displyCursorName {
  370. if s == r {
  371. return DisplyCursor(n)
  372. }
  373. }
  374. return 0
  375. }
  376. type LineWrapMode int
  377. const (
  378. LineWrapNone LineWrapMode = iota
  379. LineWrapChar
  380. LineWrapWord
  381. )
  382. var (
  383. lineWrapName = []string{"none", "char", "word"}
  384. )
  385. func (v LineWrapMode) String() string {
  386. if v >= 0 && int(v) < len(lineWrapName) {
  387. return lineWrapName[v]
  388. }
  389. return ""
  390. }
  391. func parserLineWrapModeResult(r string, err error) LineWrapMode {
  392. if err != nil {
  393. return 0
  394. }
  395. for n, s := range lineWrapName {
  396. if s == r {
  397. return LineWrapMode(n)
  398. }
  399. }
  400. return 0
  401. }
  402. type TreeSelectMode int
  403. const (
  404. TreeSelectExtended TreeSelectMode = iota
  405. TreeSelectBrowse
  406. TreeSelectNode
  407. )
  408. var (
  409. treeSelectName = []string{"extended", "browse", "none"}
  410. )
  411. func (v TreeSelectMode) String() string {
  412. if v >= 0 && int(v) < len(treeSelectName) {
  413. return treeSelectName[v]
  414. }
  415. return ""
  416. }
  417. func parserTreeSelectModeResult(r string, err error) TreeSelectMode {
  418. if err != nil {
  419. return 0
  420. }
  421. for n, s := range treeSelectName {
  422. if s == r {
  423. return TreeSelectMode(n)
  424. }
  425. }
  426. return 0
  427. }
  428. func parserPaddingResult(r string, err error) (int, int) {
  429. if err != nil {
  430. return 0, 0
  431. }
  432. return parserTwoInt(r)
  433. }