MVV90 / Lovely-Toasts

Lövely Toasts: toasts for Löve2D

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lövely Toasts: toasts for Löve2D

Usage

Step 1: Place the "lovelyToasts.lua" library somewhere in your source folder (e.g. "/lib/soupy.lua")

Step 2: Add a variable to require the library in your main.lua file:

lovelyToasts = require("lib.lovelyToasts")

Step 3: Call lovelyToast's draw and update functions

function love.update(dt)
  lovelyToasts.update(dt)
end

function love.draw()
  lovelyToasts.draw()
end

Step 4: Show a toast message!

lovelyToasts.show("This is a Lövely toast :)")

For best looking toasts, set t.window.msaa in your conf.lua to 16

Customization

Other than the toast message you can also pass a duration and position

lovelyToasts.show("Lövely toast :)", 2, "top")

This will create a toast messsage at the top of the screen that appears for 2 seconds. Other options for the position are "middle", to put the toast in the center of the screen, "bottom", the default value, or a number for the Y position.

Styling

Various attributes of the toast message can be changed by changing the values in lovelyToasts.style

  • lovelyToasts.style.font The font to use for the toast message
  • lovelyToasts.style.textColor The color of the text
  • lovelyToasts.style.backgroundColor The color of the toast
  • lovelyToasts.style.paddingLR Left and right padding in the toast
  • lovelyToasts.style.paddingTB Top and bottom padding in the toast

Other options

  • lovelyToasts.options.tapToDismiss (set to false by default)
    Allows user to tap or click on the toast message to dismiss it
  • lovelyToasts.options.queueEnabled (set to false by default)
    When set to true the toasts don't replace, but enter a queue so you can queue multiple toasts in a row
  • lovelyToasts.options.animationDuration (set to 0.3 by default)
    Animation duration for appear and disappear animation

In order for lovelyToasts.options.tapToDismiss to work you need to implement Love's mousereleased for mouse and/or touchreleased for touch screens such a mobile devices.

function love.mousereleased(x, y, button)
  lovelyToasts.mousereleased(x, y, button)
end

function love.touchreleased(id, x, y, dx, dy, pressure)
  lovelyToasts.touchreleased(id, x, y, dx, dy, pressure)
end

License

MIT

About

Lövely Toasts: toasts for Löve2D

License:MIT License


Languages

Language:Lua 100.0%