Skip to content

Commit

Permalink
make UI smoother
Browse files Browse the repository at this point in the history
fix: make CtrlW (center circuit in window) work consistently
feat: add button to memory source change menu
  • Loading branch information
tomcl committed Sep 14, 2024
1 parent 4a536b4 commit 55c6ec9
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/Renderer/DrawBlock/Sheet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,14 @@ let getWindowParasToFitBox model (box: BoundingBox) =
getScreenEdgeCoords model
|> Option.map (fun edge ->
let lh,rh,top,bottom = edge.Left,edge.Right,edge.Top,edge.Bottom
printfn $"------------------\nbox LRTB=({edge.Left},{edge.Right},{edge.Top},{edge.Bottom})" //>
let wantedMag = min ((rh - lh)/box.W) ((bottom-top)/box.H)
let magToUse = min wantedMag Constants.maxMagnification
let xMiddle = (box.TopLeft.X + box.W/2.)*magToUse
let xScroll = xMiddle - (rh-lh)/2.
let yMiddle = (box.TopLeft.Y + (box.H)/2.)*magToUse
let yScroll = yMiddle - (bottom-top)/2.
printfn $"mid XY=({xMiddle},{yMiddle}) scroll XY={xScroll},{yScroll}\n----------------" //>
{|Scroll={X=xScroll; Y=yScroll}; MagToUse=magToUse|})

let addBoxMargin (fractionalMargin:float) (absoluteMargin:float) (box: BoundingBox) =
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/DrawBlock/SheetUpdate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ let update (msg : Msg) (issieModel : ModelType.Model): ModelType.Model*Cmd<Model
sheetCmd CheckAutomaticScrolling // Also check if there is automatic scrolling to continue
else
Cmd.none
// keep last 4 updates yo filte corresponding OnScroll events
// keep last 4 updates to filter corresponding OnScroll events
recentProgrammaticScrollPos <- scrollPos :: List.truncate 4 recentProgrammaticScrollPos
scrollSequence <- scrollSequence + 1 // increment sequence counter
viewIsAfterUpdateScroll <- true
Expand Down
6 changes: 4 additions & 2 deletions src/Renderer/DrawBlock/SheetUpdateHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ let fitCircuitToScreenUpdate (model: Model) =
let model', parasOpt = fitCircuitToWindowParas model
match parasOpt with
| Some paras ->
//printf "CtrlW Calculated Scroll = %A" paras.Scroll
printf "CtrlW Calculated Scroll = %A" paras.Scroll //>
model',
Cmd.batch
[
sheetCmd (SheetT.Msg.UpdateScrollPos paras.Scroll)
sheetCmd SheetT.Msg.UpdateBoundingBoxes
if abs (model.Zoom - model'.Zoom) > 0.001 then
sheetCmd (SheetT.Msg.KeyPress CtrlW)
printfn "Sheet has chnaged: recursively called CtrlW" //>
ModelType.Msg.RunAfterRender (false, (fun dispatch model -> (dispatch <| ModelType.Msg.Sheet (SheetT.Msg.KeyPress CtrlW)); model))
|> Cmd.ofMsg
]
| None -> model, Cmd.none

Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/Model/ModelType.fs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ type Msg =
| SaveModel
| CheckMemory
| ChangeWaveSimMultiplier of int
| RunAfterRender of ((Msg -> unit) * ((Msg -> unit) -> Model -> Model))
| RunAfterRender of (bool * ((Msg -> unit) -> Model -> Model))


//================================//
Expand Down
14 changes: 14 additions & 0 deletions src/Renderer/UI/MenuHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,18 @@ let makeSourceMenu
br []; br []
Menu.menu []
[ Menu.list [] menu ]
Level.level [ Level.Level.Props [ Style [ Width "100%"; PaddingTop "20px"] ] ] [
Level.left [] []
Level.right [] [
Level.item [] [
Button.button [
Button.Color IsSuccess
Button.OnClick (fun _ ->
dispatch ClosePopup)
] [ str "Change Source" ]
]
]
]

]

Expand Down Expand Up @@ -664,6 +676,8 @@ let setupProjectFromComponents (finishUI:bool) (sheetName: string) (ldComps: Loa
}
|> SetProject // this message actually changes the project in model
|> dispatch
printfn "Centering schematic" //>
//dispatch <| Sheet (SheetT.KeyPress SheetT.KeyboardMsg.CtrlW) //>
dispatch SynchroniseCanvas


Expand Down
4 changes: 2 additions & 2 deletions src/Renderer/UI/Update.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ let update (msg : Msg) oldModel =
//-------------------------------------------------------------------------------//

match testMsg with
| RunAfterRender( dispatch, fn) ->
{model with RunAfterRenderWithSpinner = Some {FnToRun=fn; ButtonSpinnerOn = true}}, Cmd.none
| RunAfterRender( withSpinner, fn) ->
{model with RunAfterRenderWithSpinner = Some {FnToRun=fn; ButtonSpinnerOn = withSpinner}}, Cmd.none

| ChangeWaveSimMultiplier key ->
let table = Constants.multipliers
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer/UI/WaveSim/WaveSimTop.fs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ let refreshButtonAction canvasState model dispatch = fun _ ->
dispatch <| UpdateWSModel (fun wsModel -> {wsModel with DefaultCursor = Default})
else
dispatch <| SetWSModelAndSheet ({ wsModel with State = NonSequential}, wsSheet)
dispatch <| RunAfterRender(dispatch, fun dispatch model -> startWaveSimulation dispatch model; model)
dispatch <| RunAfterRender(true, fun dispatch model -> startWaveSimulation dispatch model; model)



Expand Down
2 changes: 1 addition & 1 deletion static/demos/5eratosthenes/datapath.dgm

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/demos/5eratosthenes/dpdecode.dgm

Large diffs are not rendered by default.

0 comments on commit 55c6ec9

Please sign in to comment.