@@ -4,18 +4,28 @@ namespace iplug {
44namespace igraphics {
55ReacomaSegmented::ReacomaSegmented (
66 const IRECT &bounds, int paramIdx,
7- const std::vector<std::string> &segmentLabels, const ReacomaTheme &theme)
8- : IControl(bounds, paramIdx), mSegmentLabels (segmentLabels), mTheme (theme) {
7+ const std::vector<std::string> &segmentLabels, const ReacomaTheme &theme,
8+ int itemsPerRow)
9+ : IControl(bounds, paramIdx), mSegmentLabels (segmentLabels), mTheme (theme),
10+ mItemsPerRow (itemsPerRow) {
911 CalculateSegmentRects ();
1012}
1113
1214void ReacomaSegmented::CalculateSegmentRects () {
1315 mSegmentRects .clear ();
1416 if (mSegmentLabels .empty ())
1517 return ;
16- for (size_t i = 0 ; i < mSegmentLabels .size (); ++i) {
17- mSegmentRects .push_back (
18- mRECT .SubRectHorizontal (mSegmentLabels .size (), i));
18+
19+ int numItems = static_cast <int >(mSegmentLabels .size ());
20+ int nCols = mItemsPerRow > 0 ? mItemsPerRow : numItems;
21+ int nRows = (numItems + nCols - 1 ) / nCols;
22+
23+ for (int i = 0 ; i < numItems; ++i) {
24+ int row = i / nCols;
25+ int col = i % nCols;
26+
27+ IRECT rowRect = mRECT .SubRectVertical (nRows, row);
28+ mSegmentRects .push_back (rowRect.SubRectHorizontal (nCols, col));
1929 }
2030}
2131
@@ -52,10 +62,20 @@ void ReacomaSegmented::Draw(IGraphics &g) {
5262
5363 // 2. Draw the main border and dividers over everything for a clean look
5464 g.DrawRoundRect (mTheme .border , mRECT , mTheme .cornerRadius );
55- for (size_t i = 0 ; i < mSegmentLabels .size () - 1 ; ++i) {
56- const IRECT &segmentRect = mSegmentRects [i];
57- g.DrawLine (mTheme .border , segmentRect.R , segmentRect.T , segmentRect.R ,
58- segmentRect.B );
65+
66+ if (mItemsPerRow <= 0 ||
67+ mSegmentLabels .size () <= static_cast <size_t >(mItemsPerRow )) {
68+ // Single row - use vertical dividers
69+ for (size_t i = 0 ; i < mSegmentLabels .size () - 1 ; ++i) {
70+ const IRECT &segmentRect = mSegmentRects [i];
71+ g.DrawLine (mTheme .border , segmentRect.R , segmentRect.T ,
72+ segmentRect.R , segmentRect.B );
73+ }
74+ } else {
75+ // Multi-row - draw borders for each segment to form a grid
76+ for (size_t i = 0 ; i < mSegmentLabels .size (); ++i) {
77+ g.DrawRect (mTheme .border , mSegmentRects [i]);
78+ }
5979 }
6080
6181 // 3. Draw the text labels on top
@@ -103,9 +123,11 @@ int ReacomaSegmented::GetSegmentForPos(float x, float y) {
103123 if (mSegmentLabels .empty () || !mRECT .Contains (x, y))
104124 return -1 ;
105125
106- float segmentWidth = mRECT .W () / mSegmentLabels .size ();
107- int segmentIdx = static_cast <int >((x - mRECT .L ) / segmentWidth);
108- return std::clamp (segmentIdx, 0 , (int )mSegmentLabels .size () - 1 );
126+ for (int i = 0 ; i < static_cast <int >(mSegmentRects .size ()); ++i) {
127+ if (mSegmentRects [i].Contains (x, y))
128+ return i;
129+ }
130+ return -1 ;
109131}
110132} // namespace igraphics
111133} // namespace iplug
0 commit comments