Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // X* = zero or more X
- // X? = zero or one X
- // X*? = zero or one of each type of X
- // X! = exactly one X
- // abstract Fn = All immediate children must implement this
- // gen - this member is generated
- // mut - method may mutate state of self
- // ref - reference to
- // * on a function means that it's being used as a map
- // '-' compose functions like Min-Length*-Side(Shape)
- UIWindow OuterLayout {
- enum Type {
- FloatingWindow,
- DockedWindow
- }
- }
- UIElement {
- abstract Render : (Point -> Colour)
- abstract ProcessUIEvent : mut (UIEvent -> ())
- gen UILayout
- }
- FloatingElement {
- abstract FloatDescriptor
- }
- UIIdent : {
- Icon?
- Text?
- }
- Control : UIElement
- ControlGroup : Control {
- UIIdent
- elem Control*
- }
- Button : Control {
- UIIdent
- }
- SingleLineTextInput : Control, Text {
- UIIdent
- }
- // maybe replace '~if' with 'else'
- ClosestLine : (Text with Layout), Point -> (Line of Text)? {
- Axis = LineAxis of Text
- for_each Line in Text
- local Dist of Line
- Dist = Dist-Projection(Axis)*(Line,Point*)
- if Dist == 0
- return Line
- ~if no_matches
- Min(Line by Dist)
- ~if empty
- return null
- return min
- return Kind = Closest
- if
- ~if multiple_matches
- return First
- return Kind = Multiple
- }
- ClosestGlyph : (Text with Layout), Point -> (Glyph of Text)? {
- Axis = PrimaryAxis of Text
- GetClosestLine
- for_each Glyph in Line
- local Dist of Glyph = Dist-Projection(Axis)**(Glyph, Point*)
- if Dist == 0
- return Glyph
- ~if no_matches
- return Min(Line by Dist)
- ~if empty
- return null
- return Kind = Closest
- ~if multiple_matches
- return First, All = all_matches
- return Kind = Multiple
- }
- // maybe the below overcomplicates things
- // the stars could be removed too
- //
- // @ means transpose 2
- // # could mean cycle 3 (in case this is ever needed)
- // extend_result f means a function that takes the same args as f but mutates the value before returning
- // in a similar way an extend_input could be added.
- // it is important because it preserves additional members
- ClosestPos = extend_result ClosestGlyph returning (Pos of Text) {
- Axis = PrimaryAxis of Text
- Projection(Axis)*-Diff*(Glyph, Point*)
- if Positive-Avg-Projection
- Pos = Add(1,Pos of Glyph)
- else
- Pos = Pos of Glyph
- }
- CursorGesture {
- enum CursorMode*? {
- Primary (default),
- Secondary
- }
- Priority?
- Shared?
- Detect : CursorEvent* -> enum{Start,End}?
- Detect preprocess {
- if Matches(CursorMode)
- continue
- else
- abort
- }
- on Cancel?
- on Start?
- on Detect?
- while Active?
- on End?
- }
- CursorGesture Drag {
- override Detect : Point -> Boolean
- original Detect {
- }
- }
- // on_change gives old_val and new_val
- CursorGesture Hover {
- Priority default = 1
- Region
- on MoveWithin?
- on MoveOut?
- Detect {
- on_change Contains(Region, Point) {
- if new_val: return Start
- if old_val: return End
- }
- }
- }
- // Matches checks whether the CursorMode is the same as ours
- CursorGesture Click {
- Priority default = 2
- Region
- Detect {
- on_change (Contains(Region, Point) && ButtonIsDown {
- if new Type == Depress: return Start
- if old Type == Release:
- return End
- }
- }
- KeyGesture {
- Priority
- }
- std SingleLineTextInput {
- CursorPos : Pos of Text
- Selection? : Range of Text
- ProcessUIEvent = {
- DragSelect : PointerGesture, DragGesture {
- Priority = 3
- StartPos : Pos of Text
- Detect = Always True // the always could be optional
- on Start { // this needs to be reverted if it turns out to not be a DragSelect
- StartPos = ClosestPos
- }
- while Active {
- Selection = Range-Sort(StartPos,ClosestPos)
- Cursor = ClosestPos
- }
- on Cancel {}
- }
- DragMove : PointerGesture, DragGesture {
- Priority = 6
- Cursor = DragObject
- Detect = {
- ClosestPos
- if Contains(Selection, ClosestPos)
- return True
- else if ClosestPos == Add(1,Max(Selection)) && Kind != Closest
- return True
- else return False
- }
- while Active {
- Cursor = ClosestPos
- }
- on Drop {
- StoredText = Store(Text of Selection)
- EraseText(Selection)
- InsertText(StoredText)
- Free StoredText
- }
- }
- KeyMap = TextEditKeyMap
- }
- }
- ToggleButton : Control, Boolean {
- }
- Select : Control
- ControlBar : UIPaneElement {
- elem (Control + FloatingElement)*
- }
- Menu : UIPaneElement
- StatusBar : UIPaneElement
- TitleBar : UIPaneElement
- UIPaneElement : FloatingElement, UIElement
- enum Axis {
- XAxis
- YAxis
- }
- struct InnerNavigation {
- Scrollable : Axis*?
- Tabbed?
- }
- instances_of Scrollable have ScrollAxisPosition! for_each Axis
- instances_of Tabbed have {
- Tab*
- SelectedTab : Tab
- }
- UIWindow InnerLayout {
- axis UIMainContent
- axis InnerNavigation
- UIPaneElement*
- }
- PaneContainer : UIMainContent
- Content : UIMainContent
- Form : UIMainContent
- struct FloatDescriptor {
- Direction
- Weight : Int // Higher float weight means closer to edge
- }
- struct UIWindow LayoutPreferences {
- OuterLayout?
- InnerLayout!
- FloatDescriptor?
- ConceptualCategory? // Group like elements together if possible
- }
- UIWindow Layout {
- InnerLayout!
- OuterLayout!
- InnerRect! : Rect
- OuterRect! : Rect
- }
- type UIElement : Hierarchy {
- HandleUIEvent!
- Draw!
- LayoutPreferences!
- gen Layout from ComputeLayout
- }
- UITitleBar : UIElement {
- Icon?
- Title! : String
- UIWindowControlButtons : {Button}
- }
- UIFrameWindow : UIElement {
- UITitleBar!
- UIMenu?
- UIToolbar?
- UIContent! : UIElement
- UIResizable
- }
- LayoutFn = (ExternalLayoutPreferencesAndConstraints -> Layout)
- Draw = ({Point} -> (Point -> PointViewData))
- struct DocumentEditorWindow : UI Window {
- hold Document?
- Menu = [
- Document,
- Document Edit,
- Insert to Document,
- ]
- }
- struct Command
- namespace Fractal {
- Iterator {
- Initial : Type2
- Next : Type2 -> Type1, Type2
- IsFinal : Type2 -> Boolean
- }
- ComplexIteration {
- IterationFn : Complex, Complex -> Complex, Complex
- Initial : Complex
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement