Skip to content

Allow tabs to adjust their size when there are too many tabs #8011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions app/src/processing/app/EditorHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;

Expand Down Expand Up @@ -241,19 +242,45 @@ public void paintComponent(Graphics screen) {
tabRight = new int[codeCount];
}

int x = scale(6); // offset from left edge of the component
int i = 0;
List<String> texts = new ArrayList<String>();
int totalWidth = 0;
for (EditorTab tab : tabs) {
SketchFile file = tab.getSketchFile();
String filename = file.getPrettyName();

// if modified, add the li'l glyph next to the name
String text = " " + filename + (file.isModified() ? " \u00A7" : " ");
String text = filename;
if (file.isModified())
text += " \u00A7";
texts.add(text);

int textWidth = (int)
font.getStringBounds(text, g.getFontRenderContext()).getWidth();

int pieceCount = textWidth / PIECE_WIDTH;
int pieceWidth = pieceCount * PIECE_WIDTH;
totalWidth += PIECE_WIDTH * (pieceCount + 2) - 1; // left + middle + right - overlap(=1)
}

int marginPieceCount = 0;
int marginForEveryPiece = PIECE_WIDTH * tabs.size();
for (int i = 1; i <= 6; ++i) {
if (sizeW - totalWidth > marginForEveryPiece * i) {
marginPieceCount = i;
continue;
}
break;
}

int x = scale(6); // offset from left edge of the component
int i = 0;
for (EditorTab tab : tabs) {
String text = texts.get(i);

int textWidth = (int)
font.getStringBounds(text, g.getFontRenderContext()).getWidth();

int pieceCount = 2 + (textWidth / PIECE_WIDTH);
int pieceCount = marginPieceCount + (textWidth / PIECE_WIDTH);
int pieceWidth = pieceCount * PIECE_WIDTH;

int state = (i == editor.getCurrentTabIndex()) ? SELECTED : UNSELECTED;
Expand All @@ -276,7 +303,7 @@ public void paintComponent(Graphics screen) {

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

menuLeft = sizeW - (16 + menuButtons[0].getWidth(this));
Expand Down