fix(gtk): handle scrolling of settings tabs independently

This commit is contained in:
Johannes Frohnmeyer 2024-10-04 18:06:59 +02:00
parent 4dfcbb038d
commit 363a62542e
Signed by: Johannes
GPG Key ID: E76429612C2929F4
4 changed files with 15 additions and 11 deletions

View File

@ -7,7 +7,7 @@ import org.gnome.gtk.*
import org.jetbrains.annotations.PropertyKey import org.jetbrains.annotations.PropertyKey
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
open class SectionedSettingsTab<W : Window>(window: W?): SettingsTab<Box, W>(window, Box(Orientation.VERTICAL, 8)) { open class SectionedSettingsTab<W : Window>(window: W?): SettingsTab<Box, W>(window, Box(Orientation.VERTICAL, 8), true) {
init { init {
content.marginHorizontal = 24 content.marginHorizontal = 24
content.marginTop = 12 content.marginTop = 12

View File

@ -7,7 +7,8 @@ import org.gnome.gtk.Window
open class SettingsTab<T : Widget, W : Window>( open class SettingsTab<T : Widget, W : Window>(
protected val window: W?, protected val window: W?,
val content: T val content: T,
val scrollable: Boolean
) { ) {
protected fun showError(message: String, t: Throwable) = protected fun showError(message: String, t: Throwable) =
GtkEnvBackend.simpleDialog( GtkEnvBackend.simpleDialog(

View File

@ -15,7 +15,9 @@ open class SettingsWindow(app: Application?) : Window() {
init { init {
application = app application = app
stack = ViewStack() stack = ViewStack().apply {
vexpand = true
}
val header = HeaderBar() val header = HeaderBar()
val viewSwitcher = ViewSwitcherTitle() val viewSwitcher = ViewSwitcherTitle()
@ -23,16 +25,11 @@ open class SettingsWindow(app: Application?) : Window() {
header.titleWidget = viewSwitcher header.titleWidget = viewSwitcher
titlebar = header titlebar = header
val scroll = ScrolledWindow()
scroll.setPolicy(PolicyType.NEVER, PolicyType.AUTOMATIC)
scroll.child = stack
scroll.vexpand = true
val bottomBar = ViewSwitcherBar() val bottomBar = ViewSwitcherBar()
bottomBar.stack = stack bottomBar.stack = stack
viewSwitcher.bindProperty("title-visible", bottomBar, "reveal", BindingFlags.DEFAULT) viewSwitcher.bindProperty("title-visible", bottomBar, "reveal", BindingFlags.DEFAULT)
val view = Box(Orientation.VERTICAL, 0) val view = Box(Orientation.VERTICAL, 0)
view.append(scroll) view.append(stack)
view.append(bottomBar) view.append(bottomBar)
child = view child = view
@ -41,7 +38,13 @@ open class SettingsWindow(app: Application?) : Window() {
} }
fun addTab(tab: SettingsTab<*, *>, title: @PropertyKey(resourceBundle = I18n.BUNDLE) String, iconName: String) { fun addTab(tab: SettingsTab<*, *>, title: @PropertyKey(resourceBundle = I18n.BUNDLE) String, iconName: String) {
stack.addTitledWithIcon(tab.content, title, I18n[title], iconName) if (tab.scrollable) {
stack.addTitledWithIcon(ScrolledWindow().apply {
child = tab.content
}, title, I18n[title], iconName)
} else {
stack.addTitledWithIcon(tab.content, title, I18n[title], iconName)
}
} }
var activePage: String var activePage: String

View File

@ -31,7 +31,7 @@ import org.jetbrains.annotations.PropertyKey
import java.util.concurrent.ForkJoinPool import java.util.concurrent.ForkJoinPool
import kotlin.jvm.optionals.getOrNull import kotlin.jvm.optionals.getOrNull
class ModsTab(window: InstanceSettingsWindow) : SettingsTab<Leaflet, InstanceSettingsWindow>(window, Leaflet()) { class ModsTab(window: InstanceSettingsWindow) : SettingsTab<Leaflet, InstanceSettingsWindow>(window, Leaflet(), false) {
private val instance: Instance = window.instance private val instance: Instance = window.instance
private val mds: ModsDirScanner = instance.mds private val mds: ModsDirScanner = instance.mds
private val listModel: StringList private val listModel: StringList