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 click on canvas to jumpToEntry in multi-edit mode #49

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
2 changes: 2 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,7 @@ data class AppConf(
val continuousLabelNames: ContinuousLabelNames = ContinuousLabelNames(),
val postEditNext: PostEditAction = PostEditAction.DEFAULT_NEXT,
val postEditDone: PostEditAction = PostEditAction.DEFAULT_DONE,
val clickToSwitchCurrentIndex: Boolean = DEFAULT_CLICK_TO_SWITCH_CURRENT_INDEX,
) {

/**
Expand Down Expand Up @@ -399,6 +400,7 @@ data class AppConf(
const val DEFAULT_SHOW_STAR = true
const val DEFAULT_SHOW_TAG = true
const val DEFAULT_SHOW_EXTRA = true
const val DEFAULT_CLICK_TO_SWITCH_CURRENT_INDEX = false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,12 @@ object PreferencesPages {
select = { it.playerCursorColor },
update = { copy(playerCursorColor = 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 place it over the color.

title = Strings.PreferencesEditorClickToJumToEntry,
defaultValue = AppConf.Editor.DEFAULT_CLICK_TO_SWITCH_CURRENT_INDEX,
select = { it.clickToSwitchCurrentIndex },
update = { copy(clickToSwitchCurrentIndex = it) },
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,15 @@ fun MarkerPointEventContainer(
)
}
.onPointerEvent(PointerEventType.Press) { event ->
state.handleMousePress(tool, keyboardState, event, state.labelerConf, appState.appConf, screenRange)
state.handleMousePress(
tool,
keyboardState,
event,
state.labelerConf,
appState.appConf,
screenRange,
editorState,
)
}
.onPointerEvent(PointerEventType.Release) { event ->
state.handleMouseRelease(
Expand Down Expand Up @@ -583,9 +591,10 @@ private fun MarkerState.handleMousePress(
labelerConf: LabelerConf,
appConf: AppConf,
screenRange: FloatRange?,
editorState: EditorState,
) {
when (tool) {
Tool.Cursor -> handleCursorPress(keyboardState, event, labelerConf, appConf)
Tool.Cursor -> handleCursorPress(keyboardState, event, labelerConf, appConf, editorState)
Tool.Scissors -> Unit
Tool.Pan -> handlePanPress(event)
Tool.Playback -> handlePlaybackPress(keyboardState, screenRange, event)
Expand All @@ -597,6 +606,7 @@ private fun MarkerState.handleCursorPress(
event: PointerEvent,
labelerConf: LabelerConf,
appConf: AppConf,
editorState: EditorState,
) {
val action = keyboardState.getEnabledMouseClickAction(event) ?: return
if (action.canMoveParameter()) {
Copy link
Owner

Choose a reason for hiding this comment

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

I think we need to add another mouse action instead of handling it over the existing moving actions, right now, if we enable this, it's very difficult to drag parameter lines, because when you press, it immediately causes the jumping.

Also, it might be better UX if we handle it on mouse release (up), not mouse press (down).

Even if we use another mouse action, we should note that the action def might be the same for multiple actions (e.g. we can simply set Left Click on this new action).
So, e.g. when we handle it on mouse release, we need to check whether this release event is a finishing event of a dragging, and only handle when it's not.

Expand All @@ -619,6 +629,15 @@ private fun MarkerState.handleCursorPress(
val forcedDrag = action == MouseClickAction.MoveParameterIgnoringConstraints
cursorState.update { startDragging(lockedDrag, withPreview, forcedDrag) }
}
if (appConf.editor.clickToSwitchCurrentIndex) {
cursorStateValue.position?.let { position ->
getEntryIndexByCursorPosition(position)?.let { index ->
// having bugs here
// if the cursor do not move, it would not jump
Copy link
Owner

Choose a reason for hiding this comment

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

Do you mean, when only clicking and without any moving, this line is not executed?
It doesn't happen on my side.
Could you explain more?

editorState.jumpToEntry(editorState.project.currentModule.name, index)
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,15 @@ class MarkerState(
return null
}

fun getEntryIndexByCursorPosition(position: Float): Int? {
entriesInPixel.forEachIndexed { index, entry ->
if (entry.getActualStart(labelerConf) <= position && entry.getActualEnd(labelerConf) >= position) {
return index
}
}
return null
}

fun isValidCutPosition(position: Float) = entriesInPixel.any { it.isValidCutPosition(position) }

fun isValidPlaybackPosition(position: Float) = position < entryConverter.convertToPixel(sampleLengthMillis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ enum class Strings {
PreferencesEditor,
PreferencesEditorDescription,
PreferencesEditorPlayerCursorColor,
PreferencesEditorClickToJumToEntry,
PreferencesEditorLockedDrag,
PreferencesEditorLockedDragDescription,
PreferencesEditorLockedDragUseLabeler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ fun Strings.zhHans(): String? = when (this) {
PreferencesEditor -> "编辑器"
PreferencesEditorDescription -> "编辑编辑器的外观与行为。"
PreferencesEditorPlayerCursorColor -> "音频播放光标颜色"
PreferencesEditorClickToJumToEntry -> "在多条目编辑模式下,单击画布上的条目即可跳转到该条目"
PreferencesEditorLockedDrag -> "锁定拖动"
PreferencesEditorLockedDragDescription ->
"选择启用锁定拖动的条件。" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ fun Strings.en(): String = when (this) {
PreferencesEditor -> "Editor"
PreferencesEditorDescription -> "Customize the editor's appearance and behavior."
PreferencesEditorPlayerCursorColor -> "Player cursor color"
PreferencesEditorClickToJumToEntry ->
Copy link
Owner

Choose a reason for hiding this comment

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

typo: Jum -> Jump

"Jump to the cursor position entry by clicking it on canvas 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.

QQ_1730898459961
The title should be simple and short, like "Click to switch entry"
We can add a description to it.

PreferencesEditorLockedDrag -> "Fixed-drag"
PreferencesEditorLockedDragDescription ->
"Select a condition to enable fixed-drag while you move " +
Expand Down
Loading