gi-gtk-declarative icon indicating copy to clipboard operation
gi-gtk-declarative copied to clipboard

An app with multiple windows

Open futpib opened this issue 5 years ago • 2 comments

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

futpib avatar Apr 05 '19 22:04 futpib

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?

owickstrom avatar Apr 06 '19 08:04 owickstrom

Would you be interested in providing a PR?

I'll give it a shot

futpib avatar Apr 06 '19 15:04 futpib