module Manatee.Plugin.Anything.TitleWidget where
import Graphics.UI.Gtk
import Manatee.Toolkit.Gtk.Box
import Manatee.Toolkit.Gtk.Container
data TitleWidget =
TitleWidget {titleWidgetBox :: HBox
,titleWidgetLabel :: Label
,titleWidgetSpinner :: Spinner}
titleColor :: Color
titleColor = Color 61440 30464 17920
numberColor :: Color
numberColor = Color 25000 25000 25000
spinnerSpace :: Int
spinnerSpace = 6
titleWidgetNew :: Maybe String -> IO TitleWidget
titleWidgetNew title = do
box <- hBoxNew False 0
label <- labelNew title
spinner <- spinnerNew
boxPackStart box label PackRepel 0
widgetShowAll box
return $ TitleWidget box label spinner
titleWidgetSetTitle :: TitleWidget -> String -> Int -> IO ()
titleWidgetSetTitle widget title number
| number == 0 = do
labelSetText label title
labelSetAttributes label [AttrForeground 0 (length title) titleColor]
| otherwise = do
labelSetText label (title ++ numberStr)
labelSetAttributes label [AttrForeground 0 (length title) titleColor
,AttrWeight 0 (length title) WeightBold
,AttrForeground (length title) (length (title ++ numberStr)) numberColor]
where
label = titleWidgetLabel widget
numberStr = " (" ++ show number ++ ")"
titleWidgetStart :: TitleWidget -> IO ()
titleWidgetStart TitleWidget {titleWidgetBox = box
,titleWidgetSpinner = spinner} = do
boxTryPack box spinner PackNatural (Just 1) (Just spinnerSpace)
spinnerStart spinner
widgetShow spinner
titleWidgetStop :: TitleWidget -> IO ()
titleWidgetStop TitleWidget {titleWidgetBox = box
,titleWidgetSpinner = spinner} = do
containerTryRemove box spinner
spinnerStop spinner