Giter Site home page Giter Site logo

raspberry's Introduction

Raspberry

Raspberry is an easy way to quickly make menus for your next Console Application in c#.

Getting Started

Installation

To download Raspberry, navigate to the NuGet package manager in Visual Studios and search for RaspberryMenus. Click on the one by ChobbyCode, and hit install.

Creating

To create a menu in Raspberry, simply create an instance of the Menu class:

// You must give it the name of the menu

Menu menu = new Menu("PutTheNameOfTheMenuHere");

To create an option to add to your menu, you can create a menu option:

Options should be provided with a name, description and a menu that they will open.

// Options require a name, description and an already existing menu to open.

MenuOption newOption = new MenuOption("OptionName", "OptionDescription", MenuTheOptionWillOpen);

To add an option to a menu:

// To add it to a menu, type the name of the menu and say addOption and pass in your option.

menu.AddOption(newOption);

Raspberry also needs to be provided a default menu, and told when to start:

// Just pass in an already existing menu
Rasp.SetDefaultMenu(defaultMenu);
Rasp.StartRaspberry();

Below is a quick demo, that allows you to move between two different menus.

using Raspberry;
using Raspberry.Menus;

namespace Demo
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Menu menu = new Menu("main"); // main menu
            Menu sec = new Menu("second"); // second menu

            // Create buttons for main menu
            MenuOption openSec = new MenuOption("second", "Open the second menu", sec);
            menu.AddOption(openSec);

            // Create buttons for second menu
            MenuOption closeSec = new MenuOption("closeSec", "Close the second menu", menu);
            sec.AddOption(closeSec);

            // Start the menu
            Rasp.SetDefaultMenu(menu);
            Rasp.StartRaspberry();
        }
    }
}

Custom Actions

Now, just having menus on your app is no good. You need functionality. Luckily Raspberry has an easy way to add functionality to an option.

Instead of creating a MenuOption, create a MenuAction. Menu actions have event handlers which are called when the window is opened.

Below is a modified version of the first program to have a MenuAction instead of an MenuOption.

MenuActions work the same as MenuOptions but require event handlers instead.

Menu menu = new Menu("main"); // main menu
Menu actionMenu = new Menu("Action Menu"); // main menu

// Create buttons for main menu
MenuOption openSec = new MenuOption("second", "Open the second menu", actionMenu);
menu.AddOption(openSec);

// Create buttons for second menu
MenuAction action = new MenuAction("Action", "Run An Action", actionMenu);
actionMenu.AddOption(action);

// When the event handler is called we run the function
action.onOpen += ActionRunned;

// Start the menu
Rasp.SetDefaultMenu(menu);
Rasp.StartRaspberry();

action.onOpen calls a function called ActionRunned. We can create this function as below.

public static void ActionRunned (object sender, EventArgs e)
{
    Console.WriteLine("Action Run");
    Console.ReadLine();
}

In summary, we swapped the MenuOption out for a MenuAction and created a function for it to call when ran.

raspberry's People

Contributors

chobbycode avatar

Watchers

 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.