!15 fix: #I7UHOH 修复行号宽度不能自动减小的问题;增加默认最小宽度计算

Merge pull request !15 from songdragon/fix-I7UHOH
This commit is contained in:
Luke 2023-08-20 15:21:04 +00:00 committed by Gitee
commit 6391df41a2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 16 additions and 7 deletions

View File

@ -12,16 +12,17 @@ public class LineNumberTextArea extends BorderPane {
static final int[] sizeTable = {9, 99, 999, 9999, 99999, 999999, 9999999,
99999999, 999999999, Integer.MAX_VALUE};
private static final int MIN_LINE_NUMBER_WIDTH = 30;
public LineNumberTextArea() {
mainTextArea = new TextArea();
lineNumberArea = new TextArea();
lineNumberArea.setEditable(false);
lineNumberArea.setPrefWidth(30);
mainTextArea.setStyle("-fx-border-color:white;-fx-background-color:white;");
// lineNumberArea.setStyle("-fx-border-color:white;-fx-background-color:white;");
// 设置显示滚动条样式类
lineNumberArea.setPrefWidth(MIN_LINE_NUMBER_WIDTH);
lineNumberArea.setMinWidth(MIN_LINE_NUMBER_WIDTH);
// 设定自定义样式
lineNumberArea.getStyleClass().add("text-line-number");
mainTextArea.getStyleClass().add("main-text-area");
lineNumberArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberWidth());
mainTextArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberArea());
@ -49,8 +50,8 @@ public class LineNumberTextArea extends BorderPane {
}
}
//单数字宽度10像素4为padding=左3+右1
int actualWidth = count * 10 + 4;
if (actualWidth > lineNumberArea.getWidth()) {
int actualWidth = Math.max(count * 10 + 4, MIN_LINE_NUMBER_WIDTH);
if (actualWidth != lineNumberArea.getWidth()) {
lineNumberArea.setPrefWidth(actualWidth);
}
}

View File

@ -5,15 +5,23 @@
}
/* 不显示滚动条 */
.text-line-number .content{
.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;
}
/* 主文本框区域样式 */
.main-text-area {
-fx-border-color: white;
-fx-background-color: white;
}