Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix toast messages not displaying #73

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class FileMenu : Menu("File") {
saveProject.addListener(object : ClickListener() {
override fun clicked(event: InputEvent?, x: Float, y: Float) {
projectManager.saveCurrentProject()
UI.toaster.success("Project saved")
}
})

Expand Down
17 changes: 11 additions & 6 deletions editor/src/main/com/mbrlabs/mundus/editor/utils/Toaster.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.kotcrab.vis.ui.util.ToastManager
import com.kotcrab.vis.ui.widget.VisLabel
import com.kotcrab.vis.ui.widget.VisTable
import com.kotcrab.vis.ui.widget.toast.Toast
import java.util.*

/**
* Displays Android-like toasts at top right corner of the screen.
Expand All @@ -44,8 +45,9 @@ class Toaster(stage: Stage) {
*/
fun info(msg: String) {
val table = newTable(msg)
val toast = Toast(ToastType.INFO.name.toLowerCase(), table)
val toast = Toast(ToastType.INFO.name.lowercase(Locale.getDefault()), table)
toastManager.show(toast, 3f)
toastManager.toFront()
}

/**
Expand All @@ -55,8 +57,9 @@ class Toaster(stage: Stage) {
*/
fun error(msg: String) {
val table = newTable(msg)
val toast = Toast(ToastType.ERROR.name.toLowerCase(), table)
val toast = Toast(ToastType.ERROR.name.lowercase(Locale.getDefault()), table)
toastManager.show(toast, 5f)
toastManager.toFront()
}

/**
Expand All @@ -66,8 +69,9 @@ class Toaster(stage: Stage) {
*/
fun success(msg: String) {
val table = newTable(msg)
val toast = Toast(ToastType.SUCCESS.name.toLowerCase(), table)
val toast = Toast(ToastType.SUCCESS.name.lowercase(Locale.getDefault()), table)
toastManager.show(toast, 3f)
toastManager.toFront()
}

/**
Expand All @@ -80,14 +84,15 @@ class Toaster(stage: Stage) {
val table = newTable(msg)
var toast: Toast? = null
if (type == ToastType.SUCCESS) {
toast = Toast(ToastType.SUCCESS.name.toLowerCase(), table)
toast = Toast(ToastType.SUCCESS.name.lowercase(Locale.getDefault()), table)
} else if (type == ToastType.INFO) {
toast = Toast(ToastType.INFO.name.toLowerCase(), table)
toast = Toast(ToastType.INFO.name.lowercase(Locale.getDefault()), table)
} else if (type == ToastType.ERROR) {
toast = Toast(ToastType.ERROR.name.toLowerCase(), table)
toast = Toast(ToastType.ERROR.name.lowercase(Locale.getDefault()), table)
}

toastManager.show(toast)
toastManager.toFront()
}

private fun newTable(text: String): VisTable {
Expand Down