Skip to content

Commit

Permalink
[Aardvark.UI] Add pages
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed Feb 21, 2024
1 parent 7d15ebb commit 3aea815
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
13 changes: 1 addition & 12 deletions src/Aardvark.UI.Primitives/Golden/GoldenLayout.fs
Original file line number Diff line number Diff line change
Expand Up @@ -407,19 +407,8 @@ module GoldenLayoutApp =
let inline load (key : string) (model : GoldenLayout) =
model |> update (GoldenLayout.Message.LoadLayout key)

/// View for a paged document using Golden Layout.
let pages (createPage : Page -> DomNode<'msg>) : DomNode<'msg> =
page (fun request ->
let p =
match request.queryParams |> Map.tryFind "page" with
| Some id -> Page.Element id
| _ -> Page.Body

createPage p
)

/// View for the body of a paged document using Golden Layout.
let body (attributes : Attribute<'msg> list) (model : AdaptiveGoldenLayout) =
let view (attributes : Attribute<'msg> list) (model : AdaptiveGoldenLayout) =
let attributes =
attributes @ [
clazz "gl-aard-container"
Expand Down
5 changes: 0 additions & 5 deletions src/Aardvark.UI.Primitives/Golden/GoldenLayoutModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ type LayoutConfig =
LabelTabDropdown : string
}

[<RequireQualifiedAccess>]
type Page =
| Body
| Element of id: string

[<ModelType>]
type GoldenLayout =
{
Expand Down
14 changes: 14 additions & 0 deletions src/Aardvark.UI/Tags.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ open Aardvark.Base
open Aardvark.Rendering
open FSharp.Data.Adaptive

[<RequireQualifiedAccess>]
type Pages =
| Body
| Page of id: string

module Incremental =

Expand Down Expand Up @@ -255,6 +259,16 @@ module Static =
let page (createPage : Request -> DomNode<'msg>) =
DomNode.Page createPage

let inline pages (createPage : Pages -> DomNode<'msg>) : DomNode<'msg> =
page (fun request ->
let p =
match request.queryParams |> Map.tryFind "page" with
| Some id -> Pages.Page id
| _ -> Pages.Body

createPage p
)

let inline elem (tagName : string) (attrs : list<string * AttributeValue<'msg>>) (children : list<DomNode<'msg>>) =
DomNode.Node(tagName, AttributeMap.ofList attrs, AList.ofList children)

Expand Down
14 changes: 7 additions & 7 deletions src/Scratch/25 - GoldenLayout/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ let viewScene (model : AdaptiveModel) =
}

let view (model : AdaptiveModel) =
GoldenLayout.pages (function
| Page.Element "render" ->
pages (function
| Pages.Page "render" ->
let attributes =
AttributeMap.ofListCond [
always <| style "width: 100%; height:100%; background: #2a2a2a"
Expand All @@ -92,15 +92,15 @@ let view (model : AdaptiveModel) =

FreeFlyController.controlledControl model.cameraState Camera frustum attributes sg

| Page.Element "map" ->
| Pages.Page "map" ->
body [ style "width: 100%; height: 100%; border: 0; padding: 0; margin: 0; overflow: hidden" ] [
iframe [
style "width: 100%; height: 100%"
attribute "src" "https://www.openstreetmap.org/export/embed.html?bbox=-0.004017949104309083%2C51.47612752641776%2C0.00030577182769775396%2C51.478569861898606&layer=mapnik"
] []
]

| Page.Element "aux2" ->
| Pages.Page "aux2" ->
div [style "color: white; padding: 10px"] [
button [onClick (fun _ -> Message.GoldenLayout GoldenLayout.Message.ResetLayout)] [
text "Reset layout"
Expand All @@ -115,20 +115,20 @@ let view (model : AdaptiveModel) =
]
]

| Page.Element unknown ->
| Pages.Page unknown ->
div [style "color: red; padding: 10px"] [
text $"Unknown element: {unknown}"
]

| Page.Body ->
| Pages.Body ->
Html.title false model.title (
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.body attributes model.golden
GoldenLayout.view attributes model.golden
]
)
)
Expand Down

0 comments on commit 3aea815

Please sign in to comment.