@@ -223,16 +223,7 @@ public void paintComponent(Graphics screen) {
223
223
Dimension size = getSize ();
224
224
if ((size .width != sizeW ) || (size .height != sizeH )) {
225
225
// component has been resized
226
-
227
- if ((size .width > imageW ) || (size .height > imageH )) {
228
- // nix the image and recreate, it's too small
229
- offscreen = null ;
230
-
231
- } else {
232
- // who cares, just resize
233
- sizeW = size .width ;
234
- sizeH = size .height ;
235
- }
226
+ offscreen = null ;
236
227
}
237
228
238
229
if (offscreen == null ) {
@@ -255,6 +246,8 @@ public void paintComponent(Graphics screen) {
255
246
g .setColor (backgroundColor );
256
247
g .fillRect (0 , 0 , imageW , imageH );
257
248
249
+ imageW = sizeW - 30 - menuButtons [0 ].getWidth (this );
250
+
258
251
List <EditorTab > tabs = editor .getTabs ();
259
252
260
253
int codeCount = tabs .size ();
@@ -265,7 +258,8 @@ public void paintComponent(Graphics screen) {
265
258
266
259
int x = scale (6 ); // offset from left edge of the component
267
260
int i = 0 ;
268
- int x_selected = 0 ;
261
+ int selected = 0 ;
262
+ int size_selected = 0 ;
269
263
270
264
// dry run, get the correct offset
271
265
for (EditorTab tab : tabs ) {
@@ -279,37 +273,33 @@ public void paintComponent(Graphics screen) {
279
273
font .getStringBounds (text , g .getFontRenderContext ()).getWidth ();
280
274
281
275
int pieceCount = 2 + (textWidth / PIECE_WIDTH );
282
- int pieceWidth = pieceCount * PIECE_WIDTH ;
283
276
284
277
int state = (i == editor .getCurrentTabIndex ()) ? SELECTED : UNSELECTED ;
278
+ int x_initial = x ;
285
279
x += PIECE_WIDTH ;
286
280
287
- int contentLeft = x ;
288
281
tabLeft [i ] = x ;
289
- for (int j = 0 ; j < pieceCount ; j ++) {
290
- x += PIECE_WIDTH ;
291
- }
282
+ x += PIECE_WIDTH * pieceCount ;
292
283
tabRight [i ] = x ;
293
- int textLeft = contentLeft + (pieceWidth - textWidth ) / 2 ;
294
-
295
- int baseline = (sizeH + fontAscent ) / 2 ;
296
- //g.drawString(sketch.code[i].name, textLeft, baseline);
297
284
298
285
x += PIECE_WIDTH - 1 ; // overlap by 1 pixel
299
286
300
287
if (state == SELECTED ) {
301
- x_selected = x ;
288
+ selected = i ;
289
+ size_selected = x - x_initial ;
302
290
}
303
291
304
292
i ++;
305
293
}
306
294
307
- if (x_selected > imageW ) {
308
- x = -(x_selected - imageW );
309
- } else {
310
- x = scale (6 ); // offset from left edge of the component
295
+ int non_selected_tab_size = 0 ;
296
+
297
+ if (x > imageW ) {
298
+ // find scaling factor
299
+ non_selected_tab_size = (imageW - size_selected )/(codeCount -1 );
311
300
}
312
301
i = 0 ;
302
+ x = scale (6 ); // offset from left edge of the component
313
303
314
304
for (EditorTab tab : tabs ) {
315
305
SketchFile file = tab .getSketchFile ();
@@ -319,7 +309,36 @@ public void paintComponent(Graphics screen) {
319
309
String text = " " + filename + (file .isModified () ? " \u00A7 " : " " );
320
310
321
311
int textWidth = (int )
322
- font .getStringBounds (text , g .getFontRenderContext ()).getWidth ();
312
+ font .getStringBounds (text , g .getFontRenderContext ()).getWidth ();
313
+
314
+ if (non_selected_tab_size > 0 ) {
315
+ if (i != selected ) {
316
+ // find a suitable title
317
+ while (textWidth + 3 * PIECE_WIDTH > non_selected_tab_size && filename .length () > 2 ) {
318
+ filename = filename .substring (0 , filename .length ()-1 );
319
+ text = " " + filename + ".." + (file .isModified () ? " \u00A7 " : " " );
320
+ textWidth = (int )font .getStringBounds (text , g .getFontRenderContext ()).getWidth ();
321
+ }
322
+ }
323
+ }
324
+
325
+ int current_tab_size = non_selected_tab_size ;
326
+ if (i == selected ) {
327
+ current_tab_size = size_selected ;
328
+ }
329
+
330
+ int padding = x + current_tab_size ;
331
+
332
+ if (padding > imageW ) {
333
+ if (i <= selected ) {
334
+ // create another surface to overlay g
335
+ g .setColor (backgroundColor );
336
+ g .fillRect (0 , 0 , sizeW , imageH );
337
+ x = scale (6 );
338
+ } else {
339
+ break ;
340
+ }
341
+ }
323
342
324
343
int pieceCount = 2 + (textWidth / PIECE_WIDTH );
325
344
int pieceWidth = pieceCount * PIECE_WIDTH ;
0 commit comments