Skip to content

Commit

Permalink
[GoldenLayout] Add basic save and load functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed Dec 20, 2023
1 parent a5cc602 commit a6968cf
Show file tree
Hide file tree
Showing 6 changed files with 436 additions and 241 deletions.
1 change: 1 addition & 0 deletions src/Scratch/25 - GoldenLayout/25 - GoldenLayout.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<EmbeddedResource Include="resources\golden-layout\**">
<LogicalName>resources\golden-layout\%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
</EmbeddedResource>
<Compile Include="GoldenLayoutModel.fs" />
<Compile Include="GoldenLayout.fs" />
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Model.fs" />
Expand Down
81 changes: 52 additions & 29 deletions src/Scratch/25 - GoldenLayout/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,53 @@ let initialCamera = {
view = CameraView.lookAt (V3d.III * 3.0) V3d.OOO V3d.OOI
}

let layoutConfig =
{ LayoutConfig.Default with PopInOnClose = false }

let initialLayout =
row {
column {
element {
id "render"
title "3D View"
}

element {
id "map"
title "Map"
header Header.Top
buttons (Buttons.All ^^^ Buttons.Close)
}

weight 2
}

element {
id "aux2"
title "Some pretty long title"
buttons (Buttons.All ^^^ Buttons.Maximize)
weight 1
}
}

let update (model : Model) (msg : Message) =
match msg with
| ToggleBackground ->
{ model with background = (if model.background = C4b.Black then C4b.White else C4b.Black) }

| Camera m ->
{ model with cameraState = FreeFlyController.update model.cameraState m }

| CenterScene ->
{ model with cameraState = initialCamera }

| LayoutChanged ->
Log.line "Layout changed!"
model

| GoldenLayout msg ->
{ model with golden = model.golden |> GoldenLayout.update msg }

let viewScene (model : AdaptiveModel) =
Sg.box (AVal.constant C4b.Green) (AVal.constant Box3d.Unit)
|> Sg.shader {
Expand All @@ -32,39 +70,13 @@ let viewScene (model : AdaptiveModel) =

let view (model : AdaptiveModel) =

let layout =
row {
column {
element {
id "render"
title "3D View"
}

element {
id "map"
title "Map"
header Header.Top
buttons (Buttons.All ^^^ Buttons.Close)
}

weight 2
}

element {
id "aux2"
title "Some pretty long title"
buttons (Buttons.All ^^^ Buttons.Maximize)
weight 1
}
}

body [style "width: 100%; height: 100%; overflow: hidden; margin: 0"] [
let attributes = [
style "width: 100%; height: 100%; min-width: 400px; min-height: 400px; overflow: hidden"
onLayoutChanged (fun _ -> LayoutChanged)
]

GoldenLayout.layout attributes LayoutConfig.Default layout (fun element ->
match element with
(attributes, model.golden) ||> GoldenLayout.view (function
| "render" ->
let attributes =
AttributeMap.ofListCond [
Expand Down Expand Up @@ -94,7 +106,17 @@ let view (model : AdaptiveModel) =

| "aux2" ->
div [style "color: white; padding: 10px"] [
text "What's up?"
button [onClick (fun _ -> Message.GoldenLayout GoldenLayout.Message.ResetLayout)] [
text "Reset layout"
]

button [onClick (fun _ -> Message.GoldenLayout (GoldenLayout.Message.SaveLayout "GoldenLayoutExample.Key"))] [
text "Save layout"
]

button [onClick (fun _ -> Message.GoldenLayout (GoldenLayout.Message.LoadLayout "GoldenLayoutExample.Key"))] [
text "Load layout"
]
]

| _ ->
Expand All @@ -115,6 +137,7 @@ let app =
{
cameraState = initialCamera
background = C4b(34,34,34)
golden = GoldenLayout.create layoutConfig initialLayout
}
update = update
view = view
Expand Down
Loading

0 comments on commit a6968cf

Please sign in to comment.