@@ -73,6 +73,15 @@ public IBrush TagBackground
73
73
set => SetValue ( TagBackgroundProperty , value ) ;
74
74
}
75
75
76
+ public static readonly StyledProperty < bool > AllowWrapProperty =
77
+ AvaloniaProperty . Register < CommitRefsPresenter , bool > ( nameof ( AllowWrap ) ) ;
78
+
79
+ public bool AllowWrap
80
+ {
81
+ get => GetValue ( AllowWrapProperty ) ;
82
+ set => SetValue ( AllowWrapProperty , value ) ;
83
+ }
84
+
76
85
static CommitRefsPresenter ( )
77
86
{
78
87
AffectsMeasure < CommitRefsPresenter > (
@@ -93,10 +102,19 @@ public override void Render(DrawingContext context)
93
102
var useGraphColor = UseGraphColor ;
94
103
var fg = Foreground ;
95
104
var bg = Background ;
105
+ var allowWrap = AllowWrap ;
96
106
var x = 1.0 ;
107
+ var y = 0.0 ;
108
+
97
109
foreach ( var item in _items )
98
110
{
99
- var entireRect = new RoundedRect ( new Rect ( x , 0 , item . Width , 16 ) , new CornerRadius ( 2 ) ) ;
111
+ if ( allowWrap && x > 1.0 && x + item . Width > Bounds . Width )
112
+ {
113
+ x = 1.0 ;
114
+ y += 20.0 ;
115
+ }
116
+
117
+ var entireRect = new RoundedRect ( new Rect ( x , y , item . Width , 16 ) , new CornerRadius ( 2 ) ) ;
100
118
101
119
if ( item . IsHead )
102
120
{
@@ -109,24 +127,24 @@ public override void Render(DrawingContext context)
109
127
context . DrawRectangle ( item . Brush , null , entireRect ) ;
110
128
}
111
129
112
- context . DrawText ( item . Label , new Point ( x + 16 , 8.0 - item . Label . Height * 0.5 ) ) ;
130
+ context . DrawText ( item . Label , new Point ( x + 16 , y + 8.0 - item . Label . Height * 0.5 ) ) ;
113
131
}
114
132
else
115
133
{
116
134
if ( bg != null )
117
135
context . DrawRectangle ( bg , null , entireRect ) ;
118
136
119
- var labelRect = new RoundedRect ( new Rect ( x + 16 , 0 , item . Label . Width + 8 , 16 ) , new CornerRadius ( 0 , 2 , 2 , 0 ) ) ;
137
+ var labelRect = new RoundedRect ( new Rect ( x + 16 , y , item . Label . Width + 8 , 16 ) , new CornerRadius ( 0 , 2 , 2 , 0 ) ) ;
120
138
using ( context . PushOpacity ( .2 ) )
121
139
context . DrawRectangle ( item . Brush , null , labelRect ) ;
122
140
123
- context . DrawLine ( new Pen ( item . Brush ) , new Point ( x + 16 , 0 ) , new Point ( x + 16 , 16 ) ) ;
124
- context . DrawText ( item . Label , new Point ( x + 20 , 8.0 - item . Label . Height * 0.5 ) ) ;
141
+ context . DrawLine ( new Pen ( item . Brush ) , new Point ( x + 16 , y ) , new Point ( x + 16 , y + 16 ) ) ;
142
+ context . DrawText ( item . Label , new Point ( x + 20 , y + 8.0 - item . Label . Height * 0.5 ) ) ;
125
143
}
126
144
127
145
context . DrawRectangle ( null , new Pen ( item . Brush ) , entireRect ) ;
128
146
129
- using ( context . PushTransform ( Matrix . CreateTranslation ( x + 3 , 3 ) ) )
147
+ using ( context . PushTransform ( Matrix . CreateTranslation ( x + 3 , y + 3 ) ) )
130
148
context . DrawGeometry ( fg , null , item . Icon ) ;
131
149
132
150
x += item . Width + 4 ;
@@ -157,6 +175,9 @@ protected override Size MeasureOverride(Size availableSize)
157
175
var tagBG = TagBackground ;
158
176
var labelSize = FontSize ;
159
177
var requiredWidth = 0.0 ;
178
+ var requiredHeight = 16.0 ;
179
+ var x = 0.0 ;
180
+ var allowWrap = AllowWrap ;
160
181
161
182
foreach ( var decorator in refs )
162
183
{
@@ -211,11 +232,24 @@ protected override Size MeasureOverride(Size availableSize)
211
232
item . Width = 16 + ( isHead ? 0 : 4 ) + label . Width + 4 ;
212
233
_items . Add ( item ) ;
213
234
214
- requiredWidth += item . Width + 4 ;
235
+ x += item . Width + 4 ;
236
+ if ( allowWrap )
237
+ {
238
+ if ( x > availableSize . Width )
239
+ {
240
+ requiredHeight += 20.0 ;
241
+ x = item . Width ;
242
+ }
243
+ }
215
244
}
216
245
246
+ if ( allowWrap && requiredHeight > 16.0 )
247
+ requiredWidth = availableSize . Width ;
248
+ else
249
+ requiredWidth = x + 2 ;
250
+
217
251
InvalidateVisual ( ) ;
218
- return new Size ( requiredWidth + 2 , 16 ) ;
252
+ return new Size ( requiredWidth , requiredHeight ) ;
219
253
}
220
254
221
255
InvalidateVisual ( ) ;
0 commit comments