@@ -407,10 +407,8 @@ class DraggableNumber : public Component, public TextEditor::Listener
407407 dragMode = newDragMode;
408408 }
409409
410- void getDraggedNumberBounds ( Rectangle<float >& position, int dragPosition)
410+ Rectangle<float > getDraggedNumberBounds ( int dragPosition)
411411 {
412- position = Rectangle<float >();
413-
414412 auto const textArea = border.subtractedFrom (getLocalBounds ());
415413 auto const text = dragMode == Integer ? currentValue.upToFirstOccurrenceOf (" ." , false , false ) : String (currentValue.getDoubleValue ());
416414
@@ -422,13 +420,10 @@ class DraggableNumber : public Component, public TextEditor::Listener
422420
423421 if (dragPosition == 0 )
424422 {
425- for (int i = 0 ; i < fullNumber.indexOf (" ." ); i++)
426- {
427- position = position.getUnion (glyphs.getGlyph (i).getBounds ());
428- }
423+ return glyphs.getBoundingBox (0 , fullNumber.indexOf (" ." ), true );
429424 }
430425 else {
431- position = position. getUnion ( glyphs.getGlyph (fullNumber.indexOf (" ." ) + dragPosition).getBounds () );
426+ return glyphs.getGlyph (fullNumber.indexOf (" ." ) + dragPosition).getBounds ();
432427 }
433428 }
434429
@@ -479,10 +474,7 @@ class DraggableNumber : public Component, public TextEditor::Listener
479474 continue ;
480475 }
481476 if (isDecimalPoint) {
482- glyphBounds = Rectangle<float >();
483- for (int j = 0 ; j < i; j++) {
484- glyphBounds = glyphBounds.getUnion (glyphs.getGlyph (j).getBounds ());
485- }
477+ glyphBounds = glyphs.getBoundingBox (0 , i, false );
486478 }
487479 if (position)
488480 *position = glyphBounds;
@@ -674,7 +666,7 @@ class DraggableNumber : public Component, public TextEditor::Listener
674666 }
675667
676668
677- getDraggedNumberBounds ( hoveredDecimalPosition, decimalDrag);
669+ hoveredDecimalPosition = getDraggedNumberBounds ( decimalDrag);
678670 repaint ();
679671 }
680672
@@ -813,7 +805,14 @@ struct DraggableListNumber final : public DraggableNumber {
813805
814806 void mouseMove (MouseEvent const & e) override
815807 {
816- updateListHoverPosition (e.x );
808+ int const oldHoverPosition = hoveredDecimal;
809+ auto [numberStart, numberEnd, numberValue] = getListItemAtPosition (e.x , &hoveredDecimalPosition);
810+
811+ hoveredDecimal = numberStart;
812+
813+ if (oldHoverPosition != hoveredDecimal) {
814+ repaint ();
815+ }
817816 }
818817
819818 void mouseDrag (MouseEvent const & e) override
@@ -850,7 +849,11 @@ struct DraggableListNumber final : public DraggableNumber {
850849 setText (newText, dontSendNotification);
851850 onValueChange (0 );
852851
853- updateListHoverPosition (e.getMouseDownX ());
852+ // Update hover area
853+ auto const textArea = border.subtractedFrom (getLocalBounds ());
854+ GlyphArrangement glyphs;
855+ glyphs.addFittedText (font, newText, textArea.getX (), 2 ., 99999 , textArea.getHeight (), Justification::centredLeft, 1 , minimumHorizontalScale);
856+ hoveredDecimalPosition = glyphs.getBoundingBox (numberStartIdx, numberEndIdx - numberStartIdx, false );
854857 }
855858
856859 void mouseUp (MouseEvent const & e) override
@@ -918,24 +921,12 @@ struct DraggableListNumber final : public DraggableNumber {
918921 nvgText (nvg, textArea.getX (), textArea.getCentreY () + 1 .5f , listText.toRawUTF8 (), nullptr );
919922 }
920923
921-
922- void updateListHoverPosition (int const x)
923- {
924- int const oldHoverPosition = hoveredDecimal;
925- auto [numberStart, numberEnd, numberValue] = getListItemAtPosition (x, &hoveredDecimalPosition);
926-
927- hoveredDecimal = numberStart;
928-
929- if (oldHoverPosition != hoveredDecimal) {
930- repaint ();
931- }
932- }
933924 void textEditorReturnKeyPressed (TextEditor& editor) override
934925 {
935926 onReturnKey (0 );
936927 hideEditor (false );
937928 }
938-
929+
939930 std::tuple<int , int , double > getListItemAtPosition (int const x, Rectangle<float >* position = nullptr ) const
940931 {
941932 auto const textArea = border.subtractedFrom (getBounds ());
0 commit comments