66// License: MIT
77// -----------------------------------------------------------------------
88
9+ using SharpConsoleUI . Configuration ;
910using SharpConsoleUI . Drivers ;
1011using SharpConsoleUI . Helpers ;
1112using SharpConsoleUI . Layout ;
@@ -22,7 +23,7 @@ public override LayoutSize MeasureDOM(LayoutConstraints constraints)
2223 int dropdownWidth = calculateHeaderWidth ( constraints . MaxWidth - Margin . Left - Margin . Right ) ;
2324
2425 // Sane minimum: prompt + arrow + space for at least a few chars
25- string arrow = "▼" ;
26+ string arrow = ControlDefaults . DropdownClosedArrow ;
2627 int minWidth = Parsing . MarkupParser . StripLength ( $ "{ _prompt } { arrow } ") + 3 ;
2728 dropdownWidth = Math . Max ( dropdownWidth , minWidth ) ;
2829
@@ -80,7 +81,7 @@ public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutR
8081 int dropdownWidth = calculateHeaderWidth ( targetWidth ) ;
8182
8283 // Sane minimum: prompt + arrow + space for at least a few chars
83- string arrowMin = "▼" ;
84+ string arrowMin = ControlDefaults . DropdownClosedArrow ;
8485 int minWidth = Parsing . MarkupParser . StripLength ( $ "{ _prompt } { arrowMin } ") + 3 ;
8586 dropdownWidth = Math . Min ( Math . Max ( dropdownWidth , minWidth ) , targetWidth ) ;
8687
@@ -114,17 +115,16 @@ public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutR
114115
115116 // Render header: arrow flush-right, padding between text and arrow
116117 string selectedText = selectedIdx >= 0 && selectedIdx < paintSnapshot . Count ? paintSnapshot [ selectedIdx ] . Text : "(None)" ;
117- string arrow = _isDropdownOpen && _opensUpward ? "▲" : "▼" ;
118- string suffix = $ " { arrow } ";
119- int suffixLen = Parsing . MarkupParser . StripLength ( suffix ) ;
120- int maxSelectedTextLength = dropdownWidth - promptLength - 1 - suffixLen ; // 1 = space after prompt
118+ string arrow = _isDropdownOpen && _opensUpward ? ControlDefaults . DropdownOpenArrow : ControlDefaults . DropdownClosedArrow ;
119+ int arrowDisplayWidth = Parsing . MarkupParser . StripLength ( arrow ) ;
120+ // Reserve: space + arrow
121+ int suffixReserved = 1 + arrowDisplayWidth ;
122+ int maxSelectedTextLength = dropdownWidth - promptLength - 1 - suffixReserved ; // 1 = space after prompt
121123 if ( maxSelectedTextLength > 0 && Parsing . MarkupParser . StripLength ( selectedText ) > maxSelectedTextLength )
122124 selectedText = TextTruncationHelper . Truncate ( selectedText , maxSelectedTextLength ) ;
123125
124126 string prefix = $ "{ _prompt } { selectedText } ";
125127 int prefixLen = Parsing . MarkupParser . StripLength ( prefix ) ;
126- int paddingNeeded = Math . Max ( 0 , dropdownWidth - prefixLen - suffixLen ) ;
127- string headerContent = prefix + new string ( ' ' , paddingNeeded ) + suffix ;
128128
129129 int paintY = startY ;
130130
@@ -136,10 +136,28 @@ public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutR
136136 if ( alignOffset > 0 )
137137 ControlRenderingHelpers . FillRect ( buffer , new LayoutRect ( startX , paintY , alignOffset , 1 ) , foregroundColor , windowBackground , preserveBg ) ;
138138
139- var cells = Parsing . MarkupParser . Parse ( headerContent , foregroundColor , backgroundColor ) ;
140- buffer . WriteCellsClipped ( startX + alignOffset , paintY , cells , clipRect ) ;
139+ int writeX = startX + alignOffset ;
141140
142- int rightFillStart = startX + alignOffset + dropdownWidth ;
141+ // Paint prefix (prompt + selected text)
142+ var prefixCells = Parsing . MarkupParser . Parse ( prefix , foregroundColor , backgroundColor ) ;
143+ buffer . WriteCellsClipped ( writeX , paintY , prefixCells , clipRect ) ;
144+ writeX += prefixCells . Count ;
145+
146+ // Paint padding between text and arrow
147+ int paddingNeeded = Math . Max ( 0 , dropdownWidth - prefixLen - suffixReserved ) ;
148+ for ( int p = 0 ; p < paddingNeeded + 1 ; p ++ ) // +1 for space before arrow
149+ {
150+ if ( writeX >= clipRect . X && writeX < clipRect . Right )
151+ buffer . SetNarrowCell ( writeX , paintY , ' ' , foregroundColor , backgroundColor ) ;
152+ writeX ++ ;
153+ }
154+
155+ // Paint arrow via Parse (handles wide chars with continuation cells)
156+ var arrowCells = Parsing . MarkupParser . Parse ( arrow , foregroundColor , backgroundColor ) ;
157+ buffer . WriteCellsClipped ( writeX , paintY , arrowCells , clipRect ) ;
158+ writeX += arrowCells . Count ;
159+
160+ int rightFillStart = writeX ;
143161 int rightFillWidth = bounds . Right - rightFillStart - Margin . Right ;
144162 if ( rightFillWidth > 0 )
145163 ControlRenderingHelpers . FillRect ( buffer , new LayoutRect ( rightFillStart , paintY , rightFillWidth , 1 ) , foregroundColor , windowBackground , preserveBg ) ;
0 commit comments