Skip to content

Commit

Permalink
simplify min-width of panels
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc committed Feb 26, 2024
1 parent f7caef5 commit 99bffbc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 94 deletions.
8 changes: 0 additions & 8 deletions src/renderer/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@
(.then (js/window.api.webrefCss.listAll)
#(rf/dispatch-sync [:set-webref-css (js->clj % :keywordize-keys true)])))

(defn resize-event
[]
(rf/dispatch-sync [:window/resize [(.-innerWidth js/window)
(.-innerHeight js/window)]]))

(defn ^:export init []
#_(if platform/electron?
(sentry-electron-renderer/init (clj->js config/sentry-options) sentry-react/init)
Expand All @@ -121,9 +116,6 @@
(.addEventListener js/document "keydown" keyb/event-handler)
(.addEventListener js/document "keyup" keyb/event-handler)

(.addEventListener js/window "load" resize-event) ; Save initial size.
(.addEventListener js/window "resize" resize-event)

(.setup paper)

(if platform/electron?
Expand Down
108 changes: 49 additions & 59 deletions src/renderer/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -122,65 +122,55 @@

(defn tree-panel
[]
(let [tree? @(rf/subscribe [:panel/visible? :tree])
tree-min-width @(rf/subscribe [:window/tree-min-width])]
(when (and tree? tree-min-width)
[:<>
[:> Panel
{:id "tree-panel"
:minSize tree-min-width
:defaultSize tree-min-width
:class "flex flex-col"}
[doc/actions]
[tree/root]]
[:> PanelResizeHandle
{:id "tree-resize-handle"
:className "resize-handle"}]])))
(when @(rf/subscribe [:panel/visible? :tree])
[:<>
[:> Panel
{:id "tree-panel"
:class "flex flex-col"
:style {:min-width "230px"}}
[doc/actions]
[tree/root]]
[:> PanelResizeHandle
{:id "tree-resize-handle"
:className "resize-handle"}]]))

(defn root
[]
(let [props-min-width @(rf/subscribe [:window/props-min-width])
props? @(rf/subscribe [:panel/visible? :properties])]
[:> Tooltip/Provider
[:div.flex.flex-col.flex-1.h-screen
[win/app-header]
(if (seq @(rf/subscribe [:documents]))
[:> PanelGroup
{:direction "horizontal"
:id "root-group"
:autoSaveId "root-group"}
[tree-panel]
[:> Panel
{:id "main-panel"
:order 2}
[:div.flex.flex-col.flex-1.overflow-hidden.h-full
[doc/tab-bar]
[:> PanelGroup
{:direction "horizontal"
:id "center-group"
:autoSaveId "center-group"}
[:> Panel
{:id "center-panel"
:minSize 10
:order 1}
[:div.flex.h-full.flex-col
[editor]]]

(when (and props? props-min-width)
[:<>
[:> PanelResizeHandle
{:id "properties-resize-handle"
:className "resize-handle"}]
[:> Panel
{:id "properties-panel"
:order 2
:minSize props-min-width
:defaultSize props-min-width
:onCollapse #(rf/dispatch-sync [:panel/collapse :properties])
:onExpand #(rf/dispatch-sync [:panel/expand :properties])}

[attr/form]]])
[toolbar.object/root]]]]]
[home/panel])]
[cmdk/dialog]
[notification/main]]))
[:> Tooltip/Provider
[:div.flex.flex-col.flex-1.h-screen
[win/app-header]
(if (seq @(rf/subscribe [:documents]))
[:> PanelGroup
{:direction "horizontal"
:id "root-group"
:autoSaveId "root-group"}
[tree-panel]
[:> Panel
{:id "main-panel"
:order 2}
[:div.flex.flex-col.flex-1.overflow-hidden.h-full
[doc/tab-bar]
[:> PanelGroup
{:direction "horizontal"
:id "center-group"
:autoSaveId "center-group"}
[:> Panel
{:id "center-panel"
:minSize 10
:order 1}
[:div.flex.h-full.flex-col
[editor]]]
(when @(rf/subscribe [:panel/visible? :properties])
[:<>
[:> PanelResizeHandle
{:id "properties-resize-handle"
:className "resize-handle"}]
[:> Panel
{:id "properties-panel"
:order 2
:style {:min-width "320px"}}
[attr/form]]])
[toolbar.object/root]]]]]
[home/panel])]
[cmdk/dialog]
[notification/main]])
3 changes: 1 addition & 2 deletions src/renderer/window/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
[:map
[:maximized? boolean?]
[:minimized? boolean?]
[:fullscreen? boolean?]
[:size [:tuple double? double?]]])
[:fullscreen? boolean?]])
6 changes: 0 additions & 6 deletions src/renderer/window/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@
(fn [db [_ state]]
(assoc db :minimized? state)))

(rf/reg-event-db
:window/resize
(rf/path :window)
(fn [db [_ size]]
(assoc db :size size)))

(rf/reg-fx
::close
(fn [_]
Expand Down
19 changes: 0 additions & 19 deletions src/renderer/window/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,3 @@
:window/fullscreen?
:<- [:window]
:-> :fullscreen?)

(rf/reg-sub
:window/size
:<- [:window]
:-> :size)

(rf/reg-sub
:window/tree-min-width
:<- [:window/size]
(fn [size]
(when-let [width (first size)]
(* (/ 230 width) 100))))

(rf/reg-sub
:window/props-min-width
:<- [:window/size]
(fn [size]
(when-let [width (first size)]
(* (/ 320 width) 100))))

0 comments on commit 99bffbc

Please sign in to comment.