Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to change subcircuit buttons #100

Merged
merged 1 commit into from
Sep 30, 2023

Conversation

malmeloo
Copy link
Contributor

This PR adds support for adding, removing and changing subcircuit buttons. An array of "Button" objects can be passed as an option to the constructor of a Circuit and will be applied to all subcircuit pop-ups. A button object currently looks like this:

{
    // unique button ID. Setting this to an existing ID overrides a previous button with the same ID.
    id: string,
    // (optional, default = false) Hides the button if `true`. Allows hiding existing buttons together with `id`.
    hidden: boolean,

    // The following two options are only relevant if the button is not hidden

    // The text to display inside the button
    buttonText: string,
    // function taking the circuit, model and paper objects of the subcircuit
    callback: ({circuit, model, paper}) => void
}

The current zoom in/out buttons are defined as defaults, so they will still be there if the new option is not specified.

Examples

Hiding existing buttons:

const buttons = [
    {
        id: "zoomIn",
        hidden: true
    },
    {
        id: "zoomOut",
        hidden: true
    }
]

const circuit = new digitaljs.Circuit(input, {subcircuitButtons: buttons});

Adding a new button:

const buttons = [
    {
        id: "magic",
        hidden: false,  // Optional!
        buttonText: "Do Magic",
        callback: ({circuit, model, paper}) => {
            console.log(model.get("label"));
        }
    }
]

const circuit = new digitaljs.Circuit(input, {subcircuitButtons: buttons});

Closes #99.

@tilk tilk merged commit a541f0f into tilk:master Sep 30, 2023
3 checks passed
@malmeloo malmeloo deleted the add-subcircuit-buttons branch January 10, 2024 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow customization of subcircuit buttons
2 participants