@@ -243,6 +243,52 @@ public void paintComponent(Graphics screen) {
243
243
244
244
int x = scale (6 ); // offset from left edge of the component
245
245
int i = 0 ;
246
+ int x_selected = 0 ;
247
+
248
+ // dry run, get the correct offset
249
+ for (EditorTab tab : tabs ) {
250
+ SketchFile file = tab .getSketchFile ();
251
+ String filename = file .getPrettyName ();
252
+
253
+ // if modified, add the li'l glyph next to the name
254
+ String text = " " + filename + (file .isModified () ? " \u00A7 " : " " );
255
+
256
+ int textWidth = (int )
257
+ font .getStringBounds (text , g .getFontRenderContext ()).getWidth ();
258
+
259
+ int pieceCount = 2 + (textWidth / PIECE_WIDTH );
260
+ int pieceWidth = pieceCount * PIECE_WIDTH ;
261
+
262
+ int state = (i == editor .getCurrentTabIndex ()) ? SELECTED : UNSELECTED ;
263
+ x += PIECE_WIDTH ;
264
+
265
+ int contentLeft = x ;
266
+ tabLeft [i ] = x ;
267
+ for (int j = 0 ; j < pieceCount ; j ++) {
268
+ x += PIECE_WIDTH ;
269
+ }
270
+ tabRight [i ] = x ;
271
+ int textLeft = contentLeft + (pieceWidth - textWidth ) / 2 ;
272
+
273
+ int baseline = (sizeH + fontAscent ) / 2 ;
274
+ //g.drawString(sketch.code[i].name, textLeft, baseline);
275
+
276
+ x += PIECE_WIDTH - 1 ; // overlap by 1 pixel
277
+
278
+ if (state == SELECTED ) {
279
+ x_selected = x ;
280
+ }
281
+
282
+ i ++;
283
+ }
284
+
285
+ if (x_selected > imageW ) {
286
+ x = -(x_selected - imageW );
287
+ } else {
288
+ x = scale (6 ); // offset from left edge of the component
289
+ }
290
+ i = 0 ;
291
+
246
292
for (EditorTab tab : tabs ) {
247
293
SketchFile file = tab .getSketchFile ();
248
294
String filename = file .getPrettyName ();
@@ -276,6 +322,7 @@ public void paintComponent(Graphics screen) {
276
322
277
323
g .drawImage (pieces [state ][RIGHT ], x , 0 , null );
278
324
x += PIECE_WIDTH - 1 ; // overlap by 1 pixel
325
+
279
326
i ++;
280
327
}
281
328
0 commit comments