Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An app with multiple windows #45

Open
futpib opened this issue Apr 5, 2019 · 2 comments
Open

An app with multiple windows #45

futpib opened this issue Apr 5, 2019 · 2 comments

Comments

@futpib
Copy link

futpib commented Apr 5, 2019

Does not seem possible right now (or am I wrong?). I wish a container for multiple windows was provided.

@owickstrom
Copy link
Owner

You're right, it's not explicitly supported right now. You can hack it in by including Window bins in an existing container, but the problem is that the container grows:

{-# LANGUAGE OverloadedLabels  #-}
{-# LANGUAGE OverloadedLists   #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns      #-}

module Windows where

import           Control.Monad                 (void)
import qualified Data.Text                     as Text
import           Data.Vector                   (Vector)
import qualified Data.Vector                   as Vector
import           GI.Gtk                        (Box (..), Label (..),
                                                Orientation (..), Window (..))
import           GI.Gtk.Declarative
import           GI.Gtk.Declarative.App.Simple

type State = ()

data Event = Closed

view' :: State -> AppView Window Event
view' _ =
  bin Window [ #title := "Top Window"
             , #widthRequest := 600
             , on #deleteEvent (const (True, Closed))
             ]
  (container Box [#orientation := OrientationVertical] windows)
  where
    windows :: Vector (BoxChild Event)
    windows = Vector.generate 5 $ \(succ -> i) ->
      let
        lbl = "Window " <> Text.pack (show i)
        size = 600 - fromIntegral i * 25
      in
        BoxChild defaultBoxChildProperties $
        bin Window [ #title := lbl
                   , #widthRequest := size
                   , #heightRequest := size
                   , on #deleteEvent (const (True, Closed))
                   ]
        (widget Label [#label :=lbl])


update' :: State -> Event -> Transition State Event
update' _ Closed = Exit

main :: IO ()
main = void $ run App
  { view         = view'
  , update       = update'
  , inputs       = []
  , initialState = ()
  }

As you can see, "Top Window" seems to take the full height of the child windows:

Screenshot from 2019-04-06 10-05-51

I can see two solutions:

  1. Create a specific window container that is only used for spawning sub-windows, that will not add them as widgets in the container taking any space
  2. Have some sort of edge case check in regular widgets (if the child widget to add is a Window or subtype) and if so only instantiate it, don't add it to the container

I'm not sure which approach is better, but I'm leaning towards 1. Would you be interested in providing a PR?

@futpib
Copy link
Author

futpib commented Apr 6, 2019

Would you be interested in providing a PR?

I'll give it a shot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants