Git Product home page Git Product logo

regorxxx / menu-framework-smp Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 0.0 7.48 MB

A helper script for Spider Monkey Panel which allows to easily create customizable menus on demand which can be easily refactored, moved or edited without working with static ids. A lifesaver.

Home Page: https://regorxxx.github.io/foobar2000-Framework-SMP.github.io/scripts/menu-framework-smp/

License: GNU Affero General Public License v3.0

JavaScript 100.00%
foobar2000 foobar2000-component foobar2000-smp-script spidermonkey-engine foobar2000-smp-framework

menu-framework-smp's Introduction

Menu-Framework-SMP

version CodeFactor CodacyBadge GitHub
A helper script for Spider Monkey Panel and foobar2000 which allows to easily create customizable menus on demand which can be easily refactored, moved or edited without working with static ids. A lifesaver.

The problem with current SMP menus

Menus are usually coded at multiple places which must be linked by ID, storing and sharing the different variables for menus and submenus when you have multiple objects using them, etc. It leads to 2 clear problems: non readability and maintenance nightmare.

carbon(1) carbon(2)

Using this framework it would translate into this:

carbon(3)

Features

  • Creates menus on demand on panels without needing to create specific methods for every script, calculate IDs, etc.
  • Menus are pushed to a list and created automatically on demand, linking the entries to their idx without needing a 'switch' block or leaving holes to ensure idx get enough numbers to expand the script.
  • The main utility of this helper is greatly reducing coding for simple menus and having both, the menu logic creation and the menus' functions on the same place. Creation order is done following entry/menus addition.
  • Can concatenate multiple menus on btn_up().
  • Full support for Context and Main menu managers.
  • Coverage of all native SMP features, flags, checks, etc.

Usage

First create the menu object. That's the main one and also includes a 'main menu' to append items to it:

const menu = new _menu();
menu.newEntry({menu, entryText: 'hello', func: () => {console.log('hello')}}); // Shorthand notation
menu.newEntry({entryText: 'hello2', func: () => {console.log('hello2')}}); // Or omit the menu, to append directly to main one
menu.newEntry({entryText: 'sep'}); // You can also add a separator

Then, you may want to create sub-menus linked to it. To do that, just create a new menu entry within the object:

const subMenu = menu.newMenu('This is a submenu'); // It will be added just after the last declared entry!
menu.newEntry({menuName: subMenu, entryText: 'This is my func', func: yourFunc);

Sub-menus can also be dynamically created:

var bSubMenu = true;
const funct = () => {return (bSubMenu) ? 'SubMenu 1' : 'SubMenu 2';};
menu.newMenu(funct);
menu.newEntry({menuName: funct, entryText: 'Change SubMenu', func: () => {bSubMenu = !bSubMenu}});
menu.newEntry({menuName: funct, entryText:'Hola 3', func: () => {console.log('Hola3')}, flags: () => {return (bSubMenu) ? MF_STRING : MF_GRAYED}});

Finally, lets call it with a callback:

function on_mouse_rbtn_up(x, y) {return menu.btn_up(x, y);}

Or an event listener:

addEventListener('on_mouse_rbtn_up', menu.btn_up);

menu_framework_01

There are more usage examples on the 'examples' folder and full documentation on the header of 'menu_xxx.js'.

Other implementations

  1. Playlist-Tools-SMP: Different tools for foobar2000. The dynamic configurable menu is built using this.
  2. Playlist-Manager-SMP: A playlist manager for foobar2000. The static menus use this.

Animation9

Installation

Since the framework only requires 1 file, i.e. the main one, you can simply include it along any other script where you will use the menu.

carbon(5)

menu-framework-smp's People

Contributors

regorxxx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.