Skip to content

Commit beb60e5

Browse files
committed
Use styling inside the EventsView
Use styleGetBackground and styleGetForeground with the appropriate StateType to apply the background and foreground colors. Remove widgetModifyBg for making the background white for this to work. This didn't have any effect on the background color anymore to begin with but was overriding the colors for the other StateTypes.
1 parent 887ac0c commit beb60e5

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

GUI/EventsView.hs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ module GUI.EventsView (
1313
) where
1414

1515
import GHC.RTS.Events
16-
import Debug.Trace
1716

1817
import Graphics.UI.Gtk hiding (rectangle)
1918
import Graphics.Rendering.Cairo
20-
import qualified GUI.GtkExtras as GtkExt
19+
import GUI.ViewerColours
2120

2221
import Control.Monad
23-
import Control.Monad.Reader
2422
import Data.Array
2523
import Data.Monoid
2624
import Data.IORef
@@ -68,8 +66,6 @@ eventsViewNew builder EventsViewActions{..} = do
6866
vScrollbar <- getWidget castToVScrollbar ("eventsVScroll" :: T.Text)
6967
adj <- get vScrollbar rangeAdjustment
7068

71-
-- make the background white
72-
widgetModifyBg drawArea StateNormal (Color 0xffff 0xffff 0xffff)
7369
widgetSetCanFocus drawArea True
7470
--TODO: needs to be reset on each style change ^^
7571

@@ -306,8 +302,7 @@ drawEvents EventsView{drawArea, adj}
306302
sequence_
307303
[ do when (inside || selected) $
308304
renderWithDrawWindow win $ do
309-
-- TODO: figure out how I can grab the correct color from GTK's style
310-
setSourceRGBA 0.2 1 1 0.2
305+
setSourceRGBAForStyle styleGetBackground style state1
311306
rectangle 0 y (fromIntegral width) lineHeight
312307
fill
313308

@@ -316,6 +311,7 @@ drawEvents EventsView{drawArea, adj}
316311
layoutSetAlignment layout AlignRight
317312
layoutSetWidth layout (Just (fromIntegral timeWidth))
318313
renderWithDrawWindow win $ do
314+
setForegroundColor style state2
319315
moveTo 0 y
320316
showLayout layout
321317

@@ -324,6 +320,7 @@ drawEvents EventsView{drawArea, adj}
324320
layoutSetAlignment layout AlignLeft
325321
layoutSetWidth layout (Just (fromIntegral descrWidth))
326322
renderWithDrawWindow win $ do
323+
setForegroundColor style state2
327324
moveTo (fromIntegral $ timeWidth + columnGap) y
328325
showLayout layout
329326

@@ -333,7 +330,7 @@ drawEvents EventsView{drawArea, adj}
333330
inside = maybe False (\ (s, e) -> s <= n && n <= e) mrange
334331
selected = cursorPos == n
335332
(state1, state2)
336-
| inside = (StatePrelight, StatePrelight)
333+
| inside = (StateSelected, StateSelected)
337334
| selected = (state, state)
338335
| otherwise = (state, StateNormal)
339336
]
@@ -349,6 +346,7 @@ drawEvents EventsView{drawArea, adj}
349346
Message msg -> TB.fromText msg
350347
UserMessage msg -> TB.fromText msg
351348
_ -> buildEventInfo spec
349+
setForegroundColor = setSourceRGBAForStyle styleGetForeground
352350

353351
-------------------------------------------------------------------------------
354352

GUI/ViewerColours.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,11 @@ setSourceRGBAhex (Color r g b) t
137137
(fromIntegral b/0xFFFF) t
138138

139139
-------------------------------------------------------------------------------
140+
141+
-------------------------------------------------------------------------------
142+
setSourceRGBAForStyle :: (Style -> StateType -> IO Color) -> Style -> StateType -> Render ()
143+
setSourceRGBAForStyle getColor style state = do
144+
color <- liftIO $ getColor style state
145+
setSourceRGBAhex color 1
146+
147+
-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)