mirror of
https://github.com/fjvallarino/monomer.git
synced 2024-09-20 16:27:49 +03:00
Fix issue on rect/size operations (w/h = 0 should be considered valid)
This commit is contained in:
parent
d5fa1a03ae
commit
d9b112fc73
50
app/Main.hs
50
app/Main.hs
@ -30,7 +30,7 @@ main = do
|
|||||||
-- & L.hover . L.fgColor .~ white
|
-- & L.hover . L.fgColor .~ white
|
||||||
-- & L.focus . L.fgColor .~ white
|
-- & L.focus . L.fgColor .~ white
|
||||||
let config = [
|
let config = [
|
||||||
--windowSize (1280, 960),
|
windowSize (1280, 960),
|
||||||
--windowSize (320, 240),
|
--windowSize (320, 240),
|
||||||
useHdpi True,
|
useHdpi True,
|
||||||
appTheme theme,
|
appTheme theme,
|
||||||
@ -78,10 +78,8 @@ handleAppEvent model evt = case evt of
|
|||||||
_ -> []
|
_ -> []
|
||||||
|
|
||||||
buildUI :: App -> WidgetInstance App AppEvent
|
buildUI :: App -> WidgetInstance App AppEvent
|
||||||
buildUI model = trace "Creating UI" widgetTree9 where
|
buildUI model = trace "Creating UI" widgetTree2 where
|
||||||
--widgetTree8 = box (image_ "assets/images/pecans.jpg" [fitFill] `style` [width 200])
|
widgetTree2 = zstack [
|
||||||
--widgetTree8 = hstack [image_ "assets/images/pecans.jpg" [fitFill] `style` [width 200]] --
|
|
||||||
widgetTree9 = zstack [
|
|
||||||
vstack [
|
vstack [
|
||||||
hstack [
|
hstack [
|
||||||
radio fruit Apple,
|
radio fruit Apple,
|
||||||
@ -98,47 +96,14 @@ buildUI model = trace "Creating UI" widgetTree9 where
|
|||||||
--dropdown dropdown1 items id label
|
--dropdown dropdown1 items id label
|
||||||
label "Text",
|
label "Text",
|
||||||
textField textField1
|
textField textField1
|
||||||
] -- `style` [padding 10]
|
]-- `style` [padding 10]
|
||||||
]
|
|
||||||
widgetTree8 = box (scroll (image_ "assets/images/beach.jpg" [fitFill]) `style` [width 400, height 300])
|
|
||||||
widgetTree7 = hstack [
|
|
||||||
checkbox condition1 `style` [fgColor yellow, bgColor orange],
|
|
||||||
radio fruit Apple `style` [fgColor brown, bgColor yellow]
|
|
||||||
--,
|
|
||||||
--checkbox condition2,
|
|
||||||
--checkbox condition3
|
|
||||||
]
|
|
||||||
widgetTree6 = vstack [
|
|
||||||
textField textField1 `style` [bgColor orange, textLeft],
|
|
||||||
textField textField1 `style` [bgColor red, textLeft],
|
|
||||||
textField textField1 `style` [bgColor brown, textLeft],
|
|
||||||
hgrid [
|
|
||||||
textField textField1 `style` [bgColor lightBlue, textLeft],
|
|
||||||
textField textField1 `style` [bgColor blue, textLeft],
|
|
||||||
textField textField1 `style` [bgColor darkBlue, textLeft]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
widgetTree5 = vstack [
|
|
||||||
textDropdown_ dropdown1 items id [onChange DropdownVal, onChangeIdx DropdownIdx] `style` [bgColor lightBlue],
|
|
||||||
textField textField1 `style` [bgColor lightBlue, textLeft],
|
|
||||||
image_ "assets/images/pecans.jpg" [fitFill] `style` [minWidth 200]
|
|
||||||
]
|
]
|
||||||
widgetTree = zstack [
|
widgetTree = zstack [
|
||||||
widgetTree3,
|
widgetTreeFull,
|
||||||
alert "Message" CloseAlert `visible` model ^. showAlert,
|
alert "Message" CloseAlert `visible` model ^. showAlert,
|
||||||
confirm "Message" AcceptConfirm CancelConfirm `visible` model ^. showConfirm
|
confirm "Message" AcceptConfirm CancelConfirm `visible` model ^. showConfirm
|
||||||
--confirm "Message" AcceptConfirm CancelConfirm
|
|
||||||
--widgetTree2,
|
|
||||||
--widgetTree1
|
|
||||||
]
|
]
|
||||||
widgetTree1 = vstack [
|
widgetTreeFull = vstack [
|
||||||
--label (model ^. textField1) `style` [bgColor lightBlue, textLeft]
|
|
||||||
alert "Message" RunShortTask
|
|
||||||
--,
|
|
||||||
--textField textField1 `style` [bgColor lightBlue, textLeft]
|
|
||||||
]
|
|
||||||
widgetTree2 = textField textField1 `style` [bgColor lightBlue, textLeft]
|
|
||||||
widgetTree3 = vstack [
|
|
||||||
hstack [
|
hstack [
|
||||||
radioV (model ^. fruit) RadioSt Apple,
|
radioV (model ^. fruit) RadioSt Apple,
|
||||||
radioV (model ^. fruit) RadioSt Orange,
|
radioV (model ^. fruit) RadioSt Orange,
|
||||||
@ -179,7 +144,4 @@ buildUI model = trace "Creating UI" widgetTree9 where
|
|||||||
textDropdown_ textField1 items id [onChange DropdownVal, onChangeIdx DropdownIdx],
|
textDropdown_ textField1 items id [onChange DropdownVal, onChangeIdx DropdownIdx],
|
||||||
button "Click me" (PrintMessage "Button clicked")
|
button "Click me" (PrintMessage "Button clicked")
|
||||||
] `key` "main vstack" `style` [borderT 20 red, borderL 10 blue, borderR 10 green, borderB 10 gray, iradius 50] --, padding 20
|
] `key` "main vstack" `style` [borderT 20 red, borderL 10 blue, borderR 10 green, borderB 10 gray, iradius 50] --, padding 20
|
||||||
newLabel i = label ("New: " <> showt i) `style` [altColor i]
|
|
||||||
altColor i = bgColor (if even i then gray else darkGray)
|
|
||||||
labels = newLabel <$> [0..(model ^. clickCount - 1)]
|
|
||||||
items = fmap showt [1..100::Int]
|
items = fmap showt [1..100::Int]
|
||||||
|
@ -11,3 +11,4 @@ Why do you use lawless typeclasses for combinators?
|
|||||||
Why isn't StyleState using Phantom Types? Those styleX functions could be made safer.
|
Why isn't StyleState using Phantom Types? Those styleX functions could be made safer.
|
||||||
Why did you add themes, considering you can easily create a customized version of a widget by just writing a function and using it across the application?
|
Why did you add themes, considering you can easily create a customized version of a widget by just writing a function and using it across the application?
|
||||||
Why did you remove Margin?
|
Why did you remove Margin?
|
||||||
|
Why return Maybe from rect/size operations? (word this question properly before answering)
|
||||||
|
@ -55,7 +55,7 @@ addToSize (Size w h) w2 h2 = newSize where
|
|||||||
nw = w + w2
|
nw = w + w2
|
||||||
nh = h + h2
|
nh = h + h2
|
||||||
newSize
|
newSize
|
||||||
| nw > 0 && nh > 0 = Just $ Size nw nh
|
| nw >= 0 && nh >= 0 = Just $ Size nw nh
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
|
|
||||||
subtractFromSize :: Size -> Double -> Double -> Maybe Size
|
subtractFromSize :: Size -> Double -> Double -> Maybe Size
|
||||||
@ -63,7 +63,7 @@ subtractFromSize (Size w h) w2 h2 = newSize where
|
|||||||
nw = w - w2
|
nw = w - w2
|
||||||
nh = h - h2
|
nh = h - h2
|
||||||
newSize
|
newSize
|
||||||
| nw > 0 && nh > 0 = Just $ Size nw nh
|
| nw >= 0 && nh >= 0 = Just $ Size nw nh
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
|
|
||||||
rectInRect :: Rect -> Rect -> Bool
|
rectInRect :: Rect -> Rect -> Bool
|
||||||
@ -86,20 +86,20 @@ addToRect :: Rect -> Double -> Double -> Double -> Double -> Maybe Rect
|
|||||||
addToRect (Rect x y w h) l r t b = newRect where
|
addToRect (Rect x y w h) l r t b = newRect where
|
||||||
nx = x - l
|
nx = x - l
|
||||||
ny = y - t
|
ny = y - t
|
||||||
nw = max 0 $ w + l + r
|
nw = w + l + r
|
||||||
nh = max 0 $ h + t + b
|
nh = h + t + b
|
||||||
newRect
|
newRect
|
||||||
| nw > 0 && nh > 0 = Just $ Rect nx ny nw nh
|
| nw >= 0 && nh >= 0 = Just $ Rect nx ny nw nh
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
|
|
||||||
subtractFromRect :: Rect -> Double -> Double -> Double -> Double -> Maybe Rect
|
subtractFromRect :: Rect -> Double -> Double -> Double -> Double -> Maybe Rect
|
||||||
subtractFromRect (Rect x y w h) l r t b = newRect where
|
subtractFromRect (Rect x y w h) l r t b = newRect where
|
||||||
nx = x + l
|
nx = x + l
|
||||||
ny = y + t
|
ny = y + t
|
||||||
nw = max 0 $ w - l - r
|
nw = w - l - r
|
||||||
nh = max 0 $ h - t - b
|
nh = h - t - b
|
||||||
newRect
|
newRect
|
||||||
| nw > 0 && nh > 0 = Just $ Rect nx ny nw nh
|
| nw >= 0 && nh >= 0 = Just $ Rect nx ny nw nh
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
|
|
||||||
intersectRects :: Rect -> Rect -> Maybe Rect
|
intersectRects :: Rect -> Rect -> Maybe Rect
|
||||||
@ -111,5 +111,5 @@ intersectRects (Rect x1 y1 w1 h1) (Rect x2 y2 w2 h2) = newRect where
|
|||||||
nw = nx2 - nx1
|
nw = nx2 - nx1
|
||||||
nh = ny2 - ny1
|
nh = ny2 - ny1
|
||||||
newRect
|
newRect
|
||||||
| nw > 0 && nh > 0 = Just $ Rect nx1 ny1 nw nh
|
| nw >= 0 && nh >= 0 = Just $ Rect nx1 ny1 nw nh
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
|
@ -158,9 +158,7 @@ makeBox config = widget where
|
|||||||
raChild = Rect cx cy (min cw contentW) (min ch contentH)
|
raChild = Rect cx cy (min cw contentW) (min ch contentH)
|
||||||
ah = fromMaybe ACenter (_boxAlignH config)
|
ah = fromMaybe ACenter (_boxAlignH config)
|
||||||
av = fromMaybe AMiddle (_boxAlignV config)
|
av = fromMaybe AMiddle (_boxAlignV config)
|
||||||
vpContent
|
vpContent = fromMaybe def (intersectRects viewport contentArea)
|
||||||
| rectInRect contentArea viewport = contentArea
|
|
||||||
| otherwise = viewport
|
|
||||||
raAligned = alignInRect ah av contentArea raChild
|
raAligned = alignInRect ah av contentArea raChild
|
||||||
vpAligned = fromMaybe def (intersectRects viewport raAligned)
|
vpAligned = fromMaybe def (intersectRects viewport raAligned)
|
||||||
expand = fromMaybe False (_boxExpandContent config)
|
expand = fromMaybe False (_boxExpandContent config)
|
||||||
|
@ -82,8 +82,9 @@ makeLabel config state = widget where
|
|||||||
|
|
||||||
resize wenv viewport renderArea inst = newInst where
|
resize wenv viewport renderArea inst = newInst where
|
||||||
style = activeStyle wenv inst
|
style = activeStyle wenv inst
|
||||||
|
contentArea = fromMaybe def (removeOuterBounds style renderArea)
|
||||||
(newCaptionFit, _) = case textOverflow of
|
(newCaptionFit, _) = case textOverflow of
|
||||||
Ellipsis -> fitText wenv style renderArea caption
|
Ellipsis -> fitText wenv style contentArea caption
|
||||||
_ -> (caption, def)
|
_ -> (caption, def)
|
||||||
newWidget
|
newWidget
|
||||||
| captionFit == newCaptionFit = _wiWidget inst
|
| captionFit == newCaptionFit = _wiWidget inst
|
||||||
|
13
tasks.md
13
tasks.md
@ -238,12 +238,13 @@
|
|||||||
- Add way of ignoring unassigned events in stack (or return nothing from findByPoint)
|
- Add way of ignoring unassigned events in stack (or return nothing from findByPoint)
|
||||||
- Update style when merging to avoid recalculating/merging theme every time
|
- Update style when merging to avoid recalculating/merging theme every time
|
||||||
- Use theme for all components
|
- Use theme for all components
|
||||||
|
|
||||||
- Pending
|
|
||||||
- Replace uses of Seq.zip with foldlWithIndex
|
- Replace uses of Seq.zip with foldlWithIndex
|
||||||
- Check provided renderArea is used correctly
|
- Check provided renderArea is used correctly
|
||||||
- Hover should only be active for top level item
|
|
||||||
- Provided viewport should consider parent viewport
|
- Provided viewport should consider parent viewport
|
||||||
|
- Check scroll styling works correctly (contentRect being applied, etc)
|
||||||
|
- Also handle hover so scrollbars get correct cursor
|
||||||
|
|
||||||
|
- Pending
|
||||||
- Check 1px difference on right side of labels/buttons
|
- Check 1px difference on right side of labels/buttons
|
||||||
- Multiline label
|
- Multiline label
|
||||||
- Add testing
|
- Add testing
|
||||||
@ -264,21 +265,21 @@ Maybe postponed after release?
|
|||||||
- Button should receive focus
|
- Button should receive focus
|
||||||
- Handle window title, maximize, etc
|
- Handle window title, maximize, etc
|
||||||
- Also handle as requests?
|
- Also handle as requests?
|
||||||
- Check scroll styling works correctly (contentRect being applied, etc)
|
|
||||||
- Also handle hover so scrollbars get correct cursor
|
|
||||||
- Handle onBlur/onFocus in all focusable widgets
|
- Handle onBlur/onFocus in all focusable widgets
|
||||||
- Maybe unify criteria on zstack? Top layer config for both focus/click?
|
- Maybe unify criteria on zstack? Top layer config for both focus/click?
|
||||||
- Avoid findNextFocus on unfocusable children (listView items)
|
- Avoid findNextFocus on unfocusable children (listView items)
|
||||||
- Restore focus to previous widget when zstack changes (dialog situation)
|
- Restore focus to previous widget when zstack changes (dialog situation)
|
||||||
- Also think about not losing focus because of click (when onlyTopFocusable is active)
|
- Also think about not losing focus because of click (when onlyTopFocusable is active)
|
||||||
- Find way of avoiding hover effects when widget is not in the top layer
|
- Find way of avoiding hover effects when widget is not in the top layer
|
||||||
|
- Hover should only be active for top level item
|
||||||
|
- I need to think a way of setting a layer state for zstack
|
||||||
- Further textField improvements
|
- Further textField improvements
|
||||||
- Double clicking on empty puts the cursor at the end of ghost character
|
- Double clicking on empty puts the cursor at the end of ghost character
|
||||||
- Right aligned version has cusor overlaid
|
- Right aligned version has cusor overlaid
|
||||||
- Handle mouse selection
|
- Handle mouse selection
|
||||||
- Handle undo history
|
- Handle undo history
|
||||||
- Create numeric wrapper that allows increasing/decreasing with mouse
|
- Create numeric wrapper that allows increasing/decreasing with mouse
|
||||||
- Add maps on Theme to handle user widget settings
|
- Add Maps on Theme to handle user widget settings
|
||||||
- Create Keystroke component (shortcuts and general key handling like Esc for dialog)
|
- Create Keystroke component (shortcuts and general key handling like Esc for dialog)
|
||||||
- Create Tooltip component. It just wraps a given component and draws the tooltip with renderOverlay
|
- Create Tooltip component. It just wraps a given component and draws the tooltip with renderOverlay
|
||||||
- Create Theme widget to override global theme
|
- Create Theme widget to override global theme
|
||||||
|
Loading…
Reference in New Issue
Block a user