Receive list of configs instead of single config. It looks clearer from the user side

This commit is contained in:
Francisco Vallarino 2020-09-28 20:44:04 -03:00
parent 6931a1543a
commit ac0cd5e581
12 changed files with 106 additions and 92 deletions

View File

@ -169,20 +169,20 @@ buildUI model = trace "Creating UI" widgetTree where
checkbox condition1,
checkbox condition2,
checkbox condition3,
checkbox_ condition1 (onChange CheckboxSt)
checkbox_ condition1 [onChange CheckboxSt]
],
label "Text",
textField_ textField2 (validInput validText2 <> maxLength 10 <> onChange PrintMessage <> selectOnFocus True)
textField_ textField2 [validInput validText2, maxLength 10, onChange PrintMessage, selectOnFocus True]
`style` if model ^. validText2 then def else border 1 red,
label "Floating",
floatingField_ float1 (validInput validFloat1)
floatingField_ float1 [validInput validFloat1]
`style` if model ^. validFloat1 then def else border 1 red,
label "Integer",
integralField_ word1 (validInput validWord1 <> maxValue 100)
integralField_ word1 [validInput validWord1, maxValue 100]
`style` if model ^. validWord1 then def else border 1 red,
integralField_ int1 (validInput validInt1 <> maxValue 100)
integralField_ int1 [validInput validInt1, maxValue 100]
`style` if model ^. validInt1 then def else border 1 red,
integralField_ integer1 (validInput validInteger1 <> minValue 10 <> maxValue 100)
integralField_ integer1 [validInput validInteger1, minValue 10, maxValue 100]
`style` if model ^. validInteger1 then def else border 1 red,
listView textField1 items label
] `style` borderT 20 red <> borderL 10 blue <> borderR 10 green <> borderB 10 gray <> iradius 50 -- <> padding 20

View File

@ -49,10 +49,12 @@ instance OnClickReq (ButtonCfg s e) s where
}
button :: Text -> e -> WidgetInstance s e
button label handler = button_ label (onClick handler)
button label handler = button_ label handler def
button_ :: Text -> ButtonCfg s e -> WidgetInstance s e
button_ label config = defaultWidgetInstance "button" (makeButton label config)
button_ :: Text -> e -> [ButtonCfg s e] -> WidgetInstance s e
button_ label handler configs = defaultWidgetInstance "button" widget where
config = onClick handler <> mconcat configs
widget = makeButton label config
makeButton :: Text -> ButtonCfg s e -> Widget s e
makeButton label config = widget where

View File

@ -66,18 +66,19 @@ checkboxBorderW = 2
checkbox :: ALens' s Bool -> WidgetInstance s e
checkbox field = checkbox_ field def
checkbox_ :: ALens' s Bool -> CheckboxCfg s e -> WidgetInstance s e
checkbox_ field config = checkboxD_ (WidgetLens field) def
checkbox_ :: ALens' s Bool -> [CheckboxCfg s e] -> WidgetInstance s e
checkbox_ field config = checkboxD_ (WidgetLens field) config
checkboxV :: Bool -> (Bool -> e) -> WidgetInstance s e
checkboxV value handler = checkboxV_ value handler def
checkboxV_ :: Bool -> (Bool -> e) -> CheckboxCfg s e -> WidgetInstance s e
checkboxV_ :: Bool -> (Bool -> e) -> [CheckboxCfg s e] -> WidgetInstance s e
checkboxV_ value handler config = checkboxD_ (WidgetValue value) newConfig where
newConfig = config <> onChange handler
newConfig = onChange handler : config
checkboxD_ :: WidgetData s Bool -> CheckboxCfg s e -> WidgetInstance s e
checkboxD_ widgetData config = checkboxInstance where
checkboxD_ :: WidgetData s Bool -> [CheckboxCfg s e] -> WidgetInstance s e
checkboxD_ widgetData configs = checkboxInstance where
config = mconcat configs
widget = makeCheckbox widgetData config
checkboxInstance = (defaultWidgetInstance "checkbox" widget) {
_wiFocusable = True

View File

@ -118,11 +118,11 @@ dropdown_
-> t a
-> (a -> Text)
-> (a -> WidgetInstance s e)
-> DropdownCfg s e a
-> [DropdownCfg s e a]
-> WidgetInstance s e
dropdown_ field items makeMain makeRow config = newInst where
dropdown_ field items makeMain makeRow configs = newInst where
widgetData = WidgetLens field
newInst = dropdownD_ widgetData items makeMain makeRow config
newInst = dropdownD_ widgetData items makeMain makeRow configs
dropdownV
:: (Traversable t, Eq a)
@ -142,11 +142,11 @@ dropdownV_
-> t a
-> (a -> Text)
-> (a -> WidgetInstance s e)
-> DropdownCfg s e a
-> [DropdownCfg s e a]
-> WidgetInstance s e
dropdownV_ value handler items makeMain makeRow config = newInst where
newConfig = config <> onChange handler
newInst = dropdownD_ (WidgetValue value) items makeMain makeRow newConfig
dropdownV_ value handler items makeMain makeRow configs = newInst where
newConfigs = onChange handler : configs
newInst = dropdownD_ (WidgetValue value) items makeMain makeRow newConfigs
dropdownD_
:: (Traversable t, Eq a)
@ -154,9 +154,10 @@ dropdownD_
-> t a
-> (a -> Text)
-> (a -> WidgetInstance s e)
-> DropdownCfg s e a
-> [DropdownCfg s e a]
-> WidgetInstance s e
dropdownD_ widgetData items makeMain makeRow config = makeInstance widget where
dropdownD_ widgetData items makeMain makeRow configs = makeInstance widget where
config = mconcat configs
newState = DropdownState False
newItems = foldl' (|>) Empty items
widget = makeDropdown widgetData newItems makeMain makeRow config newState
@ -294,7 +295,7 @@ makeDropdown widgetData items makeMain makeRow config state = widget where
widget = _wiWidget overlayInstance
renderAction = widgetRender widget renderer wenv overlayInstance
dropdownLabel wenv = makeMain $ currentValue wenv
dropdownLabel wenv = makeMain $ currentValue wenv
makeListView
:: (Eq a)
@ -307,10 +308,12 @@ makeListView
-> WidgetInstance s e
makeListView value items makeRow config path selected = listViewInst where
DropdownCfg{..} = config
lvConfig = onChangeReqIdx (SendMessage path . OnChangeMessage)
<> setStyle _ddcSelectedStyle selectedStyle
<> setStyle _ddcHighlightedStyle highlightedStyle
<> setStyle _ddcHoverStyle hoverStyle
lvConfig = [
onChangeReqIdx (SendMessage path . OnChangeMessage),
setStyle _ddcSelectedStyle selectedStyle,
setStyle _ddcHighlightedStyle highlightedStyle,
setStyle _ddcHoverStyle hoverStyle
]
listViewInst = listViewD_ value items makeRow lvConfig
setStyle :: (Default a) => Maybe StyleState -> (StyleState -> a) -> a

View File

@ -112,9 +112,9 @@ floatingField field = floatingField_ field def
floatingField_
:: FormattableFloat a
=> ALens' s a
-> FloatingFieldCfg s e a
-> [FloatingFieldCfg s e a]
-> WidgetInstance s e
floatingField_ field config = floatingFieldD_ (WidgetLens field) config
floatingField_ field configs = floatingFieldD_ (WidgetLens field) configs
floatingFieldV
:: FormattableFloat a
@ -125,19 +125,20 @@ floatingFieldV_
:: FormattableFloat a
=> a
-> (a -> e)
-> FloatingFieldCfg s e a
-> [FloatingFieldCfg s e a]
-> WidgetInstance s e
floatingFieldV_ value handler config = newInst where
floatingFieldV_ value handler configs = newInst where
widgetData = WidgetValue value
newConfig = config <> onChange handler
newInst = floatingFieldD_ widgetData newConfig
newConfigs = onChange handler : configs
newInst = floatingFieldD_ widgetData newConfigs
floatingFieldD_
:: FormattableFloat a
=> WidgetData s a
-> FloatingFieldCfg s e a
-> [FloatingFieldCfg s e a]
-> WidgetInstance s e
floatingFieldD_ widgetData config = newInst where
floatingFieldD_ widgetData configs = newInst where
config = mconcat configs
minVal = _ffcMinValue config
maxVal = _ffcMaxValue config
decimals = max 0 $ fromMaybe 2 (_ffcDecimals config)

View File

@ -101,9 +101,9 @@ integralField field = integralField_ field def
integralField_
:: FormattableInt a
=> ALens' s a
-> IntegralFieldCfg s e a
-> [IntegralFieldCfg s e a]
-> WidgetInstance s e
integralField_ field config = integralFieldD_ (WidgetLens field) config
integralField_ field configs = integralFieldD_ (WidgetLens field) configs
integralFieldV :: FormattableInt a => a -> (a -> e) -> WidgetInstance s e
integralFieldV value handler = integralFieldV_ value handler def
@ -112,19 +112,20 @@ integralFieldV_
:: FormattableInt a
=> a
-> (a -> e)
-> IntegralFieldCfg s e a
-> [IntegralFieldCfg s e a]
-> WidgetInstance s e
integralFieldV_ value handler config = newInst where
integralFieldV_ value handler configs = newInst where
widgetData = WidgetValue value
newConfig = config <> onChange handler
newInst = integralFieldD_ widgetData newConfig
newConfigs = onChange handler : configs
newInst = integralFieldD_ widgetData newConfigs
integralFieldD_
:: FormattableInt a
=> WidgetData s a
-> IntegralFieldCfg s e a
-> [IntegralFieldCfg s e a]
-> WidgetInstance s e
integralFieldD_ widgetData config = newInst where
integralFieldD_ widgetData configs = newInst where
config = mconcat configs
minVal = _nfcMinValue config
maxVal = _nfcMaxValue config
fromText = integralFromText minVal maxVal

View File

@ -117,10 +117,10 @@ listView_
=> ALens' s a
-> t a
-> (a -> WidgetInstance s e)
-> ListViewCfg s e a
-> [ListViewCfg s e a]
-> WidgetInstance s e
listView_ field items makeRow config = newInst where
newInst = listViewD_ (WidgetLens field) items makeRow config
listView_ field items makeRow configs = newInst where
newInst = listViewD_ (WidgetLens field) items makeRow configs
listViewV
:: (Traversable t, Eq a)
@ -138,21 +138,22 @@ listViewV_
-> (Int -> a -> e)
-> t a
-> (a -> WidgetInstance s e)
-> ListViewCfg s e a
-> [ListViewCfg s e a]
-> WidgetInstance s e
listViewV_ value handler items makeRow config = newInst where
listViewV_ value handler items makeRow configs = newInst where
widgetData = WidgetValue value
newConfig = config <> onChangeIdx handler
newInst = listViewD_ widgetData items makeRow newConfig
newConfigs = onChangeIdx handler : configs
newInst = listViewD_ widgetData items makeRow newConfigs
listViewD_
:: (Traversable t, Eq a)
=> WidgetData s a
-> t a
-> (a -> WidgetInstance s e)
-> ListViewCfg s e a
-> [ListViewCfg s e a]
-> WidgetInstance s e
listViewD_ widgetData items makeRow config = makeInstance widget where
listViewD_ widgetData items makeRow configs = makeInstance widget where
config = mconcat configs
newItems = foldl' (|>) Empty items
newState = ListViewState 0
widget = makeListView widgetData newItems makeRow config newState

View File

@ -66,24 +66,27 @@ radioBorderW = 2
radio :: (Eq a) => ALens' s a -> a -> WidgetInstance s e
radio field option = radio_ field option def
radio_ :: (Eq a) => ALens' s a -> a -> RadioCfg s e a -> WidgetInstance s e
radio_ field option config = radioD_ (WidgetLens field) option config
radio_ :: (Eq a) => ALens' s a -> a -> [RadioCfg s e a] -> WidgetInstance s e
radio_ field option configs = radioD_ (WidgetLens field) option configs
radioV :: (Eq a) => a -> (a -> e) -> a -> WidgetInstance s e
radioV value handler option = radioV_ value handler option def
radioV_ :: (Eq a) => a -> (a -> e) -> a -> RadioCfg s e a -> WidgetInstance s e
radioV_ value handler option config = radioD_ widgetData option newConfig where
radioV_
:: (Eq a) => a -> (a -> e) -> a -> [RadioCfg s e a] -> WidgetInstance s e
radioV_ value handler option configs = newInst where
widgetData = WidgetValue value
newConfig = config <> onChange handler
newConfigs = onChange handler : configs
newInst = radioD_ widgetData option newConfigs
radioD_
:: (Eq a)
=> WidgetData s a
-> a
-> RadioCfg s e a
-> [RadioCfg s e a]
-> WidgetInstance s e
radioD_ widgetData option config = radioInstance where
radioD_ widgetData option configs = radioInstance where
config = mconcat configs
widget = makeRadio widgetData option config
radioInstance = (defaultWidgetInstance "radio" widget) {
_wiFocusable = True

View File

@ -123,8 +123,9 @@ wheelRate = 10
scroll :: WidgetInstance s e -> WidgetInstance s e
scroll managedWidget = scroll_ def managedWidget
scroll_ :: ScrollCfg -> WidgetInstance s e -> WidgetInstance s e
scroll_ config managed = makeInstance (makeScroll config def) managed
scroll_ :: [ScrollCfg] -> WidgetInstance s e -> WidgetInstance s e
scroll_ configs managed = makeInstance (makeScroll config def) managed where
config = mconcat configs
makeInstance :: Widget s e -> WidgetInstance s e -> WidgetInstance s e
makeInstance widget managedWidget = (defaultWidgetInstance "scroll" widget) {

View File

@ -29,10 +29,10 @@ textDropdown_
=> ALens' s a
-> t a
-> (a -> Text)
-> DropdownCfg s e a
-> [DropdownCfg s e a]
-> WidgetInstance s e
textDropdown_ field items toText config = newInst where
newInst = textDropdownD_ (WidgetLens field) items toText config
textDropdown_ field items toText configs = newInst where
newInst = textDropdownD_ (WidgetLens field) items toText configs
textDropdownV
:: (Traversable t, Eq a)
@ -50,21 +50,21 @@ textDropdownV_
-> (a -> e)
-> t a
-> (a -> Text)
-> DropdownCfg s e a
-> [DropdownCfg s e a]
-> WidgetInstance s e
textDropdownV_ value handler items toText config = newInst where
textDropdownV_ value handler items toText configs = newInst where
widgetData = WidgetValue value
newConfig = config <> onChange handler
newInst = textDropdownD_ widgetData items toText newConfig
newConfigs = onChange handler : configs
newInst = textDropdownD_ widgetData items toText newConfigs
textDropdownD_
:: (Traversable t, Eq a)
=> WidgetData s a
-> t a
-> (a -> Text)
-> DropdownCfg s e a
-> [DropdownCfg s e a]
-> WidgetInstance s e
textDropdownD_ widgetData items toText config = newInst where
textDropdownD_ widgetData items toText configs = newInst where
makeMain = toText
makeRow = label . toText
newInst = dropdownD_ widgetData items makeMain makeRow config
newInst = dropdownD_ widgetData items makeMain makeRow configs

View File

@ -85,19 +85,20 @@ instance Default Text where
textField :: ALens' s Text -> WidgetInstance s e
textField field = textField_ field def
textField_ :: ALens' s Text -> TextFieldCfg s e -> WidgetInstance s e
textField_ field config = textFieldD_ (WidgetLens field) config
textField_ :: ALens' s Text -> [TextFieldCfg s e] -> WidgetInstance s e
textField_ field configs = textFieldD_ (WidgetLens field) configs
textFieldV :: Text -> (Text -> e) -> WidgetInstance s e
textFieldV value handler = textFieldV_ value handler def
textFieldV_ :: Text -> (Text -> e) -> TextFieldCfg s e -> WidgetInstance s e
textFieldV_ value handler config = textFieldD_ widgetData newConfig where
textFieldV_ :: Text -> (Text -> e) -> [TextFieldCfg s e] -> WidgetInstance s e
textFieldV_ value handler configs = textFieldD_ widgetData newConfig where
widgetData = WidgetValue value
newConfig = config <> onChange handler
newConfig = onChange handler : configs
textFieldD_ :: WidgetData s Text -> TextFieldCfg s e -> WidgetInstance s e
textFieldD_ widgetData config = inputField where
textFieldD_ :: WidgetData s Text -> [TextFieldCfg s e] -> WidgetInstance s e
textFieldD_ widgetData configs = inputField where
config = mconcat configs
fromText = textToText (_tfcMaxLength config)
inputConfig = InputFieldCfg {
_ifcValue = widgetData,

View File

@ -179,20 +179,16 @@
- Add mandatory event parameter for V constructors
- Why does the model update when trying to input a char in FloatingInput?
- Focus event not received after clicking and gaining focus
- Rethink focus handling. Maybe return a list of all focusable elements? Currently shift-tab is not possible
- Added a direction parameter to widgetFindNextFocus
- Pending
- Rethink focus handling. Maybe return a list of all focusable elements? Currently shift-tab is not possible
- http://hackage.haskell.org/package/data-clist-0.1.2.3
- Ver si tiene sentido esta opcion o es mejor volver a dos funciones
- Empezar desde atras pero con logica similar a la normal
- Think about argument position for widgets, in particular listview/radio
- Should value come before items/option?
- Should we use a list of configs instead of <> operator?
- Add options to label/button (ellipsis/cut)
- Add options to image widget (stretch/crop/etc)
- Add support for urls to image widget
- Compare Cairo/Skia interfaces to make Renderer able to handle future implementations
- Can _wiChildren be removed from Widget and only be kept in Container?
- Rename spacer
@ -213,9 +209,6 @@
- Add user documentation
Maybe postponed after release?
- Add options to image widget (stretch/crop/etc)
- Add support for urls to image widget
- Add options to label/button (ellipsis/cut)
- Further textField improvements
- Handle mouse selection
- Handle undo history
@ -234,3 +227,10 @@ Maybe postponed after release?
- Check if using [lifted-async](https://github.com/maoe/lifted-async) is worth it
- Implement SDL_Surface + Cairo backend
- Can we cache some drawing operations?
- Add new request types (drag started, drag stopped, drag cancelled)
- Add new events (drag hover)
- SDL supports Drag and Drop integration with OS
- Look for opportunities to reduce code duplication (CompositeWidget and BaseContainer)
- Check if using [lifted-async](https://github.com/maoe/lifted-async) is worth it
- Implement SDL_Surface + Cairo backend
- Can we cache some drawing operations?