!10 feat: #I7UFOF 隐藏滚动条
Merge pull request !10 from songdragon/feat-I7UFOF
This commit is contained in:
commit
cbcdc120b7
@ -42,6 +42,7 @@ public class LunchApp extends Application {
|
||||
|
||||
scene = new Scene(root, width, length);
|
||||
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
|
||||
scene.getStylesheets().add(Objects.requireNonNull(getClass().getResource("/styles.css")).toExternalForm());
|
||||
|
||||
primaryStage.setTitle(name);
|
||||
primaryStage.setWidth(width);
|
||||
|
||||
@ -94,7 +94,7 @@ public class Controller implements ControllerInterface {
|
||||
*/
|
||||
@Override
|
||||
public void autoSave(LineNumberTextArea textArea) {
|
||||
textArea.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
textArea.getMainTextArea().textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
Tab tab = ViewManager.tabPane.getSelectionModel().getSelectedItem();
|
||||
if (tab != null) {
|
||||
File file = (File) tab.getUserData();
|
||||
|
||||
@ -13,16 +13,18 @@ public class LineNumberTextArea extends BorderPane {
|
||||
private final TextArea mainTextArea;
|
||||
private final TextArea lineNumberArea;
|
||||
|
||||
static final int[] sizeTable = {9, 99, 999, 9999, 99999, 999999, 9999999,
|
||||
99999999, 999999999, Integer.MAX_VALUE};
|
||||
|
||||
public LineNumberTextArea() {
|
||||
mainTextArea = new TextArea();
|
||||
lineNumberArea = new TextArea();
|
||||
lineNumberArea.setEditable(false);
|
||||
lineNumberArea.setMinWidth(55);
|
||||
lineNumberArea.setMaxWidth(55);
|
||||
lineNumberArea.setPrefWidth(30);
|
||||
// 设置显示滚动条样式类
|
||||
/* lineNumberArea.getStyleClass().add("hide-scrollbars");
|
||||
mainTextArea.getStyleClass().add("show-scrollbars"); */
|
||||
|
||||
lineNumberArea.getStyleClass().add("text-line-number");
|
||||
/*mainTextArea.getStyleClass().add("show-scrollbars"); */
|
||||
lineNumberArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberWidth());
|
||||
mainTextArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberArea());
|
||||
|
||||
// 当主要文本区域的垂直滚动位置发生变化时,使行号文本区域的滚动位置保持一致
|
||||
@ -39,6 +41,22 @@ public class LineNumberTextArea extends BorderPane {
|
||||
setLeft(lineNumberArea);
|
||||
}
|
||||
|
||||
private void updateLineNumberWidth() {
|
||||
int numOfLines = mainTextArea.getParagraphs().size();
|
||||
int count = 1;
|
||||
for (int i = 0; i < sizeTable.length; i++) {
|
||||
if (numOfLines <= sizeTable[i]) {
|
||||
count = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//单数字宽度10像素,4为padding=左3+右1
|
||||
int actualWidth = count * 10 + 4;
|
||||
if (actualWidth > lineNumberArea.getWidth()) {
|
||||
lineNumberArea.setPrefWidth(actualWidth);
|
||||
}
|
||||
}
|
||||
|
||||
public StringProperty textProperty() {
|
||||
return mainTextArea.textProperty();
|
||||
}
|
||||
|
||||
@ -5,7 +5,15 @@
|
||||
}
|
||||
|
||||
/* 不显示滚动条 */
|
||||
.hide-scrollbars .scroll-pane {
|
||||
-fx-hbar-policy: never;
|
||||
-fx-vbar-policy: never;
|
||||
.text-line-number .content{
|
||||
-fx-cursor: text;
|
||||
-fx-padding: 8px 1px 8px 5px;
|
||||
}
|
||||
.text-line-number .scroll-bar:vertical {
|
||||
-fx-pref-width: 1;
|
||||
-fx-opacity: 0;
|
||||
}
|
||||
.text-line-number .scroll-bar:horizontal {
|
||||
-fx-pref-height: 1;
|
||||
-fx-opacity: 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user