mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-20 05:20:24 -07:00
Toggle Switches
This commit is contained in:
parent
ac2478d10f
commit
f386c464f4
2 changed files with 157 additions and 45 deletions
|
|
@ -3,6 +3,7 @@ package KondoKit
|
|||
import KondoKit.Helpers.convertValue
|
||||
import KondoKit.Helpers.showToast
|
||||
import KondoKit.ScrollablePanel
|
||||
import KondoKit.ToggleSwitch
|
||||
import KondoKit.plugin.Companion.TITLE_BAR_COLOR
|
||||
import KondoKit.plugin.Companion.TOOLTIP_BACKGROUND
|
||||
import KondoKit.plugin.Companion.VIEW_BACKGROUND_COLOR
|
||||
|
|
@ -146,36 +147,18 @@ object ReflectiveEditorView {
|
|||
return panel
|
||||
}
|
||||
|
||||
private fun createToggleSwitch(plugin: Plugin, pluginInfo: PluginInfo): JPanel {
|
||||
val switchPanel = JPanel(null) // null layout for precise positioning
|
||||
switchPanel.background = WIDGET_COLOR
|
||||
switchPanel.preferredSize = Dimension(50, 25)
|
||||
switchPanel.maximumSize = Dimension(50, 25)
|
||||
switchPanel.minimumSize = Dimension(50, 25)
|
||||
private fun createToggleSwitch(plugin: Plugin, pluginInfo: PluginInfo): ToggleSwitch {
|
||||
val toggleSwitch = ToggleSwitch()
|
||||
|
||||
// Track (background)
|
||||
val track = JPanel()
|
||||
track.background = if (isPluginEnabled(pluginInfo)) Color(0, 122, 255) else Color(142, 142, 147)
|
||||
track.setBounds(0, 0, 50, 25)
|
||||
track.border = RoundedBorder(12)
|
||||
// Set initial state
|
||||
toggleSwitch.setActivated(isPluginEnabled(pluginInfo))
|
||||
|
||||
// Thumb (slider)
|
||||
val thumb = JPanel()
|
||||
thumb.background = Color.WHITE
|
||||
thumb.setBounds(if (isPluginEnabled(pluginInfo)) 27 else 3, 3, 20, 20)
|
||||
thumb.border = RoundedBorder(10)
|
||||
// Add toggle listener
|
||||
toggleSwitch.onToggleListener = { activated ->
|
||||
togglePlugin(pluginInfo, plugin, toggleSwitch, activated)
|
||||
}
|
||||
|
||||
switchPanel.add(track)
|
||||
switchPanel.add(thumb)
|
||||
|
||||
// Add click handler to toggle
|
||||
switchPanel.addMouseListener(object : MouseAdapter() {
|
||||
override fun mouseClicked(e: MouseEvent) {
|
||||
togglePlugin(pluginInfo, plugin, track, thumb)
|
||||
}
|
||||
})
|
||||
|
||||
return switchPanel
|
||||
return toggleSwitch
|
||||
}
|
||||
|
||||
private fun isPluginEnabled(pluginInfo: PluginInfo): Boolean {
|
||||
|
|
@ -184,25 +167,9 @@ object ReflectiveEditorView {
|
|||
return true
|
||||
}
|
||||
|
||||
private fun togglePlugin(pluginInfo: PluginInfo, plugin: Plugin, track: JPanel, thumb: JPanel) {
|
||||
// Simple toggle animation
|
||||
val isEnabled = track.background == Color(0, 122, 255)
|
||||
|
||||
if (isEnabled) {
|
||||
// Toggle off
|
||||
track.background = Color(142, 142, 147)
|
||||
thumb.setLocation(3, 3)
|
||||
} else {
|
||||
// Toggle on
|
||||
track.background = Color(0, 122, 255)
|
||||
thumb.setLocation(27, 3)
|
||||
}
|
||||
|
||||
track.repaint()
|
||||
thumb.repaint()
|
||||
|
||||
private fun togglePlugin(pluginInfo: PluginInfo, plugin: Plugin, toggleSwitch: ToggleSwitch, activated: Boolean) {
|
||||
// In a full implementation, you would disable/enable the plugin here
|
||||
showToast(mainPanel, if (isEnabled) "Plugin disabled" else "Plugin enabled")
|
||||
showToast(mainPanel, if (activated) "Plugin enabled" else "Plugin disabled")
|
||||
}
|
||||
|
||||
private fun showPluginDetails(pluginInfo: PluginInfo, plugin: Plugin) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue