-- | A widget containing non-interactive text that reacts to changes. To prevent changes in GUI layout
-- when the text changes, a maximum number of characters must be given. The label will request space
-- for exactly that number of characters. If the input string contains more characters than can be 
-- displayed by the label, ellipsis (...) will be used.
gtkReactLabel :: Int                   -- ^ The maximum number of characters. Note: In GTK, values less than 3 are treated as 3.
              -> TextAlignment
              -> React.Discrete String -- ^ Transient text message.
              -> Widget ()
gtkReactLabel maxChars textAlignment stream = Widget {
    widgetRealize = do
        lbl <- liftIO $ do
            lbl <- Gtk.labelNew (Just (React.initial stream))
            Gtk.labelSetLineWrap lbl True
            Gtk.labelSetWidthChars lbl maxChars
            Gtk.set lbl [ Gtk.miscXalign Gtk.:= _xAlign 
                (_horizontalAlignmentFromTextAlignment textAlignment) ]
            Gtk.labelSetJustify lbl textAlignment
            Gtk.labelSetEllipsize lbl EllipsizeEnd
            return lbl
        React.reactimate (fmap (Gtk.labelSetText lbl) (React.changes stream))
        return (Gtk.toWidget lbl, ())
}
gtkReactLabel :: Int                   -- ^ The maximum number of characters. Note: In GTK, values less than 3 are treated as 3.
              -> TextAlignment
              -> React.Discrete String -- ^ Transient text message.
              -> Widget ()
gtkReactLabel maxChars textAlignment stream = Widget {
    widgetRealize = do
        lbl <- liftIO $ do
            lbl <- Gtk.labelNew (Just (React.initial stream))
            Gtk.labelSetLineWrap lbl True
            Gtk.labelSetWidthChars lbl maxChars
            Gtk.set lbl [ Gtk.miscXalign Gtk.:= _xAlign 
                (_horizontalAlignmentFromTextAlignment textAlignment) ]
            Gtk.labelSetJustify lbl textAlignment
            Gtk.labelSetEllipsize lbl EllipsizeEnd
            return lbl
        React.reactimate (fmap (Gtk.labelSetText lbl) (React.changes stream))
        return (Gtk.toWidget lbl, ())
}
gtkReactLabel maxChars textAlignment stream = Widget {
    widgetRealize = do
        lbl <- liftIO $ do
            lbl <- Gtk.labelNew (Just (React.initial stream))
            Gtk.labelSetLineWrap lbl True
            Gtk.labelSetWidthChars lbl maxChars
            Gtk.set lbl [ Gtk.miscXalign Gtk.:= _xAlign 
                (_horizontalAlignmentFromTextAlignment textAlignment) ]
            Gtk.labelSetJustify lbl textAlignment
            Gtk.labelSetEllipsize lbl EllipsizeEnd
            return lbl
        React.reactimate (fmap (Gtk.labelSetText lbl) (React.changes stream))
        return (Gtk.toWidget lbl, ())
}