• Stars
    star
    382
  • Rank 112,241 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 5 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A highly customizable radial menu that's very easy to setup.

Radial Menu

A highly customizable radial menu that's very easy to setup.

screenshot

See it live here
Alternative link

About

A radial menu, also known as pie menu, is a circular context menu where selection depends on direction. It is a graphical control element. [wikipedia]

Create a customized and beautiful radial menu for your web app that can be used as a standalone menu or override the default context menu. On a desktop or notebook click the second button of the mouse (context menu). On a smartphone or tablet, click the screen and hold for few seconds and the menu will pop.

Work in progress. Writing the documentation and doing some tests.

Feel free to commit new styles and share them with the public.

Documentation

Let's create a new radial button so you can see how simple it is. You'll need to add the RadialMenu.js to your web app and then create a new menu. Let's look at the code:

<script type="module">
import RadialMenu from "./build/RadialMenu.min.js";

const radial = new RadialMenu();
</script>

Since the last PR you can now use import RadialMenu using the script as a module.

That's it. The library has some default buttons included as example so you can see how it works. Let's continue reading the documentation so we can learn how to create our very own radial menu with our very own buttons.

To create a Radial Menu in your web app you'll need to pass a configuration object to the constructor. By default a lot of values are already setted, but you can fiddle with every single one of them. Let's talk about each one.

const mySettings = {
	textColor: 'red', //define the color of the text on the buttons
	buttons: [
		{'text': '\uf053', 'action': ()=>{ history.go(-1) } }, //create a button that goes back on history
		{'text': '\uf054', 'action': ()=>{ history.go(1) } }, //create a button tha goes forward on history
	]
};

const radial = new RadialMenu(mySettings);

fontFamily : String
Name of the font to be used. On this example 'FontAwesome' is being used for the free icons. But you can use your own font.
Default: 'FontAwesome'

fontSize : Int
Size of the icons (text) used on the buttons.
Default: 14

innerCircle : Int
Inner circle of the radial menu. Use 0 (zero) if you don't want a hole in the menu.
Default: 50

outerCircle : Int
Outer circle of the radial menu. The outer circle and the inner circle will defined how thick is the menu.
Default: 100

innerCircle = 0, outerCircle = 100
fullCircle

innerCircle = 50, outerCircle = 100
perfuratedCircle

rotation : Int
This value rotate the whole "circle" of the menu, if you want to better "align" the button's divison. This value is in radians and always rotate the menu clock wise. Default: PI/2 (90ยบ)

Not rotated
default

Rotated
rotated

shadowBlur : Int
How blurred is the shadow.
Default: 10

shadowColor : Color (rgb, rgba, hex) or Gradient Object (read more below)
Shadow color.
Default: rgba(0,0,0,0.2) black with alpha

shadowOffsetX : Int
Horizontal displacement of the shadow.
Default: 3

shadowOffsetY : Int
Vertical displacement of the shadow.
Default: 3

buttonGap : Int
Gap between buttons. This value is in radians.
Default: 0

hoverBackgroundColor : Color (rgb, rgba, hex) or Gradient Object (read more below)
The background color when hover.
Default: null

hoverTextColor : Color (rgb, rgba, hex) or Gradient Object (read more below)
The text color when hover.
Default: null

hoverAction function(boolean:isHover):void
Is the function called when hover state change.
Default: none

You can edit every single button individually, or you can set values for all of them at once.

backgroundColor : Color (rgb, rgba, hex) or Gradient Object (read more below)
The background color of the button.
Default: #EEE gray

borderColor : Color (rgb, rgba, hex) or Gradient Object (read more below)
The border color of the button.
Default: #FFF white

textColor : Color (rgb, rgba, hex) or Gradient Object (read more below)
Color of the text inside the button.
Default: #000 black

textBorderColor : Color (rgb, rgba, hex) or Gradient Object (read more below)
Color of the contour of the text inside the button.
Default: 'transparent'

textShadowColor : Color (rgb, rgba, hex) or Gradient Object (read more below)
Color of the shadow of the text.
Default: 'transparent'

textShadowBlur : Int
How blurred is the shadow of the text.
Default: 0

textShadowOffsetX : Int
Horizontal displacement of the shadow of the text.
Default: 0

textShadowOffsetY : Int
Vertical displacement of the shadow of the text.
Default: 0

posX : Int
Horizontal position of the menu. This value is used only when the menu is fixed on the page.
Default: 0

posY : Int
Vertical position of the menu. This value is used only when the menu is fixed on the page.
Default: 0

isFixed : Boolean
This value determine if the menu will be fixed on the page. This is usefull in case you're making a web app that needs a menu that is always visible.
Default: False

zIndex : Int
This value determine the order the menu will be displayed on the page. Higher values means that it is in front of elements with lower values.
Default: 9999

