Add focusHover style state (needed to be able to maintain border for active widgets)

This commit is contained in:
Francisco Vallarino 2021-01-06 14:08:42 -03:00
parent 54859fb2a4
commit cc512e024e
8 changed files with 42 additions and 22 deletions

View File

@ -116,13 +116,14 @@ handleAppEvent wenv model evt = case evt of
_ -> []
buildUI :: WidgetEnv App AppEvent -> App -> WidgetNode App AppEvent
buildUI wenv model = trace "Creating UI" widgetTree where
buildUI wenv model = trace "Creating UI" widgetHover where
widgetHover = vstack [
-- hstack [
-- label "Test" `hover` [bgColor red, textSize 32],
-- label "Test" `hover` [bgColor green],
-- textField textField1 `hover` [bgColor orange, textSize 32]
-- ],
hstack [
label "Test" `hover` [bgColor red, textSize 32],
label "Test" `hover` [bgColor green],
textField textField1 `hover` [bgColor orange, textSize 32]
],
textDropdown dropdown1 items id,
vstack $ fmap (\i -> label ("AAAA: " <> showt i) `hover` [textSize 40]) [1..10::Int],
listView dropdown1 items label
]

View File

@ -34,6 +34,7 @@ data Style = Style {
_styleBasic :: Maybe StyleState,
_styleHover :: Maybe StyleState,
_styleFocus :: Maybe StyleState,
_styleFocusHover :: Maybe StyleState,
_styleDisabled :: Maybe StyleState
} deriving (Eq, Show)
@ -42,6 +43,7 @@ instance Default Style where
_styleBasic = Nothing,
_styleHover = Nothing,
_styleFocus = Nothing,
_styleFocusHover = Nothing,
_styleDisabled = Nothing
}
@ -50,6 +52,7 @@ instance Semigroup Style where
_styleBasic = _styleBasic style1 <> _styleBasic style2,
_styleHover = _styleHover style1 <> _styleHover style2,
_styleFocus = _styleFocus style1 <> _styleFocus style2,
_styleFocusHover = _styleFocusHover style1 <> _styleFocusHover style2,
_styleDisabled = _styleDisabled style1 <> _styleDisabled style2
}

View File

@ -13,6 +13,7 @@ data Theme = Theme {
_themeBasic :: ThemeState,
_themeHover :: ThemeState,
_themeFocus :: ThemeState,
_themeFocusHover :: ThemeState,
_themeDisabled :: ThemeState
} deriving (Eq, Show)
@ -21,6 +22,7 @@ instance Default Theme where
_themeBasic = def,
_themeHover = def,
_themeFocus = def,
_themeFocusHover = def,
_themeDisabled = def
}

View File

@ -20,6 +20,7 @@ darkTheme = Theme {
_themeBasic = darkBasic,
_themeHover = darkHover,
_themeFocus = darkFocus,
_themeFocusHover = darkFocusHover,
_themeDisabled = darkDisabled
}
@ -153,7 +154,7 @@ darkFocus = darkBasic
& L.checkboxStyle . L.fgColor ?~ lightSkyBlue
& L.dropdownStyle . L.border ?~ borderFocus
& L.dropdownListStyle . L.border ?~ borderFocus
& L.dropdownItemStyle . L.bgColor ?~ lightGray
& L.dropdownItemStyle . L.border ?~ border 1 gray
& L.dropdownItemSelectedStyle . L.border ?~ border 1 lightGray
& L.inputFloatingStyle . L.border ?~ borderFocus
& L.inputIntegralStyle . L.border ?~ borderFocus
@ -163,5 +164,8 @@ darkFocus = darkBasic
& L.listViewItemSelectedStyle . L.border ?~ border 1 lightGray
& L.radioStyle . L.fgColor ?~ lightSkyBlue
darkFocusHover :: ThemeState
darkFocusHover = darkFocus
darkDisabled :: ThemeState
darkDisabled = darkBasic

View File

@ -457,17 +457,19 @@ getItemStyle node idx = itStyle where
getSlStyle :: WidgetEnv s e -> ListViewCfg s e a -> Style
getSlStyle wenv config = slStyle where
slTheme = collectTheme wenv L.listViewItemSelectedStyle
slStyleCfg = _lvcItemSelectedStyle config
slStyle = fromJust (Just slTheme <> slStyleCfg)
theme = collectTheme wenv L.listViewItemSelectedStyle
style = fromJust (Just theme <> _lvcItemSelectedStyle config)
slStyle = style
& L.hover .~ style ^. L.focusHover
& L.basic .~ style ^. L.focus
getHlStyle :: WidgetEnv s e -> ListViewCfg s e a -> Style
getHlStyle wenv config = hlStyle where
normalTheme = collectTheme wenv L.listViewItemStyle
normalStyle = fromJust (Just normalTheme <> _lvcItemStyle config)
hlStyle = normalStyle
& L.hover .~ normalStyle ^. L.focus <> normalStyle ^. L.hover
& L.basic .~ normalStyle ^. L.focus
theme = collectTheme wenv L.listViewItemStyle
style = fromJust (Just theme <> _lvcItemStyle config)
hlStyle = style
& L.hover .~ style ^. L.focusHover
& L.basic .~ style ^. L.focus
makeItemsList
:: (Eq a)

View File

@ -44,7 +44,7 @@ activeStyle_ isHoveredFn wenv node = fromMaybe def styleState where
isFocus = isFocused wenv node
styleState
| not isEnabled = _styleDisabled
| isHover && isFocus = _styleFocus <> _styleHover
| isHover && isFocus = _styleFocusHover
| isHover = _styleHover
| isFocus = _styleFocus
| otherwise = _styleBasic
@ -57,7 +57,7 @@ focusedStyle_ isHoveredFn wenv node = fromMaybe def styleState where
Style{..} = node ^. L.info . L.style
isHover = isHoveredFn wenv node
styleState
| isHover = _styleFocus <> _styleHover
| isHover = _styleFocusHover
| otherwise = _styleFocus
activeTheme :: WidgetEnv s e -> WidgetNode s e -> ThemeState
@ -166,6 +166,7 @@ baseStyleFromTheme theme = style where
_styleBasic = fromThemeState (_themeBasic theme),
_styleHover = fromThemeState (_themeHover theme),
_styleFocus = fromThemeState (_themeFocus theme),
_styleFocusHover = fromThemeState (_themeFocusHover theme),
_styleDisabled = fromThemeState (_themeDisabled theme)
}
fromThemeState tstate = Just $ def {
@ -176,10 +177,12 @@ baseStyleFromTheme theme = style where
mergeBasicStyle :: Style -> Style
mergeBasicStyle st = newStyle where
focusHover = _styleHover st <> _styleFocus st <> _styleFocusHover st
newStyle = Style {
_styleBasic = _styleBasic st,
_styleHover = _styleBasic st <> _styleHover st,
_styleFocus = _styleBasic st <> _styleFocus st,
_styleFocusHover = _styleBasic st <> focusHover,
_styleDisabled = _styleBasic st <> _styleDisabled st
}

View File

@ -47,22 +47,26 @@ collectThemeField wenv fieldS fieldT = style where
& fieldS ?~ wenv ^. L.theme . L.hover . fieldT
focus = Just $ base ^. L.focus . non def
& fieldS ?~ wenv ^. L.theme . L.focus . fieldT
focusHover = Just $ base ^. L.focusHover . non def
& fieldS ?~ wenv ^. L.theme . L.focusHover . fieldT
disabled = Just $ base ^. L.disabled . non def
& fieldS ?~ wenv ^. L.theme . L.disabled . fieldT
style = Style basic hover focus disabled
style = Style basic hover focus focusHover disabled
collectTheme :: WidgetEnv s e -> Lens' ThemeState StyleState -> Style
collectTheme wenv fieldT = style where
basic = Just $ wenv ^. L.theme . L.basic . fieldT
hover = Just $ wenv ^. L.theme . L.hover . fieldT
focus = Just $ wenv ^. L.theme . L.focus . fieldT
focusHover = Just $ wenv ^. L.theme . L.focusHover . fieldT
disabled = Just $ wenv ^. L.theme . L.disabled . fieldT
style = Style basic hover focus disabled
style = Style basic hover focus focusHover disabled
collectUserTheme :: WidgetEnv s e -> String -> Style
collectUserTheme wenv name = style where
basic = wenv ^. L.theme . L.basic . L.userStyleMap . at name
hover = wenv ^. L.theme . L.hover . L.userStyleMap . at name
focus = wenv ^. L.theme . L.focus . L.userStyleMap . at name
focusHover = wenv ^. L.theme . L.focusHover . L.userStyleMap . at name
disabled = wenv ^. L.theme . L.disabled . L.userStyleMap . at name
style = Style basic hover focus disabled
style = Style basic hover focus focusHover disabled

View File

@ -383,6 +383,9 @@
- Label needs to rebuild its glyphs if style/renderArea changes
- Listview needs to update sizeReq of modified items
- If sizeReq changes, it should request ResizeWidgets
- When hover is lost, size is not reduced/recalculated
- Handle Window Lost Focus
- Not needed; I thought it was part of the previous issue
- Pending
- Add header in all files, indicating license and documenting what the module does
@ -395,8 +398,6 @@
- Add user documentation
Maybe postponed after release?
- When hover is lost, size is not reduced/recalculated
- Handle Window Lost Focus
- Rethink, again, order of style merging (focus/hover)
- Focus border gets lost
- Maybe a FocusHover style is needed?