Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

savio

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

savio

  • 0.1.8
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

| SavIO

Gem Version

What is it?

SavIO is an input/output library created to be used with Ruby2D. It adds multiple ways for the user to interact with your application, including :

  • Sliders
  • Buttons
  • Text Input
  • Color Picker (Work In Progress)

How to install?

Easy! do:

gem install savio

then in your program do:

require "savio"

How do they work?

Good question! Part of the goal when developing SavIO was to make it as intuitive and simple as possible, while also being highly versatile, powerful, and customizable.

| ALL OBJECTS

All SavIO objects inherit these basic properties.
You can access an array of all SavIO Objects by using Savio.elements
Example:
Savio.elements.each do |element|
    element.x += 1 #Moves all elements over by 1 pixel
end
SavIO Commands:
Savio.hide         #This will hide all elements
Savio.unhide       #This will bring them all back
Savio.stop         #This stops the mouse and keyboard event listeners
Savio.listen       #Starts the mouse and keyboard event listeners
Savio.listening    #returns true or false if its listening or not

Creation:

myAwesomeOBJECT = OBJECTNAME.new(params)

Params:

all SavIO object's parameters are optional, if it is not defined then it will use the default.

VariableDescriptionDefault
xThe x position0
yThe y Position0
zThe z Position1
sizeThe scaling value10
enabledIf the object can be interacted with by the usertrue
displayNameThe name of the object""
draggingEnabledIf the object itself can be moved around the windowfalse
dragType"move" or "duplicate" If draggingEnabled is true, this is what happens when it drags"move"
shownIf the object is shown or nottrue

Example:

myAwesomeOBJECT = OBJECTNAME.new(x: 100, y: 30, z:2, size: 13, displayName: "Swag")

Methods:


MethodDescription
.remove()removes the object from the screen
.add()adds the object back to the screen
.rebuild()rebuilds the object
.context()returns a hash with all the variables that make the object

| Sliders:

On top of all the basic parameters and methods a Slider can also use these:

Params:

VariableDescriptionDefault
lengthHow long the slider is100
minThe minimum value of the slider0
maxThe maximum value of the slider100
valueThe value of the sliderRandom between min and max
style'knob' or 'fill' changes the style the slider is shown with'knob'
showValueIf the value label should be showntrue
labelColorThe color of the labels'#F5F5F5'
sliderColorColor of the slider line'#757575'
knobColorColor of the sliders knob'#5BB36A'

Example:

slippyTheSlider = Slider.new(x: 830, y: 40, length: 220, draggingEnabled: true, dragType: "duplicate")

Methods:


MethodDescription
.moveKnob(x)Moves the knob to that x pixel location on the screen and finds and sets equivalent value for the slider
.setValue(value)Sets the sliders value to that value and moves the knob there (same as .value=)
.value = valueSets the sliders value to that value and moves the knob there (same as .setValue)
.onChangeCalls the given proc any time the sliders value is updated(see basic usage)

Basic Usage:

if slippyTheSlider.value == 69
    puts "nice"
end

slippyTheSlider.onChange do
  puts "Value Changed! new value is: " + slippyTheSlider.value.to_s
end

| Buttons:

On top of all the basic parameters and methods a Button can also use these:

Params:

VariableDescriptionDefault
selectedWhether the button is selected or notfalse
typeWhether the button will act normally('toggle') or instantly deselect itself('clicker')'toggle'
style'box' or 'badge'. Determines the style the button should be rendered with'badge'
lengthOnly used for the 'box' style. Determines the length of the button@size * 10
heightOnly used for the 'box' style. Determines the height of the button@size * 1.2
cooldownTimeTime needed to wait in seconds until the button may be clicked again0.0
buttonManagerThe manager that controls this buttonnil
enforceManagerWhen a manager is defined, whether the manager should force this button to follow its ruletrue
baseColorColor shown when the button is deselected'#F5F5F5'
selectedColorColor shown when the button is selected'#00B3EC'
labelColorColor of the buttons displayName label'#F5F5F5'

Example:

clickyBob = Button.new(
  x: 830, y: 90,
  displayName: "Enable Bob?",
  selectedColor: "purple",
  type : 'clicker'
)

anotherButton = Button.new(
  x: 830, y: 150,
  displayName: "Enable flux capacitors?",
)

Methods:


MethodDescription
.select(enforce)Selects the button. if left empty enforce will be the buttons @enforceManager state. when true the manager will enforce its rule on the button. when false, the button will perform as if it were not controlled.
.deselect(enforce)Deselects the button. enforce works the same as .select() (see above)
.toggle(enforce)Toggles the buttons Selection state. enforce works the same as .select() (see above)
.selected = boolSelects or deselects the button whether given true or false
.timeLastClickedreturns the unix time of the last click
.onClickTakes in a proc that will be ran every time the button gets selected (See example and basic usage)

Basic Usage:

clickyBob.onClick do
    puts "Bob is now enabled! Hi Bob!"
end

if anotherButton.selected == true do
  puts "Flux capacitors now enabled"
end

| ButtonManager:

Now I'm sure after reading how a button works you're saying, "What in the hell is a manager?"

Let me explain, it's very simple.

A ButtonManager is a simple and easy way to manage a group of multiple buttons. More specifically, it controls the state of all the buttons in its group depending on the state of all the other buttons in its group.

This is not considered a standard SavIO Object and does not inherit the typical parameters and methods.

Creation:

theSwagMaster = ButtonManager.new(type: "checkbox")

Params:

ParamDescriptionDefault
typeeither "radio" or "checkbox" Decides how the manager should control its buttons"radio"

Methods:


MethodDescription
.addButton(button)Adds the button to the group of buttons controlled by the manager. This is done automatically when a buttons @buttonManager is set to the manager. If called this way however, it will also automatically set the buttons @buttonManager to this manager, so they will always be linked.
.removeButton(button, overwrite)Removes the button from the group of buttons controlled by the manager. This is done automatically when a buttons @buttonManager is changed or removed. overwrite is not required and is automatically set to true. When true, this will overwrite the button's @buttonManager and set it to nil. When false it will not overwrite the buttons @buttonManager. It is highly recommended not to change this since it will desynchronize the button and manager and cause issues. It is used internally to prevent recursion when removed the manager from the button rather than from the manager
.toggle(button)Toggles the button according to the rule of the manager. This is done automatically by the button when button.toggle() is called and this manager is used. This is true also for .select() and .deselect().
.select(button)Selects the button according to the rule of the manager.
.deselect(button)Deselects the button according to the rule of the manager

Variables :

VariableDescriptionType
buttonsan array of all the buttons that are controlled by this managerarray
selectedan array of all the buttons that are currently selected and in control of this managerarray

Basic Usage:

theSwagMaster.selected.each do |button|
    puts button.to_s + " Is currently selected!"
end

--

if theSwagMaster.selected.include?(button)
    puts "This button is currently selected!"
end

| InputBox:

On top of all the basic parameters and methods an InputBox can also use these:

Params:

VariableDescriptionDefault
selectedWhether it is currently focusedfalse
valueThe current text input in the field@displayName
displayNameThe value shown in the text field when nothing is in it. AKA the default value. if a value was specified, this will be overwritten with it.@value or "Default"
lengthThe length of the text box@size * 10
widthThe width of the text box@size * 1.2
colorThe color of the box when not focused'#F5F5F5'
activeColorThe color of the box when focused'#5BB36A'
activeTextColorThe color of the text when focused'#F5F5F5'
inactiveTextColorThe color of the text when not focused'#757575'

Example:

askMeAnything = InputBox.new(
  x: 830, y: 180, size: 30,
  activeColor: 'purple',
  displayName: "What would you like to ask?"
)

Methods:


MethodDescription
.addKey(key)Simulates a key input of given key
.updateDisplay()Adds the line follower marker to the text box
.select()Focuses the text box and lets you type in it
.deselect()Loses focus of the text box and finalizes value
.toggle()Toggles the selection value of the text box
.selected=(bool)Selects or deselects the text box based on the bool

Basic Usage:

if askMeAnything.value == "Favorite Color?"
    puts "Purple"
end

| ColorSlider:

These technically work but I'm not done with them so for now I wont bother with documentation.

FAQs

Package last updated on 08 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc