diff --git a/app/Main.hs b/app/Main.hs index 7be8348d..fc5b349e 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -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 diff --git a/src/Monomer/Graphics/NanoVGRenderer.hs b/src/Monomer/Graphics/NanoVGRenderer.hs index ec118b51..34d9fba2 100644 --- a/src/Monomer/Graphics/NanoVGRenderer.hs +++ b/src/Monomer/Graphics/NanoVGRenderer.hs @@ -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 diff --git a/src/Monomer/Widgets/InputField.hs b/src/Monomer/Widgets/InputField.hs index b432ca30..eab75c3f 100644 --- a/src/Monomer/Widgets/InputField.hs +++ b/src/Monomer/Widgets/InputField.hs @@ -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 diff --git a/tasks.md b/tasks.md index f8090c13..ad4e814d 100644 --- a/tasks.md +++ b/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)