buttons : Array (of buttons object)
You should pass an array with button objects. A button object is a simple object with only two attributes: text and action.

text is the icon that will be displayed. see the font-visualizer.html for the unicode of each icon '\uf000'

action is a function that will be called when the button is clicked.

Besides that, you can pass all those above metioned settings inside the button object, but this way, the settings will only apply to that particular button. Take a look on the example below. One button will have the default color (black) and the other one will have a red color for the text.

const ok  = function(){
	alert('ok');
}

const nok = function(){
	alert('not ok');
}

const myButtons = [
	{text: '\uf00c', action: ok},
	{text: '\uf001', action: nok, textColor: 'red'} //you can set values for the button individually
];

const radial = new RadialMenu({buttons: myButtons});

Gradient Object Every color setting could be a gradient. In order to create a gradient, you need to pass a generic object with a gradient type and some colors. Let's take a look at the example below:

const gradient = {gradient: 'radial', colors: {0: 'black', 1: 'white'} };

const menu = new RadialMenu({backgroundColor: gradient})

The index keys inside 'colors' will define where the color start and where it ends. 0 is the start, 1 is the end and everything in between is a step. You can add as many colors as you like, respecting these steps. Let's see how we add more colors on the example below:

const gradient = {gradient: 'radial', colors: {0: 'red', 0.25: 'green', 0.5: 'yellow', 0.75: 'blue', 1: 'orange'} };

const menu = new RadialMenu({backgroundColor: gradient})

That means that the gradient will start with red, 25% along the way it will change to green, 50% after it will become yellow, 75% blue and eventually it will end as orange. The steps indicates where the color change will happen (in percentage).

The gradient object can have one of this values: radial, linear1, linear2, linear3 and linear4. Let's look at them.

radial - from inside to outside
rotated

linear1 - top to bottom
linear1

linear2 - left to right
linear2

linear3 - top left to bottom right
linear3

linear4 - bottom left to top right
linear4

If you want a gradient from black to white set 0 as black and 1 as white, if you want a white to black gradient, invert the colors: set 0 to white and 1 to black.

You can check out you some styles I've created as examples here

Methods

The RadialMenu class also offers some auxiliary methods so you can use the menu as a stand alone menu (like a joypad for a web game).

show() Show the menu.

hide() Hide the menu.

setPos(x : int, y : int) Set the X and Y position of the menu.

addButtons(buttons : array of Buttons) Useful if you want to load the style from a json file and add the buttons later on. Example below:

const load = async function(){
	const request = await fetch('styles/orange.json');
	const data = await request.json();
	
	const menu = new RadialMenu(data);
	menu.addButtons([
		{text: '\uf000', action: ()=>{ /*your code here*/ } },
		{text: '\uf001', action: ()=>{ /*your code here*/ } },
	]);
}

load();

Buy me a coffee

Donations

More Repositories

1

isocity

A isometric city builder in JavaScript
JavaScript
2,812
star
2

invaderz

Space invaders, but the invaders evolve with genetic algorithm
JavaScript
705
star
3

imgToAscii

A JavaScript implementation of a image to Ascii code
JavaScript
376
star
4

aimAndShoot

A neuroevolution game experiment.
JavaScript
220
star
5

groupImg

A script in python to organize your images by similarity.
Python
211
star
6

hntitlenator

Test your HN title against a neural network
JavaScript
183
star
7

fos

Web Components to turn your web app into a fake operating system
JavaScript
175
star
8

dial

A Rotary Dial menu for input numbers
JavaScript
161
star
9

oldTerminal

an old terminal template for html pages
CSS
156
star
10

retroSynthwave

A retro synthwave "demo scene"
JavaScript
134
star
11

jokenpo

Can a neural network predict your next move on a game of rock, paper and scissor?
JavaScript
118
star
12

fingerPool

A pool game in JavaScript using my sphereCollision project
JavaScript
106
star
13

tileEditor

A 2D Tile Editor that runs on the browser.
JavaScript
103
star
14

budget

A simply budget app that predicts where the expenses are being made
JavaScript
103
star
15

ocr

Simple app to extract text from pictures using Tesseract
HTML
103
star
16

bangBang

Play BangBang against a Neural Network
JavaScript
99
star
17

photoEditor

A image editor in browser using JavaScript canvas
JavaScript
94
star
18

radio

A simple javascript web radio visualizer
JavaScript
92
star
19

randomFractal

Random fractal or the secret behind my tree
JavaScript
91
star
20

rpiapi

An API for your Raspberry Pi
Python
85
star
21

bruteforcetv

Let's brute force this hotel's tv.
73
star
22

perceptronCobol

A perceptron written in COBOL
COBOL
69
star
23

