Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. // X* = zero or more X
  2. // X? = zero or one X
  3. // X*? = zero or one of each type of X
  4. // X! = exactly one X
  5. // abstract Fn = All immediate children must implement this
  6. // gen - this member is generated
  7. // mut - method may mutate state of self
  8. // ref - reference to
  9. // * on a function means that it's being used as a map
  10. // '-' compose functions like Min-Length*-Side(Shape)
  11.  
  12. UIWindow OuterLayout {
  13. enum Type {
  14. FloatingWindow,
  15. DockedWindow
  16. }
  17. }
  18.  
  19. UIElement {
  20. abstract Render : (Point -> Colour)
  21. abstract ProcessUIEvent : mut (UIEvent -> ())
  22. gen UILayout
  23. }
  24.  
  25. FloatingElement {
  26. abstract FloatDescriptor
  27. }
  28.  
  29. UIIdent : {
  30. Icon?
  31. Text?
  32. }
  33.  
  34. Control : UIElement
  35. ControlGroup : Control {
  36. UIIdent
  37. elem Control*
  38. }
  39. Button : Control {
  40. UIIdent
  41. }
  42. SingleLineTextInput : Control, Text {
  43. UIIdent
  44. }
  45.  
  46. // maybe replace '~if' with 'else'
  47.  
  48. ClosestLine : (Text with Layout), Point -> (Line of Text)? {
  49. Axis = LineAxis of Text
  50. for_each Line in Text
  51. local Dist of Line
  52. Dist = Dist-Projection(Axis)*(Line,Point*)
  53. if Dist == 0
  54. return Line
  55. ~if no_matches
  56. Min(Line by Dist)
  57. ~if empty
  58. return null
  59. return min
  60. return Kind = Closest
  61. if
  62. ~if multiple_matches
  63. return First
  64. return Kind = Multiple
  65. }
  66.  
  67. ClosestGlyph : (Text with Layout), Point -> (Glyph of Text)? {
  68. Axis = PrimaryAxis of Text
  69. GetClosestLine
  70. for_each Glyph in Line
  71. local Dist of Glyph = Dist-Projection(Axis)**(Glyph, Point*)
  72. if Dist == 0
  73. return Glyph
  74. ~if no_matches
  75. return Min(Line by Dist)
  76. ~if empty
  77. return null
  78. return Kind = Closest
  79. ~if multiple_matches
  80. return First, All = all_matches
  81. return Kind = Multiple
  82. }
  83.  
  84. // maybe the below overcomplicates things
  85. // the stars could be removed too
  86. //
  87. // @ means transpose 2
  88. // # could mean cycle 3 (in case this is ever needed)
  89. // extend_result f means a function that takes the same args as f but mutates the value before returning
  90. // in a similar way an extend_input could be added.
  91. // it is important because it preserves additional members
  92.  
  93. ClosestPos = extend_result ClosestGlyph returning (Pos of Text) {
  94. Axis = PrimaryAxis of Text
  95. Projection(Axis)*-Diff*(Glyph, Point*)
  96. if Positive-Avg-Projection
  97. Pos = Add(1,Pos of Glyph)
  98. else
  99. Pos = Pos of Glyph
  100. }
  101.  
  102. CursorGesture {
  103. enum CursorMode*? {
  104. Primary (default),
  105. Secondary
  106. }
  107. Priority?
  108. Shared?
  109. Detect : CursorEvent* -> enum{Start,End}?
  110. Detect preprocess {
  111. if Matches(CursorMode)
  112. continue
  113. else
  114. abort
  115. }
  116. on Cancel?
  117. on Start?
  118. on Detect?
  119. while Active?
  120. on End?
  121. }
  122.  
  123. CursorGesture Drag {
  124. override Detect : Point -> Boolean
  125. original Detect {
  126.  
  127. }
  128. }
  129.  
  130. // on_change gives old_val and new_val
  131.  
  132. CursorGesture Hover {
  133. Priority default = 1
  134. Region
  135. on MoveWithin?
  136. on MoveOut?
  137. Detect {
  138. on_change Contains(Region, Point) {
  139. if new_val: return Start
  140. if old_val: return End
  141. }
  142. }
  143. }
  144.  
  145. // Matches checks whether the CursorMode is the same as ours
  146.  
  147. CursorGesture Click {
  148. Priority default = 2
  149. Region
  150. Detect {
  151. on_change (Contains(Region, Point) && ButtonIsDown {
  152. if new Type == Depress: return Start
  153. if old Type == Release:
  154. return End
  155. }
  156. }
  157.  
  158. KeyGesture {
  159. Priority
  160. }
  161.  
  162. std SingleLineTextInput {
  163. CursorPos : Pos of Text
  164. Selection? : Range of Text
  165. ProcessUIEvent = {
  166. DragSelect : PointerGesture, DragGesture {
  167. Priority = 3
  168. StartPos : Pos of Text
  169. Detect = Always True // the always could be optional
  170. on Start { // this needs to be reverted if it turns out to not be a DragSelect
  171. StartPos = ClosestPos
  172. }
  173. while Active {
  174. Selection = Range-Sort(StartPos,ClosestPos)
  175. Cursor = ClosestPos
  176. }
  177. on Cancel {}
  178. }
  179. DragMove : PointerGesture, DragGesture {
  180. Priority = 6
  181. Cursor = DragObject
  182. Detect = {
  183. ClosestPos
  184. if Contains(Selection, ClosestPos)
  185. return True
  186. else if ClosestPos == Add(1,Max(Selection)) && Kind != Closest
  187. return True
  188. else return False
  189. }
  190. while Active {
  191. Cursor = ClosestPos
  192. }
  193. on Drop {
  194. StoredText = Store(Text of Selection)
  195. EraseText(Selection)
  196. InsertText(StoredText)
  197. Free StoredText
  198. }
  199. }
  200. KeyMap = TextEditKeyMap
  201. }
  202. }
  203. ToggleButton : Control, Boolean {
  204.  
  205. }
  206. Select : Control
  207.  
  208. ControlBar : UIPaneElement {
  209. elem (Control + FloatingElement)*
  210.  
  211. }
  212. Menu : UIPaneElement
  213. StatusBar : UIPaneElement
  214. TitleBar : UIPaneElement
  215.  
  216. UIPaneElement : FloatingElement, UIElement
  217.  
  218. enum Axis {
  219. XAxis
  220. YAxis
  221. }
  222.  
  223. struct InnerNavigation {
  224. Scrollable : Axis*?
  225. Tabbed?
  226. }
  227.  
  228. instances_of Scrollable have ScrollAxisPosition! for_each Axis
  229. instances_of Tabbed have {
  230. Tab*
  231. SelectedTab : Tab
  232. }
  233.  
  234. UIWindow InnerLayout {
  235. axis UIMainContent
  236. axis InnerNavigation
  237. UIPaneElement*
  238. }
  239.  
  240. PaneContainer : UIMainContent
  241. Content : UIMainContent
  242. Form : UIMainContent
  243.  
  244. struct FloatDescriptor {
  245. Direction
  246. Weight : Int // Higher float weight means closer to edge
  247. }
  248.  
  249. struct UIWindow LayoutPreferences {
  250. OuterLayout?
  251. InnerLayout!
  252. FloatDescriptor?
  253. ConceptualCategory? // Group like elements together if possible
  254. }
  255.  
  256. UIWindow Layout {
  257. InnerLayout!
  258. OuterLayout!
  259. InnerRect! : Rect
  260. OuterRect! : Rect
  261. }
  262.  
  263. type UIElement : Hierarchy {
  264. HandleUIEvent!
  265. Draw!
  266. LayoutPreferences!
  267. gen Layout from ComputeLayout
  268. }
  269.  
  270. UITitleBar : UIElement {
  271. Icon?
  272. Title! : String
  273. UIWindowControlButtons : {Button}
  274. }
  275.  
  276. UIFrameWindow : UIElement {
  277. UITitleBar!
  278. UIMenu?
  279. UIToolbar?
  280. UIContent! : UIElement
  281. UIResizable
  282. }
  283.  
  284. LayoutFn = (ExternalLayoutPreferencesAndConstraints -> Layout)
  285. Draw = ({Point} -> (Point -> PointViewData))
  286.  
  287. struct DocumentEditorWindow : UI Window {
  288. hold Document?
  289. Menu = [
  290. Document,
  291. Document Edit,
  292. Insert to Document,
  293.  
  294. ]
  295. }
  296.  
  297. struct Command
  298.  
  299. namespace Fractal {
  300. Iterator {
  301. Initial : Type2
  302. Next : Type2 -> Type1, Type2
  303. IsFinal : Type2 -> Boolean
  304. }
  305. ComplexIteration {
  306. IterationFn : Complex, Complex -> Complex, Complex
  307. Initial : Complex
  308. }
  309. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement