Design/Layout

This commit is contained in:
downthecrop 2025-08-13 03:19:50 -07:00
parent f386c464f4
commit 2cee659582
2 changed files with 95 additions and 57 deletions

View file

@ -79,8 +79,48 @@ object ReflectiveEditorView {
loadedPluginsField.isAccessible = true loadedPluginsField.isAccessible = true
val loadedPlugins = loadedPluginsField.get(null) as HashMap<*, *> val loadedPlugins = loadedPluginsField.get(null) as HashMap<*, *>
// Separate plugins with and without exposed attributes
val pluginsWithExposed = mutableListOf<Pair<PluginInfo, Plugin>>()
val pluginsWithoutExposed = mutableListOf<Pair<PluginInfo, Plugin>>()
for ((pluginInfo, plugin) in loadedPlugins) { for ((pluginInfo, plugin) in loadedPlugins) {
val pluginPanel = createPluginItemPanel(pluginInfo as PluginInfo, plugin as Plugin) val exposedFields = (plugin as Plugin).javaClass.declaredFields.filter { field ->
field.annotations.any { annotation ->
annotation.annotationClass.simpleName == "Exposed"
}
}
if (exposedFields.isNotEmpty()) {
pluginsWithExposed.add(pluginInfo as PluginInfo to plugin as Plugin)
} else {
pluginsWithoutExposed.add(pluginInfo as PluginInfo to plugin as Plugin)
}
}
// Sort both lists by package name
pluginsWithExposed.sortBy { it.second.javaClass.`package`.name }
pluginsWithoutExposed.sortBy { it.second.javaClass.`package`.name }
// Add plugins with exposed attributes first
for ((pluginInfo, plugin) in pluginsWithExposed) {
val pluginPanel = createPluginItemPanel(pluginInfo, plugin)
panel.add(pluginPanel)
panel.add(Box.createVerticalStrut(5))
}
// Add a separator if we have plugins with exposed attributes
if (pluginsWithExposed.isNotEmpty() && pluginsWithoutExposed.isNotEmpty()) {
val separator = JPanel()
separator.background = VIEW_BACKGROUND_COLOR
separator.preferredSize = Dimension(Int.MAX_VALUE, 1)
separator.maximumSize = Dimension(Int.MAX_VALUE, 1)
panel.add(separator)
panel.add(Box.createVerticalStrut(5))
}
// Add plugins without exposed attributes
for ((pluginInfo, plugin) in pluginsWithoutExposed) {
val pluginPanel = createPluginItemPanel(pluginInfo, plugin)
panel.add(pluginPanel) panel.add(pluginPanel)
panel.add(Box.createVerticalStrut(5)) panel.add(Box.createVerticalStrut(5))
} }
@ -119,18 +159,30 @@ object ReflectiveEditorView {
nameLabel.foreground = secondaryColor nameLabel.foreground = secondaryColor
nameLabel.font = Font("RuneScape Small", Font.BOLD, 16) nameLabel.font = Font("RuneScape Small", Font.BOLD, 16)
// Check if plugin has exposed attributes
val exposedFields = plugin.javaClass.declaredFields.filter { field ->
field.annotations.any { annotation ->
annotation.annotationClass.simpleName == "Exposed"
}
}
// Edit button (only show if plugin has exposed attributes)
val editButton = if (exposedFields.isNotEmpty()) {
val button = JButton("Edit")
button.background = TITLE_BAR_COLOR
button.foreground = secondaryColor
button.font = Font("RuneScape Small", Font.PLAIN, 14)
button.addActionListener {
showPluginDetails(pluginInfo, plugin)
}
button
} else {
null
}
// Plugin toggle switch (iOS style) // Plugin toggle switch (iOS style)
val toggleSwitch = createToggleSwitch(plugin, pluginInfo) val toggleSwitch = createToggleSwitch(plugin, pluginInfo)
// Edit button
val editButton = JButton("Edit")
editButton.background = TITLE_BAR_COLOR
editButton.foreground = secondaryColor
editButton.font = Font("RuneScape Small", Font.PLAIN, 14)
editButton.addActionListener {
showPluginDetails(pluginInfo, plugin)
}
// Layout // Layout
val infoPanel = JPanel(BorderLayout()) val infoPanel = JPanel(BorderLayout())
infoPanel.background = WIDGET_COLOR infoPanel.background = WIDGET_COLOR
@ -138,8 +190,12 @@ object ReflectiveEditorView {
val controlsPanel = JPanel(FlowLayout(FlowLayout.RIGHT, 5, 0)) val controlsPanel = JPanel(FlowLayout(FlowLayout.RIGHT, 5, 0))
controlsPanel.background = WIDGET_COLOR controlsPanel.background = WIDGET_COLOR
// Add edit button first (left side of controls)
editButton?.let { controlsPanel.add(it) }
// Add toggle switch second (right side of controls)
controlsPanel.add(toggleSwitch) controlsPanel.add(toggleSwitch)
controlsPanel.add(editButton)
panel.add(infoPanel, BorderLayout.CENTER) panel.add(infoPanel, BorderLayout.CENTER)
panel.add(controlsPanel, BorderLayout.EAST) panel.add(controlsPanel, BorderLayout.EAST)

View file

@ -13,7 +13,6 @@ class ToggleSwitch : JPanel() {
private var borderColor = Color(50, 50, 50) private var borderColor = Color(50, 50, 50)
private var activeSwitch = Color(0, 125, 255) private var activeSwitch = Color(0, 125, 255)
private var puffer: BufferedImage? = null private var puffer: BufferedImage? = null
private var borderRadius = 10
private var g: Graphics2D? = null private var g: Graphics2D? = null
var onToggleListener: ((Boolean) -> Unit)? = null var onToggleListener: ((Boolean) -> Unit)? = null
@ -28,9 +27,10 @@ class ToggleSwitch : JPanel() {
} }
}) })
cursor = Cursor(Cursor.HAND_CURSOR) cursor = Cursor(Cursor.HAND_CURSOR)
preferredSize = Dimension(41, 21) preferredSize = Dimension(40, 20)
maximumSize = Dimension(41, 21) maximumSize = Dimension(40, 20)
minimumSize = Dimension(41, 21) minimumSize = Dimension(40, 20)
isOpaque = false // Make the panel background transparent
} }
override fun paint(gr: Graphics) { override fun paint(gr: Graphics) {
@ -44,37 +44,33 @@ class ToggleSwitch : JPanel() {
g?.setRenderingHints(rh) g?.setRenderingHints(rh)
} }
g?.color = if (activated) activeSwitch else switchColor // Clear the buffer with transparent background
g?.fillRoundRect(0, 0, width - 1, height - 1, 5, borderRadius) g?.color = Color(0, 0, 0, 0)
g?.color = borderColor g?.fillRect(0, 0, width, height)
g?.drawRoundRect(0, 0, width - 1, height - 1, 5, borderRadius)
g?.color = buttonColor
if (activated) { // Draw the track with circular ends (rounded rectangle)
g?.fillRoundRect( val trackHeight = height - 2
width / 2, 1, val trackWidth = width - 2
(width - 1) / 2 - 2, (height - 1) - 2, val trackArc = trackHeight // Makes it fully rounded at the ends
borderRadius, borderRadius
) g?.color = if (activated) activeSwitch else switchColor
g?.color = borderColor g?.fillRoundRect(1, 1, trackWidth, trackHeight, trackArc, trackArc)
g?.drawRoundRect( g?.color = borderColor
(width - 1) / 2, 0, g?.drawRoundRect(1, 1, trackWidth, trackHeight, trackArc, trackArc)
(width - 1) / 2, (height - 1),
borderRadius, borderRadius // Draw the thumb (circular button)
) val thumbDiameter = trackHeight - 4
val thumbX = if (activated) {
width - thumbDiameter - 3 // Right side when activated
} else { } else {
g?.fillRoundRect( 3 // Left side when not activated
1, 1,
(width - 1) / 2 - 2, (height - 1) - 2,
borderRadius, borderRadius
)
g?.color = borderColor
g?.drawRoundRect(
0, 0,
(width - 1) / 2, (height - 1),
borderRadius, borderRadius
)
} }
val thumbY = (height - thumbDiameter) / 2
g?.color = buttonColor
g?.fillOval(thumbX, thumbY, thumbDiameter, thumbDiameter)
g?.color = borderColor
g?.drawOval(thumbX, thumbY, thumbDiameter, thumbDiameter)
gr.drawImage(puffer, 0, 0, null) gr.drawImage(puffer, 0, 0, null)
} }
@ -128,18 +124,4 @@ class ToggleSwitch : JPanel() {
fun setActiveSwitch(activeSwitch: Color) { fun setActiveSwitch(activeSwitch: Color) {
this.activeSwitch = activeSwitch this.activeSwitch = activeSwitch
} }
/**
* @return the borderRadius
*/
fun getBorderRadius(): Int {
return borderRadius
}
/**
* @param borderRadius the borderRadius to set
*/
fun setBorderRadius(borderRadius: Int) {
this.borderRadius = borderRadius
}
} }