simpleWFC

A simplified version of the Wave Function Collapse algorithm
JavaScript
56
star
24

bangBangML

Watch a Neural Network learns to shoot a target
JavaScript
56
star
25

googol

Googol Game or "You should learn when to quit". A JavaScript game.
JavaScript
47
star
26

perceptron

The simplest Perceptron you'll ever see
JavaScript
45
star
27

myConsole

A JavaScript editor for your phone, in JavaScript
JavaScript
41
star
28

carGamePerceptron

A Neural Network experiment involving a JavaScript game.
JavaScript
31
star
29

3Dengine

A JavaScript WebGL 3D engine. From scratch.
JavaScript
28
star
30

deforestation

A machine learning exercise, using KNN to classify deforested areas
Python
27
star
31

scrap

Scrapping Facebook with JavaScript.
JavaScript
27
star
32

pixelRestorer

Using statistics to restore pixel art images.
HTML
26
star
33

paintDraw

A JavaScript paint and draw app.
JavaScript
24
star
34

digitRecognition

Implementation of a digit recognition using my Neural Network with the MNIST data set.
JavaScript
21
star
35

terrainGenerator

A 3D terrain generator from a height maps using Three.js
JavaScript
18
star
36

MLP

A multilayer perceptron in JavaScript
JavaScript
17
star
37

raspberryCar

A flask server to control a raspberry pi over the internet.
Python
15
star
38

genius

Genius game implemented using JavaScript and RadialMenu
JavaScript
14
star
39

rippleEffect

A JavaScript ripple effect implemented using canvas
JavaScript
14
star
40

faceRecognition

A face recognition in JavaScript using my neural network
JavaScript
13
star
41

towerDefense

A tower defense game written in vanilla JavaScript
JavaScript
13
star
42

gaia

An AI concept that can help the game designer create procedural quests.
JavaScript
11
star
43

create

A simple bash script to create progressive web apps (pwa).
Shell
11
star
44

imageCounter

A simple page view counter that store data as text and shows data as a PNG image
PHP
10
star
45

memes

A progressive web app with memes, videos and gifs, from reddit.
JavaScript
10
star
46

FOStutorial

A git repository to go along with a tutorial for using FOS to build a web app
HTML
9
star
47

pathfind

Using Breadth-First Search as a pathfinder algorithm, visualizing the final path.
JavaScript
9
star
48

audio2text

Converting audio files to text using Google Chrome's speech API.
JavaScript
9
star
49

plot

Plot equations using JavaScript canvas
HTML
8
star
50

monteCarlo

Finding Areas Using the Monte Carlo Method
JavaScript
8
star
51

splitDjangoModels

Split Django generated models into separated files, with proper names, classes and imports
Python
8
star
52

remember

Remember is a simple bash script that allow you to write "to do" lists and things you want to remember.
Shell
7
star
53

myRaycast

A JavaScript Ray Casting engine I'm working on
JavaScript
7
star
54

bridge

A JavaScript implementation of the bridge game.
JavaScript
7
star
55

sphereCollision

Javascript experiment with 2D physics
JavaScript
7
star
56

terms

Get related terms to a word.
JavaScript
6
star
57

syntax

A very simple JavaScript syntax highlighter
HTML
6
star
58

naiveCorners

A naive algorithm to identify corners on a image
Python
6
star
59

keypad2text

Convert text to keypad code and vice versa.
JavaScript
4
star
60

customFilter

A image editor that runs in the browser
JavaScript
4
star
61

fireEffect

A fire effect algorithm implemented using JavaScript canvas
JavaScript
4
star
62

mycanvas

A JavaScript Canvas application
HTML
3
star
63

scramble

A puzzle game in JavaScript
JavaScript
3
star
64

rpg2djavascriptgame

"Engine" for a 2D JavaScript rpg game
JavaScript
3
star
65

dtf

DTF - Duplicate Thumbnail Files - A method to identify duplicate files.
Python
3
star
66

goSpellcheck

A terrible spell checker in Go.
Go
2
star
67

montyhall

Monty Hall problem. An old code I wrote a long time ago.
HTML
2
star
68

AOSE

A simulation involving a criminal, a civilian, a police officer and a firefighter. My final project for the AOSE class.
JavaScript
2
star
69

BatalhaNaval

Jogo Java Batalha Naval
Java
2
star
70

compactImage

Trying to beat the PNG file format (Just for fun)
JavaScript
1
star
71

BeautyHair

BeautyHair is a multiplatform CLI software written in Java to manage beauty saloons.
Java
1
star
72

carGame

A simple JavaScript game
JavaScript
1
star
73

simpleCounter

A simple counter in vanilla JavaScript
JavaScript
1
star
74

victorqribeiro

1
star