Skip to content

Commit

Permalink
Forms are now more user-friendly. Solving some of the problems of issue
Browse files Browse the repository at this point in the history
  • Loading branch information
GlenDC committed Sep 2, 2015
1 parent 5cc2cfd commit 9f2cc0c
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/Trixel/Models/Dom.elm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ initialModel =
, title = "Trixel"
, exceptionalKeys =
[ TrKeyboard.c
, TrKeyboard.enter
]
, optionKeys =
[ TrKeyboard.ctrl
Expand Down Expand Up @@ -63,4 +64,4 @@ update workModel model =
| title <- TrWorkModel.computeTitle workModel
, limitInput <- (workModel.state == TrState.Default)
, isDirty <- workModel.unsavedProgress
}
}
24 changes: 24 additions & 0 deletions src/Trixel/Models/Update/Shortcuts.elm
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,36 @@ updateContextMenu model =
]


updateNewDocument : TrWorkModel.Model -> TrWorkModel.Model
updateNewDocument model =
applyShortcuts
model
[ TrUserActions.newDoc
]
|> updateContextMenu


updateOpenDocument : TrWorkModel.Model -> TrWorkModel.Model
updateOpenDocument model =
applyShortcuts
model
[ TrUserActions.openDoc
]
|> updateContextMenu


update : TrWorkModel.Model -> TrWorkModel.Model
update model =
( case model.state of
TrState.Default ->
updateWorkspace model

TrState.New ->
updateNewDocument model

TrState.Open ->
updateOpenDocument model

_ ->
updateContextMenu model
) |> updateCommon
6 changes: 3 additions & 3 deletions src/Trixel/Models/Work/Actions.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Trixel.Types.Input as TrInput
import Trixel.Types.State as TrState
import Trixel.Types.Vector as TrVector

import Trixel.Models.Work.Document as TrDocument
import Trixel.Models.Work.Scratch as TrScratch

import Math.Vector2 as Vector

Expand Down Expand Up @@ -36,10 +36,10 @@ type Action
-- Set Editor State
| SetState TrState.State
-- Update Scratch
| SetOpenDocScratch TrDocument.Model
| SetOpenDocScratch TrScratch.DocumentSpecs


type alias WindowContext =
{ dimensions : TrVector.Vector
, fullscreen : Bool
}
}
2 changes: 1 addition & 1 deletion src/Trixel/Models/Work/Input.elm
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ initialButtonModel =
type alias ButtonModel =
{ down : TrInput.Buttons
, pressed : TrInput.Buttons
}
}
64 changes: 58 additions & 6 deletions src/Trixel/Models/Work/Scratch.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,36 @@ module Trixel.Models.Work.Scratch where
import Trixel.Models.Work.Document as TrDocument

import Math.Vector2 as Vector
import Maybe exposing (..)
import Result
import String


