mirror of
https://github.com/fjvallarino/monomer.git
synced 2024-11-10 11:21:50 +03:00
Avoid ghost cursor position on empty strings for inputField
This commit is contained in:
parent
a0bea51b42
commit
d0f4ca1754
@ -78,7 +78,7 @@ handleAppEvent model evt = case evt of
|
||||
_ -> []
|
||||
|
||||
buildUI :: App -> WidgetInstance App AppEvent
|
||||
buildUI model = trace "Creating UI" widgetTreeAlt where
|
||||
buildUI model = trace "Creating UI" widgetTree4 where
|
||||
widgetTreeAlt
|
||||
| model ^. clickCount `mod` 2 == 0 = widgetTree10
|
||||
| otherwise = widgetTree11
|
||||
|
@ -256,13 +256,12 @@ newRenderer c dpr lock envRef = Renderer {..} where
|
||||
-- Glyph position is usually used in local coord calculations, ignoring dpr
|
||||
setFont c envRef dpr font fontSize
|
||||
|
||||
glyphsPos <- fmap vecToSeq (textGlyphPositions c 0 0 text)
|
||||
glyphsPos <- fmap vecToSeq (textGlyphPositions c 0 0 message)
|
||||
|
||||
return $ foldl' reducer Seq.empty (Seq.zip glyphs glyphsPos)
|
||||
where
|
||||
text = if message == "" then " " else message
|
||||
vecToSeq = foldl' (|>) Seq.empty
|
||||
glyphs = Seq.fromList $ T.unpack text
|
||||
glyphs = Seq.fromList $ T.unpack message
|
||||
reducer acc glyph = acc |> convert glyph
|
||||
convert (glyph, pos) = GlyphPos {
|
||||
_glpGlyph = glyph,
|
||||
@ -340,6 +339,9 @@ getTextBounds
|
||||
-> Double
|
||||
-> Text
|
||||
-> IO (Double, Double, Double, Double)
|
||||
getTextBounds c x y "" = do
|
||||
(asc, desc, lineh) <- VG.textMetrics c
|
||||
return (x, y, 0, realToFrac lineh)
|
||||
getTextBounds c x y text = do
|
||||
VG.Bounds (VG.V4 x1 y1 x2 y2) <- VG.textBounds c cx cy text
|
||||
return (realToFrac x1, realToFrac y1, realToFrac x2, realToFrac y2)
|
||||
@ -370,6 +372,7 @@ handleImageRender c dpr rect alpha image = do
|
||||
|
||||
textGlyphPositions
|
||||
:: VG.Context -> Double -> Double -> Text -> IO (V.Vector VG.GlyphPosition)
|
||||
textGlyphPositions c x y "" = return V.empty
|
||||
textGlyphPositions c x y text = withCStringLen text $ \(ptr, len) ->
|
||||
VG.textGlyphPositions c cx cy ptr (ptr `plusPtr` len) count
|
||||
where
|
||||
|
@ -199,7 +199,9 @@ makeInputField config state = widget where
|
||||
contentArea = getContentArea style inst
|
||||
localX = x - _rX contentArea + _ifsOffset state
|
||||
textLen = getGlyphsMax (_ifsGlyphs state)
|
||||
glyphs = _ifsGlyphs state |> GlyphPos ' ' textLen 0 0
|
||||
glyphs
|
||||
| Seq.null (_ifsGlyphs state) = Seq.empty
|
||||
| otherwise = _ifsGlyphs state |> GlyphPos ' ' textLen 0 0
|
||||
glyphStart i g = (i, abs (_glpXMin g - localX))
|
||||
pairs = Seq.mapWithIndex glyphStart glyphs
|
||||
cpm (_, g1) (_, g2) = compare g1 g2
|
||||
@ -211,7 +213,7 @@ makeInputField config state = widget where
|
||||
}
|
||||
result
|
||||
| isFocused wenv inst = Just $ resultWidget newInst
|
||||
| otherwise = Just $ resultReqs [SetFocus $ _wiPath inst] inst
|
||||
| otherwise = Just $ resultReqs [SetFocus $ _wiPath inst] newInst
|
||||
|
||||
KeyAction mod code KeyPressed -> Just result where
|
||||
(newText, newPos, newSel) = handleKeyPress wenv mod code
|
||||
|
2
tasks.md
2
tasks.md
@ -253,7 +253,6 @@
|
||||
- Check getState/merge in all components
|
||||
|
||||
- Pending
|
||||
- TextOverflow in TextStyle?
|
||||
- Check 1px difference on right side of labels/buttons
|
||||
- Further textField improvements
|
||||
- Check displaced textField when adding characters on right align
|
||||
@ -281,6 +280,7 @@ Maybe postponed after release?
|
||||
- Create numeric wrapper that allows increasing/decreasing with mouse
|
||||
- Handle window title, maximize, etc
|
||||
- Also handle as requests?
|
||||
- TextOverflow in TextStyle?
|
||||
- Handle onBlur/onFocus in all focusable widgets
|
||||
- Avoid findNextFocus on unfocusable children (listView items)
|
||||
- Restore focus to previous widget when zstack changes (dialog situation)
|
||||
|
Loading…
Reference in New Issue
Block a user