From 500efd6dcc532fff8186bbb8cf34081cd7edceb4 Mon Sep 17 00:00:00 2001 From: RibosomeK <122797zhyktb@gmail.com> Date: Thu, 24 Oct 2024 21:16:16 +0800 Subject: [PATCH] add border highlight with customization in multiple entry edit mode along with chinese translations --- .../com/sdercolin/vlabeler/model/AppConf.kt | 12 ++++ .../ui/dialog/preferences/PreferencesPages.kt | 60 +++++++++++++++++++ .../ui/editor/labeler/marker/Marker.kt | 32 +++++++++- .../sdercolin/vlabeler/ui/string/Strings.kt | 10 ++++ .../ui/string/StringsChineseSimplified.kt | 10 ++++ .../vlabeler/ui/string/StringsEnglish.kt | 12 ++++ 6 files changed, 134 insertions(+), 2 deletions(-) diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/model/AppConf.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/model/AppConf.kt index 2161f939..223323a5 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/model/AppConf.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/model/AppConf.kt @@ -368,6 +368,12 @@ data class AppConf( val continuousLabelNames: ContinuousLabelNames = ContinuousLabelNames(), val postEditNext: PostEditAction = PostEditAction.DEFAULT_NEXT, val postEditDone: PostEditAction = PostEditAction.DEFAULT_DONE, + val highlightCurrentEntryBorder: Boolean = DEFAULT_HIGHLIGHT_CURRENT_ENTRY_BORDER, + val currentEntryBorderHighlightColor: String = DEFAULT_CURRENT_ENTRY_BORDER_HIGHLIGHT_COLOR, + val currentEntryBorderHighlightWidth: Float = DEFAULT_CURRENT_ENTRY_BORDER_HIGHLIGHT_WIDTH, + val highlightCursorPositionEntryBorder: Boolean = DEFAULT_HIGHLIGHT_CURSOR_POSITION_ENTRY_BORDER, + val cursorPositionEntryBorderHighlightColor: String = DEFAULT_CURSOR_POSITION_ENTRY_BORDER_HIGHLIGHT_COLOR, + val cursorPositionEntryBorderHighlightWidth: Float = DEFAULT_CURSOR_POSITION_ENTRY_BORDER_HIGHLIGHT_WIDTH, ) { /** @@ -399,6 +405,12 @@ data class AppConf( const val DEFAULT_SHOW_STAR = true const val DEFAULT_SHOW_TAG = true const val DEFAULT_SHOW_EXTRA = true + const val DEFAULT_HIGHLIGHT_CURRENT_ENTRY_BORDER = false + const val DEFAULT_CURRENT_ENTRY_BORDER_HIGHLIGHT_COLOR = "#F48FB1" + const val DEFAULT_CURRENT_ENTRY_BORDER_HIGHLIGHT_WIDTH = 6f + const val DEFAULT_HIGHLIGHT_CURSOR_POSITION_ENTRY_BORDER = false + const val DEFAULT_CURSOR_POSITION_ENTRY_BORDER_HIGHLIGHT_COLOR = "#AD375F" + const val DEFAULT_CURSOR_POSITION_ENTRY_BORDER_HIGHLIGHT_WIDTH = 4f } } diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/dialog/preferences/PreferencesPages.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/dialog/preferences/PreferencesPages.kt index c3b11325..48161f2e 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/dialog/preferences/PreferencesPages.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/dialog/preferences/PreferencesPages.kt @@ -699,6 +699,7 @@ object PreferencesPages { EditorNotes, EditorContinuousLabelNames, EditorPostEditAction, + EditorBorderHighlight, ) override val content: List @@ -1010,6 +1011,65 @@ object PreferencesPages { } } + object EditorBorderHighlight : PreferencesPage( + Strings.PreferencesEditorBorderHighlight, + Strings.PreferencesEditorBorderHighlightDescription, + ) { + override val content: List + get() = buildPageContent { + withContext( + selector = { it.editor }, + updater = { copy(editor = it) }, + ) { + + switch( + title = Strings.PreferencesEditorHighlightCurrentEntryBorder, + description = Strings.PreferencesEditorHighlightCursorPositionEntryBorderDescription, + defaultValue = AppConf.Editor.DEFAULT_HIGHLIGHT_CURRENT_ENTRY_BORDER, + select = { it.highlightCurrentEntryBorder }, + update = { copy(highlightCurrentEntryBorder = it) }, + ) + color( + title = Strings.PreferencesEditorCurrentEntryBorderHighlightColor, + defaultValue = AppConf.Editor.DEFAULT_CURRENT_ENTRY_BORDER_HIGHLIGHT_COLOR, + useAlpha = false, + select = { it.currentEntryBorderHighlightColor }, + update = { copy(currentEntryBorderHighlightColor = it) }, + ) + float( + title = Strings.PreferencesEditorCurrentEntryBorderHighlightWidth, + defaultValue = AppConf.Editor.DEFAULT_CURRENT_ENTRY_BORDER_HIGHLIGHT_WIDTH, + min = 2f, + max = 10f, + select = { it.currentEntryBorderHighlightWidth }, + update = { copy(currentEntryBorderHighlightWidth = it) }, + ) + switch( + title = Strings.PreferencesEditorHighlightCursorPositionEntryBorder, + description = Strings.PreferencesEditorHighlightCursorPositionEntryBorderDescription, + defaultValue = AppConf.Editor.DEFAULT_HIGHLIGHT_CURSOR_POSITION_ENTRY_BORDER, + select = { it.highlightCursorPositionEntryBorder }, + update = { copy(highlightCursorPositionEntryBorder = it) }, + ) + color( + title = Strings.PreferencesEditorCursorPositionEntryBorderHighlightColor, + defaultValue = AppConf.Editor.DEFAULT_CURSOR_POSITION_ENTRY_BORDER_HIGHLIGHT_COLOR, + useAlpha = false, + select = { it.cursorPositionEntryBorderHighlightColor }, + update = { copy(cursorPositionEntryBorderHighlightColor = it) }, + ) + float( + title = Strings.PreferencesEditorCursorPositionEntryBorderHighlightWidth, + defaultValue = AppConf.Editor.DEFAULT_CURSOR_POSITION_ENTRY_BORDER_HIGHLIGHT_WIDTH, + min = 2f, + max = 10f, + select = { it.cursorPositionEntryBorderHighlightWidth }, + update = { copy(cursorPositionEntryBorderHighlightWidth = it) }, + ) + } + } + } + object Playback : PreferencesPage(Strings.PreferencesPlayback, Strings.PreferencesPlaybackDescription) { override val content: List diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/editor/labeler/marker/Marker.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/editor/labeler/marker/Marker.kt index 336c0a36..900c37b6 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/editor/labeler/marker/Marker.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/editor/labeler/marker/Marker.kt @@ -313,12 +313,40 @@ private fun FieldBorderCanvas( state.getEntryIndexesByBorderIndex(pointIndex).second == entryIndex ) 1f else IDLE_LINE_ALPHA if (border in screenRange) { + var strokeWidth: Float = STROKE_WIDTH + var color = borderColor.copy(alpha = borderLineAlpha) + if (editorConf.highlightCurrentEntryBorder) { + val currentIndex = editorState.project.currentModule.currentIndex + if (currentIndex == entryIndex || currentIndex == entryIndex - 1) { + strokeWidth = editorConf.currentEntryBorderHighlightWidth + color = editorConf.currentEntryBorderHighlightColor.toColor() + } + } + // when dragging, the highlight border would glitch, but I have no idea how to fix that + if (editorConf.highlightCursorPositionEntryBorder) { + cursorState.value.position?.let { position -> + if (entryInPixel.getActualStart(labelerConf) <= position && + position <= entryInPixel.getActualEnd(labelerConf) + ) { + strokeWidth = editorConf.cursorPositionEntryBorderHighlightWidth + color = editorConf.cursorPositionEntryBorderHighlightColor.toColor() + } + state.entriesInPixel.getOrNull(entryIndex - 1)?.let { entryInPixel -> + if (entryInPixel.getActualStart(labelerConf) < position && + position <= entryInPixel.getActualEnd(labelerConf) + ) { + strokeWidth = editorConf.cursorPositionEntryBorderHighlightWidth + color = editorConf.cursorPositionEntryBorderHighlightColor.toColor() + } + } + } + } val relativeBorder = border - screenRange.start drawLine( - color = borderColor.copy(alpha = borderLineAlpha), + color = color, start = Offset(relativeBorder, 0f), end = Offset(relativeBorder, canvasHeight), - strokeWidth = STROKE_WIDTH, + strokeWidth = strokeWidth, ) } } diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/Strings.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/Strings.kt index 023ce4e6..82b102dc 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/Strings.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/Strings.kt @@ -451,6 +451,16 @@ enum class Strings { PreferencesEditorContinuousLabelNamesEditableBackgroundColor, PreferencesEditorContinuousLabelNamesSize, PreferencesEditorContinuousLabelNamesPosition, + PreferencesEditorBorderHighlight, + PreferencesEditorBorderHighlightDescription, + PreferencesEditorHighlightCurrentEntryBorder, + PreferencesEditorHighlightCurrentEntryBorderDescription, + PreferencesEditorCurrentEntryBorderHighlightColor, + PreferencesEditorCurrentEntryBorderHighlightWidth, + PreferencesEditorHighlightCursorPositionEntryBorder, + PreferencesEditorHighlightCursorPositionEntryBorderDescription, + PreferencesEditorCursorPositionEntryBorderHighlightColor, + PreferencesEditorCursorPositionEntryBorderHighlightWidth, PreferencesPlayback, PreferencesPlaybackDescription, PreferencesPlaybackPlayOnDragging, diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsChineseSimplified.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsChineseSimplified.kt index fbf5c6cf..88476f40 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsChineseSimplified.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsChineseSimplified.kt @@ -488,6 +488,16 @@ fun Strings.zhHans(): String? = when (this) { PreferencesEditorContinuousLabelNamesEditableBackgroundColor -> "背景色(编辑中)" PreferencesEditorContinuousLabelNamesSize -> "大小" PreferencesEditorContinuousLabelNamesPosition -> "位置" + PreferencesEditorBorderHighlight -> "边界高亮" + PreferencesEditorBorderHighlightDescription -> "编辑在多条目编辑模式中边界高亮等的设置" + PreferencesEditorHighlightCurrentEntryBorder -> "高亮当前条目的边界" + PreferencesEditorHighlightCurrentEntryBorderDescription -> "在多条目编辑模式下高亮当前条目的边界" + PreferencesEditorCurrentEntryBorderHighlightColor -> "当前条目边界的高亮颜色" + PreferencesEditorCurrentEntryBorderHighlightWidth -> "当前条目边界的高亮宽度" + PreferencesEditorHighlightCursorPositionEntryBorder -> "高亮光标位置条目的边界" + PreferencesEditorHighlightCursorPositionEntryBorderDescription -> "在多条目编辑模式下高亮光标位置的条目边界" + PreferencesEditorCursorPositionEntryBorderHighlightColor -> "光标位置条目边界的高亮颜色" + PreferencesEditorCursorPositionEntryBorderHighlightWidth -> "光标位置条目边界的高亮宽度" PreferencesPlayback -> "播放" PreferencesPlaybackDescription -> "编辑音频播放的行为。" PreferencesPlaybackPlayOnDragging -> "预览播放" diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsEnglish.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsEnglish.kt index d66bee24..549f61c2 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsEnglish.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsEnglish.kt @@ -547,6 +547,18 @@ fun Strings.en(): String = when (this) { PreferencesEditorContinuousLabelNamesEditableBackgroundColor -> "Background color (editing)" PreferencesEditorContinuousLabelNamesSize -> "Size" PreferencesEditorContinuousLabelNamesPosition -> "Position" + PreferencesEditorBorderHighlight -> "Border Highlight" + PreferencesEditorBorderHighlightDescription -> "Customize border highlighting in multiple entry edit mode" + PreferencesEditorHighlightCurrentEntryBorder -> "Highlight current entry border" + PreferencesEditorHighlightCurrentEntryBorderDescription, + -> "Highlight current entry border in multiple entry edit mode." + PreferencesEditorCurrentEntryBorderHighlightColor -> "Highlight color of current entry border" + PreferencesEditorCurrentEntryBorderHighlightWidth -> "Highlight width of current entry border" + PreferencesEditorHighlightCursorPositionEntryBorder -> "Highlight cursor position entry border" + PreferencesEditorHighlightCursorPositionEntryBorderDescription, + -> "Highlight cursor position entry border in multiple entry edit mode." + PreferencesEditorCursorPositionEntryBorderHighlightColor -> "Highlight color of the cursor position entry border" + PreferencesEditorCursorPositionEntryBorderHighlightWidth -> "Highlight width of the cursor position entry border" PreferencesPlayback -> "Playback" PreferencesPlaybackDescription -> "Customize the behavior about audio playback." PreferencesPlaybackPlayOnDragging -> "Preview playback"