fix SaveSettings (+androidMain)
This commit is contained in:
parent
2403c3f700
commit
e941da6f19
3 changed files with 66 additions and 29 deletions
|
|
@ -0,0 +1,14 @@
|
|||
package mg.dot.feufaro
|
||||
|
||||
import com.russhwolf.settings.Settings
|
||||
import com.russhwolf.settings.set
|
||||
|
||||
actual class SaveSettings actual constructor() {
|
||||
actual val settings: Settings = Settings()
|
||||
|
||||
actual fun loadLastUsedDir(): String = settings.getString("last_dir", "/")
|
||||
actual fun saveLastUsedDir(lastDir: String) { settings["last_dir"] = lastDir }
|
||||
|
||||
actual fun saveWindowBounds(width: Int, height: Int, x: Int, y: Int) {}
|
||||
actual fun loadWindowBounds(): List<Int> = listOf(0, 0, 0, 0)
|
||||
}
|
||||
|
|
@ -8,36 +8,13 @@ import androidx.compose.ui.window.WindowPlacement
|
|||
import androidx.compose.ui.window.WindowState
|
||||
import androidx.compose.ui.window.WindowPosition
|
||||
|
||||
class SaveSettings {
|
||||
expect class SaveSettings() {
|
||||
val settings: Settings
|
||||
|
||||
private val settings: Settings = Settings()
|
||||
fun loadLastUsedDir(): String
|
||||
|
||||
fun loadLastUsedDir(): String {
|
||||
val lastDirectory = settings.getString("last_dir", "/")
|
||||
fun saveLastUsedDir(lastDir: String)
|
||||
|
||||
return lastDirectory
|
||||
}
|
||||
|
||||
fun saveLastUsedDir(lastDir: String) {
|
||||
settings["last_dir"] = lastDir
|
||||
}
|
||||
|
||||
fun loadWindowState(): WindowState {
|
||||
val width = settings.getInt("window_width", 800)
|
||||
val height = settings.getInt("window_height", 600)
|
||||
val x = settings.getInt("window_x", 100)
|
||||
val y = settings.getInt("window_y", 100)
|
||||
|
||||
return WindowState(
|
||||
size = DpSize(width.dp, height.dp),
|
||||
position = WindowPosition(x.dp, y.dp)
|
||||
)
|
||||
}
|
||||
|
||||
fun saveWindowState(state: WindowState) {
|
||||
settings["window_width"] = state.size.width.value.toInt()
|
||||
settings["window_height"] = state.size.height.value.toInt()
|
||||
settings["window_x"] = state.position.x.value.toInt()
|
||||
settings["window_y"] = state.position.y.value.toInt()
|
||||
}
|
||||
fun loadWindowState(): WindowState
|
||||
fun saveWindowState(state: WindowState)
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package mg.dot.feufaro
|
||||
|
||||
import com.russhwolf.settings.Settings
|
||||
import com.russhwolf.settings.set
|
||||
import androidx.compose.ui.window.WindowState
|
||||
import androidx.compose.ui.window.WindowPosition
|
||||
import androidx.compose.ui.unit.DpSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
actual class SaveSettings actual constructor() {
|
||||
actual val settings: Settings = Settings()
|
||||
|
||||
actual fun loadLastUsedDir(): String = settings.getString("last_dir", "/")
|
||||
actual fun saveLastUsedDir(lastDir: String) { settings["last_dir"] = lastDir }
|
||||
|
||||
fun saveWindowBounds(width: Int, height: Int, x: Int, y: Int) {
|
||||
settings["window_width"] = width
|
||||
settings["window_height"] = height
|
||||
settings["window_x"] = x
|
||||
settings["window_y"] = y
|
||||
}
|
||||
|
||||
fun loadWindowBounds(): List<Int> = listOf(
|
||||
settings.getInt("window_width", 800),
|
||||
settings.getInt("window_height", 600),
|
||||
settings.getInt("window_x", 100),
|
||||
settings.getInt("window_y", 100)
|
||||
)
|
||||
|
||||
actual fun loadWindowState(): WindowState {
|
||||
val bounds = loadWindowBounds()
|
||||
return WindowState(
|
||||
size = DpSize(bounds[0].dp, bounds[1].dp),
|
||||
position = WindowPosition(bounds[2].dp, bounds[3].dp)
|
||||
)
|
||||
}
|
||||
|
||||
actual fun saveWindowState(state: WindowState) {
|
||||
saveWindowBounds(
|
||||
state.size.width.value.toInt(),
|
||||
state.size.height.value.toInt(),
|
||||
state.position.x.value.toInt(),
|
||||
state.position.y.value.toInt()
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue