Skip to content

Commit

Permalink
adds animate splits and animation duration options to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
cmcpasserby committed Feb 7, 2025
1 parent 567ccb9 commit e98c8fd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/main/kotlin/GoldenRatioPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.intellij.openapi.fileEditor.impl.EditorsSplitters
import com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl
import com.intellij.openapi.ui.Splitter
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.registry.Registry
import com.intellij.ui.ClientProperty
import com.intellij.ui.DrawUtil
import com.intellij.util.SmartList
Expand All @@ -22,7 +21,9 @@ class GoldenRatioPlugin : PersistentStateComponent<GoldenRatioPlugin.State> {

data class State(
var autoEnabled: Boolean = true,
var ratio: Float = (1f + sqrt(5f)) / 2f
var ratio: Float = (1f + sqrt(5f)) / 2f,
var animate: Boolean = true,
var animationDuration: Int = 350,
)

private var myState = State()
Expand All @@ -39,6 +40,18 @@ class GoldenRatioPlugin : PersistentStateComponent<GoldenRatioPlugin.State> {
myState.ratio = value
}

var animate: Boolean
get() = myState.animate
set(value) {
myState.animate = value
}

var animationDuration: Int
get() = myState.animationDuration
set(value) {
myState.animationDuration = value
}

@Suppress("UnstableApiUsage")
private val activeAnimators = SmartList<JBAnimator>()

Expand Down Expand Up @@ -75,15 +88,15 @@ class GoldenRatioPlugin : PersistentStateComponent<GoldenRatioPlugin.State> {

@Suppress("UnstableApiUsage")
private fun setProportion(splitter: Splitter, value: Float) {
if (!Registry.`is`("ide.experimental.ui.animations") || DrawUtil.isSimplifiedUI()) {
if (!myState.animate || DrawUtil.isSimplifiedUI()) {
splitter.proportion = value
return
}

val animator = JBAnimator().also { activeAnimators.add(it) }
animator.animate(
animation(splitter.proportion, value, splitter::setProportion).apply {
duration = 350
duration = myState.animationDuration
runWhenExpiredOrCancelled {
Disposer.dispose(animator)
activeAnimators.remove(animator)
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/settings/GoldenRatioConfigurable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class GoldenRatioConfigurable : SearchableConfigurable, Configurable.NoScroll {
private val autoEnabled
get() = CheckboxDescriptor(message("settings.autoLabel"), settings::autoEnabled)

private val animate
get() = CheckboxDescriptor(message("settings.animateResize"), settings::animate)

private val myPanel = panel {
group(message("settings.group.generalSettings")) {
row { checkBox(autoEnabled) }
Expand All @@ -32,6 +35,11 @@ class GoldenRatioConfigurable : SearchableConfigurable, Configurable.NoScroll {
.gap(RightGap.SMALL)
label(message("settings.ratioLabelSuffix", settings.defaultRatio))
}
row { checkBox(animate) }
row(message("settings.animationDuration")) {
intTextField(10..1000, 1)
.bindIntText(settings::animationDuration)
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/GoldenRatioBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ actions.toggleText=Toggle Auto GoldenRatio
settings.autoLabel=Run GoldenRation automatically on selected pane change
settings.ratioLabelPrefix=Resize panes using a ratio of
settings.ratioLabelSuffix=(default is {0})
settings.group.generalSettings=General Settings
settings.group.generalSettings=General Settings
settings.animateResize=Animate Split Resizing
settings.animationDuration=Animation Duration

0 comments on commit e98c8fd

Please sign in to comment.