Skip to content
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

Add border highlight in multi-edit mode #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/jvmMain/kotlin/com/sdercolin/vlabeler/model/AppConf.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {

/**
Expand Down Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ object PreferencesPages {
EditorNotes,
EditorContinuousLabelNames,
EditorPostEditAction,
EditorBorderHighlight,
)

override val content: List<PreferencesGroup>
Expand Down Expand Up @@ -1010,6 +1011,65 @@ object PreferencesPages {
}
}

object EditorBorderHighlight : PreferencesPage(
Strings.PreferencesEditorBorderHighlight,
Strings.PreferencesEditorBorderHighlightDescription,
) {
override val content: List<PreferencesGroup>
get() = buildPageContent {
withContext(
selector = { it.editor },
updater = { copy(editor = it) },
) {

switch(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use grouping (you can find examples in this file) to make it more clear, and some repeated texts can be simplified.

QQ_1730900533308

For example, these can be simply Color and Width under a group.

Copy link
Owner

@sdercolin sdercolin Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I feel like the default color/width settings should be inverted.
The cursor should have the highest visual priority.

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<PreferencesGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add some checks about multiple edit mode here.

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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most simple fix:

Suggested change
if (editorConf.highlightCursorPositionEntryBorder) {
if (editorConf.highlightCursorPositionEntryBorder &&
cursorState.value.mouse != MarkerCursorState.Mouse.Dragging
) {

But this will cause the highlight to disappear when dragging.

So if we want it perfectly, we need to add a previousPositionBeforeDragging nullable field in MarkerCursorState:

  1. in startDragging, copy the position value to previousPositionBeforeDragging
  2. during dragging, do not change it
  3. in finishDragging, clear it
  4. when drawing the highlight, get the position according to the mouse type. If it's dragging, use previousPositionBeforeDragging, otherwise, use position

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um, I think I was wrong.
Even if we remember the cursor position before we start dragging, the borders are changing, causing the entry selected also changing.

So we probably should instead remember a relative offset of the clicked position and the parameter line being dragged, so when rendering the lines, we can get a stable cursor position.

Copy link
Owner

@sdercolin sdercolin Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it working. Please have a look! (It's a git patch, if you don't now how to apply it please Google or GPT)

patch.diff.zip

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,
)
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/Strings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,16 @@ enum class Strings {
PreferencesEditorContinuousLabelNamesEditableBackgroundColor,
PreferencesEditorContinuousLabelNamesSize,
PreferencesEditorContinuousLabelNamesPosition,
PreferencesEditorBorderHighlight,
PreferencesEditorBorderHighlightDescription,
PreferencesEditorHighlightCurrentEntryBorder,
PreferencesEditorHighlightCurrentEntryBorderDescription,
PreferencesEditorCurrentEntryBorderHighlightColor,
PreferencesEditorCurrentEntryBorderHighlightWidth,
PreferencesEditorHighlightCursorPositionEntryBorder,
PreferencesEditorHighlightCursorPositionEntryBorderDescription,
PreferencesEditorCursorPositionEntryBorderHighlightColor,
PreferencesEditorCursorPositionEntryBorderHighlightWidth,
PreferencesPlayback,
PreferencesPlaybackDescription,
PreferencesPlaybackPlayOnDragging,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,16 @@ fun Strings.zhHans(): String? = when (this) {
PreferencesEditorContinuousLabelNamesEditableBackgroundColor -> "背景色(编辑中)"
PreferencesEditorContinuousLabelNamesSize -> "大小"
PreferencesEditorContinuousLabelNamesPosition -> "位置"
PreferencesEditorBorderHighlight -> "边界高亮"
PreferencesEditorBorderHighlightDescription -> "编辑在多条目编辑模式中边界高亮等的设置"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a period.

PreferencesEditorHighlightCurrentEntryBorder -> "高亮当前条目的边界"
PreferencesEditorHighlightCurrentEntryBorderDescription -> "在多条目编辑模式下高亮当前条目的边界"
PreferencesEditorCurrentEntryBorderHighlightColor -> "当前条目边界的高亮颜色"
PreferencesEditorCurrentEntryBorderHighlightWidth -> "当前条目边界的高亮宽度"
PreferencesEditorHighlightCursorPositionEntryBorder -> "高亮光标位置条目的边界"
PreferencesEditorHighlightCursorPositionEntryBorderDescription -> "在多条目编辑模式下高亮光标位置的条目边界"
PreferencesEditorCursorPositionEntryBorderHighlightColor -> "光标位置条目边界的高亮颜色"
PreferencesEditorCursorPositionEntryBorderHighlightWidth -> "光标位置条目边界的高亮宽度"
PreferencesPlayback -> "播放"
PreferencesPlaybackDescription -> "编辑音频播放的行为。"
PreferencesPlaybackPlayOnDragging -> "预览播放"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a period.

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"
Expand Down
Loading