Skip to content

Commit 591fd51

Browse files
authored
实现游戏日志窗口开关自动换行 (HMCL-dev#6424)
1 parent c1407a9 commit 591fd51

4 files changed

Lines changed: 27 additions & 5 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ private final class LogWindowImpl extends Control {
164164

165165
private final ListView<Log> listView = new JFXListView<>();
166166
private final BooleanProperty autoScroll = new SimpleBooleanProperty();
167+
private final BooleanProperty wrapText = new SimpleBooleanProperty(true);
167168
private final StringProperty[] buttonText = new StringProperty[LEVELS.length];
168169
private final BooleanProperty[] showLevel = new BooleanProperty[LEVELS.length];
169170
private final JFXButton btnAlwaysOnTop = FXUtils.newToggleButton4(SVG.KEEP, 20);
@@ -174,7 +175,6 @@ private final class LogWindowImpl extends Control {
174175
LogWindowImpl() {
175176
getStyleClass().add("log-window");
176177

177-
listView.getStyleClass().add("no-horizontal-scrollbar");
178178
listView.getProperties().put("no-smooth-scrolling", true);
179179
listView.setItems(FXCollections.observableList(new CircularArrayList<>(logs.size())));
180180

@@ -331,11 +331,26 @@ private static final class LogWindowSkin extends SkinBase<LogWindowImpl> {
331331
getStyleClass().add("log-window-list-cell");
332332
Region clippedContainer = (Region) listView.lookup(".clipped-container");
333333
if (clippedContainer != null) {
334-
maxWidthProperty().bind(clippedContainer.widthProperty());
335-
prefWidthProperty().bind(clippedContainer.widthProperty());
334+
wrapTextProperty().addListener((obs, oldWrap, nowWrap) -> {
335+
if (nowWrap) {
336+
maxWidthProperty().bind(clippedContainer.widthProperty());
337+
prefWidthProperty().bind(clippedContainer.widthProperty());
338+
listView.getStyleClass().add("no-horizontal-scrollbar");
339+
} else {
340+
maxWidthProperty().unbind();
341+
prefWidthProperty().unbind();
342+
343+
setMaxWidth(Region.USE_PREF_SIZE);
344+
setPrefWidth(Region.USE_COMPUTED_SIZE);
345+
listView.getStyleClass().remove("no-horizontal-scrollbar");
346+
}
347+
348+
// only for horizontal scrollbar
349+
listView.requestLayout();
350+
});
336351
}
337352
setPadding(new Insets(2));
338-
setWrapText(true);
353+
wrapTextProperty().bind(control.wrapText);
339354
setGraphic(null);
340355
}
341356

@@ -395,6 +410,10 @@ protected void updateItem(Log item, boolean empty) {
395410
autoScrollCheckBox.setSelected(true);
396411
control.autoScroll.bind(autoScrollCheckBox.selectedProperty());
397412

413+
JFXCheckBox wrapTextCheckBox = new JFXCheckBox(i18n("logwindow.wrap_text"));
414+
wrapTextCheckBox.setSelected(true);
415+
control.wrapText.bind(wrapTextCheckBox.selectedProperty());
416+
398417
JFXButton exportLogsButton = new JFXButton(i18n("button.export"));
399418
exportLogsButton.setOnAction(e -> getSkinnable().onExportLogs());
400419

@@ -414,7 +433,7 @@ protected void updateItem(Log item, boolean empty) {
414433

415434
JFXButton clearButton = new JFXButton(i18n("button.clear"));
416435
clearButton.setOnAction(e -> getSkinnable().onClear());
417-
hBox.getChildren().setAll(autoScrollCheckBox, exportLogsButton, terminateButton, exportDumpPane, clearButton);
436+
hBox.getChildren().setAll(autoScrollCheckBox, wrapTextCheckBox, exportLogsButton, terminateButton, exportDumpPane, clearButton);
418437

419438
control.getGameProcess().getProcess()
420439
.onExit()

HMCL/src/main/resources/assets/lang/I18N.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@ logwindow.terminate_game=Kill Game Process
948948
logwindow.title=Log
949949
logwindow.help=You can navigate to the HMCL community and find others for help.
950950
logwindow.autoscroll=Auto-scroll
951+
logwindow.wrap_text=Wrap Text
951952
logwindow.export_game_crash_logs=Export Crash Logs
952953
logwindow.export_dump=Export Game Stack Dump
953954
logwindow.export_dump.no_dependency=Your Java does not contain the dependencies to create the stack dump. Please join our Discord or QQ group for help.

HMCL/src/main/resources/assets/lang/I18N_zh.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ logwindow.terminate_game=結束遊戲處理程式
755755
logwindow.title=日誌
756756
logwindow.help=你可以前往 HMCL 社群,向他人尋求幫助
757757
logwindow.autoscroll=自動滾動
758+
logwindow.wrap_text=自動換行
758759
logwindow.export_game_crash_logs=匯出遊戲崩潰資訊
759760
logwindow.export_dump=匯出遊戲執行堆疊
760761
logwindow.export_dump.no_dependency=你的 Java 不包含用於建立遊戲執行堆疊的相依元件。請前往 Discord 或 HMCL QQ 群尋求幫助。

HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ logwindow.terminate_game=结束游戏进程
760760
logwindow.title=日志
761761
logwindow.help=你可以前往 HMCL 社区,寻找他人帮助
762762
logwindow.autoscroll=自动滚动
763+
logwindow.wrap_text=自动换行
763764
logwindow.export_game_crash_logs=导出游戏崩溃信息
764765
logwindow.export_dump=导出游戏运行栈
765766
logwindow.export_dump.no_dependency=你的 Java 不包含用于创建游戏运行栈的依赖。请前往 HMCL QQ 群或 Discord 寻求帮助。

0 commit comments

Comments
 (0)