mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-06-01 10:48:45 +02:00
816599749b
The layout preview/editor doesn't instantiate an Application instance, therefore accessing `displayMetrics` from the app context would lead to a crash, and the view being mocked in the preview. Additionally a default grid value is defined for `AlignmentGridView` to avoid a crash because of an invalid iteration step in the drawing loop.
48 lines
1.1 KiB
Kotlin
48 lines
1.1 KiB
Kotlin
/*
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
* Copyright © 2023 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
|
*/
|
|
|
|
package emu.skyline.input.onscreen
|
|
|
|
import android.content.res.Resources
|
|
import android.util.TypedValue
|
|
|
|
enum class EditMode {
|
|
None,
|
|
Move,
|
|
Resize
|
|
}
|
|
|
|
/**
|
|
* A small class that holds information about the current edit session
|
|
* This is used to share information between the [OnScreenControllerView] and the individual [OnScreenButton]s
|
|
*/
|
|
class OnScreenEditInfo {
|
|
/**
|
|
* The current edit mode
|
|
*/
|
|
var editMode : EditMode = EditMode.None
|
|
|
|
/**
|
|
* The button that is currently being edited
|
|
*/
|
|
var editButton : OnScreenButton? = null
|
|
|
|
/**
|
|
* Whether the buttons should snap to a grid when in edit mode
|
|
*/
|
|
var snapToGrid : Boolean = false
|
|
|
|
var gridSize : Int = GridSize
|
|
|
|
val isEditing get() = editMode != EditMode.None
|
|
|
|
companion object {
|
|
/**
|
|
* The size of the grid, calculated from the value of 8dp
|
|
*/
|
|
var GridSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8f, Resources.getSystem().displayMetrics).toInt()
|
|
}
|
|
}
|