initialModel : Model
initialModel =
{ openDoc = TrDocument.initialModel
{ openDoc = initialDocumentSpecs
}


type alias Model =
{ openDoc : TrDocument.Model
{ openDoc : DocumentSpecs
}


initialDocumentSpecs : DocumentSpecs
initialDocumentSpecs =
{ title = Nothing
, width = Just 10
, height = Just 10
}


type alias DocumentSpecs =
{ title : Maybe String
, width : Maybe Int
, height : Maybe Int
}

computeOpenDocTitle : Model -> String
computeOpenDocTitle model =
case model.openDoc.title of
Expand All @@ -25,11 +42,46 @@ computeOpenDocTitle model =

computeWidthString : Model -> String
computeWidthString model =
Vector.getX model.openDoc.dimensions
|> round |> toString
case model.openDoc.width of
Just width -> toString width
Nothing -> ""


computeHeightString : Model -> String
computeHeightString model =
Vector.getY model.openDoc.dimensions
|> round |> toString
case model.openDoc.height of
Just height -> toString height
Nothing -> ""


newDocument : Model -> TrDocument.Model
newDocument model =
let x = Maybe.withDefault 1 model.openDoc.width |> toFloat
y = Maybe.withDefault 1 model.openDoc.height |> toFloat
in
{ title = model.openDoc.title
, dimensions = Vector.vec2 x y
}


newTitle : DocumentSpecs -> String -> DocumentSpecs
newTitle model title =
{ model | title <- if title == "" then Nothing else Just title }


newWidth : DocumentSpecs -> String -> DocumentSpecs
newWidth model rawWidth =
let width =
if rawWidth == ""
then Nothing
else String.toInt rawWidth |> Result.toMaybe
in { model | width <- width }


newHeight : DocumentSpecs -> String -> DocumentSpecs
newHeight model rawHeight =
let height =
if rawHeight == ""
then Nothing
else String.toInt rawHeight |> Result.toMaybe
in { model | height <- height }
6 changes: 3 additions & 3 deletions src/Trixel/Models/Work/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Trixel.Models.Work.Update where
import Trixel.Types.State as TrState

import Trixel.Models.Work.Model as TrWorkModel
import Trixel.Models.Work.Document as TrDocument
import Trixel.Models.Work.Scratch as TrScratch


newDocument : TrWorkModel.Model -> TrWorkModel.Model
Expand All @@ -12,10 +12,10 @@ newDocument model =
document = scratch.openDoc

in { model
| document <- Just document
| document <- Just (TrScratch.newDocument scratch)
, state <- TrState.Default
, scratch <-
{ scratch | openDoc <- TrDocument.initialModel }
{ scratch | openDoc <- TrScratch.initialDocumentSpecs }
}


Expand Down
4 changes: 2 additions & 2 deletions src/Trixel/Types/Layout/UserActions.elm
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ newDoc : UserAction
newDoc =
{ action = TrWorkActions.NewDocument
, modelAction = TrUpdateWork.newDocument
, shortcut = TrInput.emptyShortcut
, shortcut = TrInput.simpleShortcut [ TrKeyboard.enter ]
, label = "Create"
, longLabel = "Create Document"
, description = "Create a new document."
Expand All @@ -204,7 +204,7 @@ openDoc : UserAction
openDoc =
{ action = TrWorkActions.OpenDocument
, modelAction = TrUpdateWork.openDocument
, shortcut = TrInput.emptyShortcut
, shortcut = TrInput.simpleShortcut [ TrKeyboard.enter ]
, label = "Open"
, longLabel = "Open Document"
, description = "Open the selected document."
Expand Down
29 changes: 9 additions & 20 deletions src/Trixel/Views/Context/Workspace.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Trixel.Views.Context.Workspace (view) where
import Trixel.Models.Model as TrModel
import Trixel.Models.Work.Actions as TrWorkActions
import Trixel.Models.Work.Scratch as TrScratch
import Trixel.Models.Work.Document as TrDocument

import Trixel.Types.State as TrState

Expand All @@ -23,10 +22,6 @@ import Math.Vector2 as Vector

import Material.Icons.File as FileIcons

import String
import Result
import Maybe


viewEditor : TrModel.Model -> TrLayout.Mode -> TrLayout.Generator
viewEditor model mode =
Expand All @@ -39,40 +34,34 @@ updateOpenDocTitle model =
in
(\title ->
TrWorkActions.SetOpenDocScratch
(TrDocument.updateTitle openDocScratch title)
(TrScratch.newTitle openDocScratch title)
)


updateOpenDocDimension : TrModel.Model -> (TrDocument.Model -> Float -> TrDocument.Model) -> (String -> TrWorkActions.Action)
updateOpenDocDimension : TrModel.Model -> (TrScratch.DocumentSpecs -> String -> TrScratch.DocumentSpecs) -> (String -> TrWorkActions.Action)
updateOpenDocDimension model updateFunction =
let openDocScratch = model.work.scratch.openDoc
in
(\valueString ->
let value =
String.toFloat valueString
|> Result.toMaybe
|> Maybe.withDefault 1
in
TrWorkActions.SetOpenDocScratch
(updateFunction openDocScratch value)
TrWorkActions.SetOpenDocScratch
(updateFunction openDocScratch valueString)
)


viewNewDocInputFields : TrModel.Model -> TrLayout.Mode -> Float -> Float -> Float -> TrLayout.Generator
viewNewDocInputFields model mode width size padding =
let labelSize = size * 0.78


labelColor = model.colorScheme.secondary.accentMid
inputColor = model.colorScheme.secondary.accentHigh
fieldColors = model.colorScheme.secondary.main

widthField =
TrLayoutInput.field
(TrLayoutInput.Number (1, 99999999))
(updateOpenDocDimension model TrDocument.updateWidth)
(updateOpenDocDimension model TrScratch.newWidth)
"Width:"
"1"
"Width of Document"
(TrScratch.computeWidthString model.work.scratch)
labelColor inputColor
fieldColors.fill
Expand All @@ -83,9 +72,9 @@ viewNewDocInputFields model mode width size padding =
heightField =
TrLayoutInput.field
(TrLayoutInput.Number (1, 99999999))
(updateOpenDocDimension model TrDocument.updateHeight)
(updateOpenDocDimension model TrScratch.newHeight)
"Height:"
"1"
"Height of Document"
(TrScratch.computeHeightString model.work.scratch)
labelColor inputColor
fieldColors.fill
Expand All @@ -103,7 +92,7 @@ viewNewDocInputFields model mode width size padding =
TrLayoutInput.Text
(updateOpenDocTitle model)
"Name:"
"Document Name"
"Name of Document"
(TrScratch.computeOpenDocTitle model.work.scratch)
labelColor inputColor
fieldColors.fill
Expand Down

0 comments on commit 9f2cc0c

Please sign in to comment.