Giter Site home page Giter Site logo

lovely-toasts's Introduction

Lövely Toasts: toasts for Löve2D

Made and tested in Löve2D v11.3

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
  • lovelyToasts.canvasSize
    If you're using a rendering library such as TLfres to scale your game you might run into issues where LT doesn't renders toasts in the center of the screen, to fix this issue you just have to pass the canvas size you're rendering your game for to LT's canvasSize property.

Example:

local CANVAS_WIDTH = 1920
local CANVAS_HEIGHT = 1080

function love.load()
	--

	LovelyToasts.canvasSize = { CANVAS_WIDTH, CANVAS_HEIGHT }
end

function love.draw()
	tlfres.beginRendering(CANVAS_WIDTH, CANVAS_HEIGHT)
	love.graphics.setBackgroundColor(1, 1, 1)
	LovelyToasts.draw()
	tlfres.endRendering()
end

License

MIT

lovely-toasts's People

Contributors

loucee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lovely-toasts's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.