All Projects β†’ Lartu β†’ P5.clickable

Lartu / P5.clickable

Licence: mit
Event driven, easy-to-use button library for P5.js πŸ‘†

Programming Languages

javascript
184084 projects - #8 most used programming language
p5js
31 projects

Projects that are alternatives of or similar to P5.clickable

Scheme Lib
ιΈ­εΊ“ duck lib scheme for gui gles gl slib openal socket web mongodb box2d game glfw mysql libevent libuv uv json http client server android osx linux chezscheme scheme-lib
Stars: ✭ 406 (+515.15%)
Mutual labels:  library, gui
Imgui markdown
Markdown for Dear ImGui
Stars: ✭ 594 (+800%)
Mutual labels:  library, gui
Toastnotifications
Toast notifications for WPF allows you to create and display rich notifications in WPF applications. It's highly configurable with set of built-in options like positions, behaviours, themes and many others. It's extendable, it gives you possibility to create custom and interactive notifications in simply manner.
Stars: ✭ 507 (+668.18%)
Mutual labels:  gui, ui-components
Fannypack
[UNMAINTAINED] An accessible-focused, themeable, friendly React UI Kit.
Stars: ✭ 245 (+271.21%)
Mutual labels:  library, button
Fillingbutton
πŸ”₯Replace typical onLongClickListener with this library!
Stars: ✭ 31 (-53.03%)
Mutual labels:  library, button
Separateshapesview
Simple custom ViewGroup with two shapes inside and simple scale animation
Stars: ✭ 250 (+278.79%)
Mutual labels:  library, button
Esp Dash
A blazing fast library to create a functional dashboard for ESP8266 and ESP32
Stars: ✭ 548 (+730.3%)
Mutual labels:  library, button
Gwork
Skinnable GUI with useful widget collection. Fork of GWEN.
Stars: ✭ 179 (+171.21%)
Mutual labels:  library, gui
Scrollbooster
Enjoyable content drag-to-scroll library
Stars: ✭ 775 (+1074.24%)
Mutual labels:  library, ui-components
Awesome Ui Component Library
Curated list of framework component libraries for UI styles/toolkit
Stars: ✭ 702 (+963.64%)
Mutual labels:  library, ui-components
Material Backdrop
A simple solution for implementing Backdrop pattern for Android
Stars: ✭ 221 (+234.85%)
Mutual labels:  library, ui-components
Google Books Android Viewer
Android library to bridge between RecyclerView and sources like web page or database. Includes demonstrator (Google Books viewer)
Stars: ✭ 37 (-43.94%)
Mutual labels:  library, ui-components
Truly Ui
Truly-UI - Web Angular UI Components for Desktop Applications (Electron, NW, APP JS)
Stars: ✭ 195 (+195.45%)
Mutual labels:  library, ui-components
Vugu
Vugu: A modern UI library for Go+WebAssembly (experimental)
Stars: ✭ 4,251 (+6340.91%)
Mutual labels:  library, gui
Rpi Backlight
πŸ”† A Python module for controlling power and brightness of the official Raspberry Pi 7" touch display
Stars: ✭ 190 (+187.88%)
Mutual labels:  library, gui
Iconfontcppheaders
C, C++ headers and C# classes for icon fonts: Font Awesome, Fork Awesome, Material Design, Kenney game icons and Fontaudio
Stars: ✭ 509 (+671.21%)
Mutual labels:  library, gui
Bttn.css
Awesome buttons for awesome projects!
Stars: ✭ 2,004 (+2936.36%)
Mutual labels:  library, button
Gooi
LΓ–VE GUI Library
Stars: ✭ 168 (+154.55%)
Mutual labels:  library, gui
Python Progressbar
Progressbar 2 - A progress bar for Python 2 and Python 3 - "pip install progressbar2"
Stars: ✭ 682 (+933.33%)
Mutual labels:  library, gui
Hhcustomcorner
Awesome library to customize corners of UIView and UIButton. Now you can customize each corner differently
Stars: ✭ 36 (-45.45%)
Mutual labels:  library, button


Welcome! This is p5.clickable, a p5.js library that lets you create and customize buttons and assign event-based behaviours to them. With p5.clickable you can create buttons and define what happens when the user hovers over, clicks, releases or moves the cursor outside of them.

Can't wait? Check this live example to see some of the things this library can do. Its source code is available in the example folder of this repository.

⚠️ Attention Contributors! It seems that in one poorly checked pull request some of the newly contributes features were deleted. Sorry! I will add them again in the next release alongside all new features.

πŸ”­ Code Example

With p5.clickable you can get a button up and running with just a few lines of code. For example, to create a plain white button at (20, 20) that when pressed changes color and shows an alert message you do:

myButton = new Clickable();     //Create button
myButton.locate(20, 20);        //Position Button
myButton.onPress = function(){  //When myButton is pressed
  this.color = "#AAAAFF";       //Change button color
  alert("Yay!");                //Show an alert message
}

Easy as pie!

πŸ”¬ Documentation

Including the p5.clickable Library

To include the p5.clickable library into your p5.js project, copy the p5.clickable.js file into your project directory and then add the line

<script src="path/to/p5.clickable.js"></script>

to the HTML file that includes your p5.js script after the line that imports the p5 library, but before all of your personal code or the line that imports your personal code. Check the example project HTML file for more information.

Creating a Clickable

p5.clickable provides the Clickable class (a Clickable is just a button). To create a button just instantiate a new Clickable, like this:

myButton = new Clickable();

The starting position of a Clickable defaults to (0, 0) and its size to (100, 50).

You can also create it at a different location:

⚠️ Sorry, this isn't working at the moment. It will be re-added in the next release.

myButton = new Clickable(200,300);

Moving a Clickable

To move a Clickable you can change its x and y properties. You can also use this properties to read the current location of a Clickable.

myButton.x = 100;
myButton.y = 200;

You can also use the locate method to change the location of a Clickable.

myButton.locate(100, 200);

Resizing a Clickable

To resize a Clickable you can modify its width and height properties. You can also use this properties to read the current size of a Clickable.

myButton.width = 250;
myButton.height = 100;

You can also use the resize method to change the size of a Clickable.

myButton.resize(250, 100);

Altering the Appearance of a Clickable

Clickables contain properties that can be changed to alter their appearance:

myButton.color = "#FFFFFF";       //Background color of the clickable (hex number as a string)
myButton.cornerRadius = 10;       //Corner radius of the clickable (float)
myButton.strokeWeight = 2;        //Stroke width of the clickable (float)
myButton.stroke = "#000000";      //Border color of the clickable (hex number as a string)
myButton.text = "Press Me";       //Text of the clickable (string)
myButton.textColor = "#000000";   //Color of the text (hex number as a string)
myButton.textSize = 12;           //Size of the text (integer)
myButton.textFont = "sans-serif"; //Font of the text (string)
myButton.textScaled = false;       //Whether to scale the text with the clickable (boolean)

Displaying a Clickable

To display a Clickable, you have to call its draw method inside the draw function of your p5.js script.

function draw(){ // This is the p5.js draw function.
  //...
  myButton.draw(); // <- Draw the 'myButton' Clickable
  //...
}

This is very important! If you don't call this method your button will not be shown and it also won't respond to any events!

Clickable Events

The Clickable class provide four methods that are called when the user interacts with a Clickable: onOutside, onHover, onPress and onRelease.

onOutside is called whenever the cursor is not hovering over the Clickable.

myButton.onOutside = function(){
  console.log("Hey! Press me!");
}

onHover is called whenever the cursor is hovering over a Clickable, but it is not being pressed.

myButton.onHover = function(){
  console.log("The cursor is over me!");
}

onPress is called when the user presses the Clickable.

myButton.onPress = function(){
  console.log("I have been pressed!");
}

onRelease is called when the user clicks a Clickable and then releases the click while within the area of the Clickable.

myButton.onRelease = function(){
  console.log("I have been released!");
}

🍻 Contributing

If there's a missing feature you'd like to see on p5.clickable, feel free to write it and submit a pull request. Something broke? Please try to fix it! Also feel free to submit issues, bug reports and requests for future features.

πŸ“œ Licensing

The p5.clickable library is licensed under the MIT License. You can find a copy of the MIT License on this repository.

This repository also includes code from the p5.js library, that is licensed under the LGPL 2.1 license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].