diff --git a/app/Glyph/View/Element/Pane.hs b/app/Glyph/View/Element/Pane.hs index 32cf8dc..1259c8e 100644 --- a/app/Glyph/View/Element/Pane.hs +++ b/app/Glyph/View/Element/Pane.hs @@ -3,18 +3,18 @@ module Glyph.View.Element.Pane where ---------------------------------------------------------------------------------------------------- import qualified Brick -import qualified Brick.Widgets.Border as Border -import qualified Brick.Widgets.Center as Center +import qualified Brick.Widgets.Border as Border +import qualified Brick.Widgets.Center as Center -import Glyph.State ( State (..) ) -import qualified Glyph.View.Style as Style -import Glyph.ViewId ( ViewId ) +import Glyph.State ( State (..) ) +import qualified Glyph.View.Style as Style +import Glyph.ViewId ( ViewId ) ---------------------------------------------------------------------------------------------------- pane :: State -> Brick.Widget ViewId pane state = Brick.withBorderStyle Style.ruledBorderStyle - <. Border.border - <| Center.center - <| Brick.txt "Hello, World!" + <. Border.border + <| Center.center + <| Brick.txt "Hello, World!" diff --git a/glyph.cabal b/glyph.cabal index 185a8d8..42216a6 100644 --- a/glyph.cabal +++ b/glyph.cabal @@ -71,8 +71,8 @@ library lib Glyph.Key.Trigger Glyph.State Glyph.State.Input - Glyph.State.Mode Glyph.State.Layout + Glyph.State.Mode Glyph.State.Notice Glyph.ViewId Prelude diff --git a/lib/Glyph/State/Layout.hs b/lib/Glyph/State/Layout.hs index d82918f..2659707 100644 --- a/lib/Glyph/State/Layout.hs +++ b/lib/Glyph/State/Layout.hs @@ -2,27 +2,87 @@ module Glyph.State.Layout where ---------------------------------------------------------------------------------------------------- - - ---------------------------------------------------------------------------------------------------- -newtype PaneId = Paneid { id :: Natural } +newtype PaneId + = PaneId { id :: Natural } deriving (Eq, Ord, Show) -data Arrangement - = SideBySide - | OneOverOther +data Arrangement = SideBySide | OneOverOther deriving (Eq, Show) -- Here we go with more trie shenanigans data Layout - = Leaf PaneId - | Split Arrangement Rational Layout Layout + = Leaf + { paneId :: PaneId + } + | Split + { arrangement :: Arrangement + , firstDimension :: Rational + , firstLayout :: Layout + , secondLayout :: Layout + } deriving (Eq, Show) data Panes - = Panes - { layout :: Layout - , focused :: PaneId - , nextId :: PaneId - } + = Panes + { layout :: Layout + , focused :: PaneId + , nextId :: PaneId + } + deriving (Eq, Show) + +--------------------------------------------------------------------------------------------------- + +incrId :: PaneId -> PaneId +incrId (PaneId id') = PaneId <| id' + 1 + +null :: PaneId +null = PaneId 0 + +getLayoutPaneId :: Layout -> PaneId +getLayoutPaneId (Leaf paneId') = paneId' +getLayoutPaneId _ = null + +init :: Panes +init = + let newPaneId = PaneId 1 + in Panes + (Leaf newPaneId) + newPaneId + (incrId newPaneId) + +split :: Arrangement -> Panes -> Panes +split arrangement' panes = + let newLayout = + Split + arrangement' + 0.5 + panes.layout + (Leaf panes.nextId) + in panes{layout = newLayout, nextId = incrId panes.nextId} + +data LayoutSplitClose = First | Second + deriving (Eq, Show) + +close :: Panes -> Panes +close panes = + let stepLayout :: Layout -> Layout + stepLayout layout@(Split a d first secnd) + | panes.focused == getLayoutPaneId first = doClose layout First first + | panes.focused == getLayoutPaneId secnd = doClose layout Second secnd + | otherwise = layout{firstLayout = stepLayout first, secondLayout = stepLayout secnd} + stepLayout leaf = leaf + + doClose :: Layout -> LayoutSplitClose -> Layout -> Layout + doClose (Leaf _) _ _ = Leaf panes.nextId + doClose (Split _ _ _ s) First (Leaf _) = Leaf <| getLayoutPaneId s + doClose (Split _ _ f _) Second (Leaf _) = Leaf <| getLayoutPaneId f + -- We should never hit this + doClose _ _ _ = Leaf panes.nextId + + getFirstsId (Split _ _ f _) = getFirstsId f + getFirstsId (Leaf i) = i + + adjusted = stepLayout panes.layout + in panes{layout = adjusted, focused = getFirstsId adjusted, nextId = incrId panes.nextId}