Skip to content

Commit 0f833ca

Browse files
committed
Shift tabs if selected one if being painted offscreen
Implemented using a dry run to get the metrics and the needed shift Fixes #1193 and #6109
1 parent 94e5e1a commit 0f833ca

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

app/src/processing/app/EditorHeader.java

+47
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,52 @@ public void paintComponent(Graphics screen) {
243243

244244
int x = scale(6); // offset from left edge of the component
245245
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+
246292
for (EditorTab tab : tabs) {
247293
SketchFile file = tab.getSketchFile();
248294
String filename = file.getPrettyName();
@@ -276,6 +322,7 @@ public void paintComponent(Graphics screen) {
276322

277323
g.drawImage(pieces[state][RIGHT], x, 0, null);
278324
x += PIECE_WIDTH - 1; // overlap by 1 pixel
325+
279326
i++;
280327
}
281328

0 commit comments

Comments
 (0)