skyline/app/src/main/java/emu/skyline/input/onscreen/OnScreenEditInfo.kt
lynxnb 816599749b Fix Android Studio OSC layout preview (again)
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.
2023-04-02 18:16:10 +02:00

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()
}
}