Skip to content

Commit cba6dc2

Browse files
authored
Merge pull request #101 from CSchank/new-start-states
New start arrows and small UI/UX fixes
2 parents fd0df55 + 7e4f1d7 commit cba6dc2

File tree

5 files changed

+89
-24
lines changed

5 files changed

+89
-24
lines changed

elm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dependencies": {
88
"direct": {
99
"MacCASOutreach/graphicsvg": "5.1.0",
10+
"avh4/elm-color": "1.0.0",
1011
"billstclair/elm-sha256": "1.0.9",
1112
"elm/browser": "1.0.1",
1213
"elm/core": "1.0.2",
@@ -22,7 +23,6 @@
2223
"rundis/elm-bootstrap": "5.2.0"
2324
},
2425
"indirect": {
25-
"avh4/elm-color": "1.0.0",
2626
"elm/regex": "1.0.0",
2727
"elm/virtual-dom": "1.0.2",
2828
"elm-community/list-extra": "8.1.0"

src/Building.elm

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ update env msg ( model, pModel, sModel ) =
205205
""
206206
in
207207
if env.holdingShift then
208-
( ( { model | machineState = EditingTransitionLabel tId oldTransName }, pModel, sModel ), False, focusInput NoOp )
208+
( ( { model | machineState = EditingTransitionLabel ( s0, tId, s1 ) oldTransName }, pModel, sModel ), False, focusInput NoOp )
209209

210210
else
211211
( ( { model | machineState = SelectedArrow ( s0, tId, s1 ) }, pModel, sModel ), False, Cmd.none )
@@ -415,12 +415,12 @@ update env msg ( model, pModel, sModel ) =
415415
""
416416
in
417417
if newLbl == oldStateName || newLbl == "" then
418-
( ( { model | machineState = Regular }, pModel, sModel ), False, Cmd.none )
418+
( ( { model | machineState = SelectedState sId }, pModel, sModel ), False, Cmd.none )
419419

420420
else
421-
( ( { model | machineState = Regular }, pModel, sModel ), True, sendMsg <| SaveStateName sId newLbl )
421+
( ( { model | machineState = SelectedState sId }, pModel, sModel ), True, sendMsg <| SaveStateName sId newLbl )
422422

423-
EditingTransitionLabel tId newLbl ->
423+
EditingTransitionLabel ( s0, tId, s1 ) newLbl ->
424424
let
425425
oldTransitionName =
426426
case Dict.get tId oldMachine.transitionNames of
@@ -431,10 +431,34 @@ update env msg ( model, pModel, sModel ) =
431431
""
432432
in
433433
if newLbl == oldTransitionName || newLbl == "" then
434-
( ( { model | machineState = Regular }, pModel, sModel ), False, Cmd.none )
434+
( ( { model | machineState = SelectedArrow ( s0, tId, s1 ) }, pModel, sModel ), False, Cmd.none )
435435

436436
else
437-
( ( { model | machineState = Regular }, pModel, sModel ), True, sendMsg <| SaveTransitionName tId newLbl )
437+
( ( { model | machineState = SelectedArrow ( s0, tId, s1 ) }, pModel, sModel ), True, sendMsg <| SaveTransitionName tId newLbl )
438+
439+
SelectedState sId ->
440+
let
441+
oldStateName =
442+
case Dict.get sId sModel.machine.stateNames of
443+
Just n ->
444+
n
445+
446+
_ ->
447+
""
448+
in
449+
( ( { model | machineState = EditingStateLabel sId oldStateName }, pModel, sModel ), False, focusInput NoOp )
450+
451+
SelectedArrow ( s0, tId, s1 ) ->
452+
let
453+
oldTransName =
454+
case Dict.get tId sModel.machine.transitionNames of
455+
Just n ->
456+
renderSet2String n
457+
458+
Nothing ->
459+
""
460+
in
461+
( ( { model | machineState = EditingTransitionLabel ( s0, tId, s1 ) oldTransName }, pModel, sModel ), False, focusInput NoOp )
438462

439463
_ ->
440464
( ( model, pModel, sModel ), False, Cmd.none )
@@ -513,6 +537,20 @@ update env msg ( model, pModel, sModel ) =
513537
}
514538
in
515539
( ( model, pModel, { sModel | machine = newMachine } ), True, Cmd.none )
540+
--else if normalizedKey == "s" then
541+
-- let
542+
-- newMachine =
543+
-- { oldMachine
544+
-- | start =
545+
-- case Set.member sId oldMachine.start of
546+
-- True ->
547+
-- Set.remove sId oldMachine.start
548+
--
549+
-- False ->
550+
-- Set.insert sId oldMachine.start
551+
-- }
552+
-- in
553+
-- ( ( model, pModel, { sModel | machine = newMachine } ), True, Cmd.none )
516554

517555
else
518556
( ( model, pModel, sModel ), False, Cmd.none )

src/Exporting.elm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ view env ( model, pModel, sModel ) =
141141
|> move ( winX / 6 - 100, -105 )
142142
in
143143
group
144-
[ (GraphicSVG.map MachineMsg <| Machine.view env Regular sModel.machine sModel.machine.start transMistakes) |> move ( -winX / 6, 0 )
144+
[ (GraphicSVG.map MachineMsg <| Machine.view env Regular sModel.machine Set.empty transMistakes) |> move ( -winX / 6, 0 )
145145
, machineSelected sModel.machineType winX winY
146146
, text "Choose format:"
147147
|> size 20
@@ -336,7 +336,7 @@ generateTikz time machine =
336336

337337
start =
338338
if Set.member sId machine.start then
339-
"line width = 0.55mm,"
339+
"initial,thick,"
340340

341341
else
342342
"thick,"

src/Machine.elm

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ type Model
190190
| MousingOverStateLabel StateID
191191
| MousingOverTransitionLabel TransitionID
192192
| EditingStateLabel StateID String
193-
| EditingTransitionLabel TransitionID String
193+
| EditingTransitionLabel ( StateID, TransitionID, StateID ) String
194194
| SelectedArrow ( StateID, TransitionID, StateID )
195195
| DraggingArrow ( StateID, TransitionID, StateID ) ( Float, Float )
196196
| CreatingNewArrow StateID
@@ -508,14 +508,14 @@ renderArrow ( x0, y0 ) ( x1, y1 ) ( x2, y2 ) r0 r1 char charID sel mistake s1 s2
508508
|> notifyMouseDown (SelectArrow ( s1, charID, s2 ))
509509
, group
510510
[ case model of
511-
EditingTransitionLabel tId str ->
511+
EditingTransitionLabel ( _, tId, _ ) str ->
512512
if tId == charID then
513513
textBox str
514514
(if String.length str == 0 then
515-
34
515+
40
516516

517517
else
518-
6 * toFloat (String.length str)
518+
8 * toFloat (String.length str) + 5
519519
)
520520
20
521521
"LaTeX"
@@ -732,6 +732,13 @@ renderStates currentStates machine model env =
732732

733733
_ ->
734734
""
735+
736+
startArrow =
737+
group
738+
[ arrow ( -15, 0 ) ( -5, 0 ) ( 0, 0 )
739+
, latex 25 18 "none" "\\text{start}" AlignRight |> move ( -16, 9 )
740+
]
741+
|> move ( -20, 0 )
735742
in
736743
group <|
737744
List.map
@@ -756,10 +763,10 @@ renderStates currentStates machine model env =
756763
if st == sId then
757764
textBox str
758765
(if String.length str == 0 then
759-
34
766+
40
760767

761768
else
762-
6 * toFloat (String.length str)
769+
8 * toFloat (String.length str) + 5
763770
)
764771
20
765772
"LaTeX"
@@ -824,6 +831,11 @@ renderStates currentStates machine model env =
824831

825832
_ ->
826833
group []
834+
, if Set.member sId machine.start then
835+
startArrow
836+
837+
else
838+
group []
827839
]
828840
|> move (getPos sId)
829841
|> (case model of

src/SaveLoad.elm

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Dict exposing (Dict)
1818
import Duration
1919
import Environment exposing (Environment)
2020
import GraphicSVG exposing (..)
21+
import Helpers exposing (editIcon)
2122
import Html exposing (Html)
2223
import Html.Attributes exposing (attribute, placeholder, style, value)
2324
import Html.Events exposing (onInput)
@@ -353,7 +354,7 @@ type LoginStatus
353354

354355
initSaveModel =
355356
( { loginState = NotLoggedIn
356-
, machineData = MachineNotCreated
357+
, machineData = MachineCreated
357358
, loadDialog = NothingOpen
358359
, loadDialogModal = Modal.shown
359360
, machineMetadata = initMachineMetadata
@@ -380,15 +381,15 @@ subscriptions model =
380381
, Ports.logoutComplete (\_ -> GetLoginStatus)
381382
, Modal.subscriptions model.loadDialogModal ModalAnimation
382383
]
383-
++ (case model.machineData of
384-
MachineCreated ->
384+
++ (case ( model.machineData, model.loginState ) of
385+
( MachineCreated, LoggedIn _ _ ) ->
385386
if model.unsavedChanges then
386387
[ Time.every 5000 (MachineCreatedMsg << AutoSave) ]
387388

388389
else
389390
[]
390391

391-
MachineNotCreated ->
392+
( _, _ ) ->
392393
[]
393394
)
394395

@@ -819,11 +820,19 @@ view model env =
819820
MachineCreated ->
820821
group
821822
[ if not model.editingName then
822-
text model.machineMetadata.name
823-
|> fixedwidth
824-
|> size 16
825-
|> filled black
826-
|> move ( -winX / 2 + 175, winY / 2 - 20 )
823+
group
824+
[ group
825+
[ roundedRect 15 15 2 |> filled white |> addOutline (solid 1) darkGray |> move ( 3, 3 )
826+
, editIcon
827+
|> scale 1.5
828+
]
829+
|> move ( -winX / 2 + 470, winY / 2 - 20 )
830+
, text model.machineMetadata.name
831+
|> fixedwidth
832+
|> size 16
833+
|> filled black
834+
|> move ( -winX / 2 + 175, winY / 2 - 20 )
835+
]
827836
|> notifyTap (MachineCreatedMsg EditMachineName)
828837

829838
else
@@ -1059,4 +1068,10 @@ renderNew loginStatus =
10591068
[ Block.text [] [ Html.text "Please finish logging in to load your machines." ] ]
10601069
|> Card.footer []
10611070
[ Button.button [ Button.primary, Button.onClick OpenLoginDialog ] [ Html.text "Login" ] ]
1071+
, Card.config []
1072+
|> Card.headerH3 [] [ Html.text "Get involved!" ]
1073+
|> Card.block []
1074+
[ Block.text [] [ Html.text "Check us out on GitHub." ] ]
1075+
|> Card.footer []
1076+
[ Button.linkButton [ Button.primary, Button.attrs [ Html.Attributes.href "https://github.com/cschank/finsm" ] ] [ Html.text "Go!" ] ]
10621077
]

0 commit comments

Comments
 (0)