Widgets
Every Widget extends an internal Widget class for efficiency reasons.
They have to be added to the BeastyWorld instance to be recognized and
rendered. This can be done either by adding them directly or through a
BeastySurface instance. In general surfaces are only really needed if
you want to have multiple pages and switch between them. Widgets with
text mostly have two ways to be created, either by the text and the
textsize or the text and the Widgetsize. Depending on which constructor
was chosen results can differ. In general the text with the textsize is a
little more accurate, but Parameters can be overwritten and updated
afterwords anyway.
The supported Widgets at the moment are:
- Button
- Checkbox
- Label
- Inputfield
- BB_Image
Widgets that are currently in Development are:
- BB_Table
- Dropdownlist
- Coordinatesystem
- Slider
- Radiobutton
Depending on which Widget is used they also differ how they react to
events. For example a Label does not react to hover over events or
hotkey events at all and because of that it also has no tooltip creation
available. The Button Widget can differentiate between Leftclick,
Rightclick and Middleclick on the mouse whereas other widgets just
trigger on all of the keys. Features of Widgets can also be used without
the instancing of the BeastyWorld class at all. Not using the it will
prevent BeastyButtons from changing all the environment - like Sketch
name and Sketch symbol and it will also prevent BeastyButtons from
automatically running in the Sketch. One usefull example would be the
usage of the cropImage() method of the BB_Image. Unlike the PImage.get()
function of Processing, not selected pixels are not only set to
transparent, but completely cut off which will result in a completely
new PImage object that you can return and work with, without the need to
crop it in another software first. Of course unlike the PImage.get()
function this is a non-reversable process. In general the order of
operations for Widgets is first to set the size and after that set the
position. This is important! Otherwise some Widgets like BB_Image will
not render at all!
1
2
3
4
5
6
7
8
PImage src;
BB_Image img;
void setup(){
src = loadImage(sourcepath);
img = new BB_Image(this, src);
img.cropImage(edge, pixelamount);
src = img.getImage();
}
Widgetmodes
In BeastyButtons there are two Modes to handle added Widgets that are
used internally and which one is used depends on the added objects.
Following Modes exist:
When the first added object was a BeastySurface object then all
Widgets that were added afterwords without a surface will be ignored.
The same applies the other way around. The intended use when using a
surfaces is to first add all needed widgets to one surface and after
that to add the whole surface to the BeastyWorld object. Some actions
like switching between surfaces are only available with surfaces because
with WidgetMode there is obviously no surface to switch to.
NOTE: surfaces are NOT related to PSurfaces in Processing. BeastyButtons
uses only the default PSurface for rendering and does not support
multiple PSurfaces.
Input Handlers
Input handlers are static members of the BeastyWorld class and handle
the interaction with the widgets. Any handler can be registered and
unregistered at anytime.
The handlers that BeastyButtons provides are:
- mouse(registered by default)
- hotkey
- tabswitch
All handlers can be enabled at once, however it is not recommended, because this will often cause confusion of the user.
Import/Export
Layouts can be exported to a .beasty file or imported from a .beasty file, which uses the XML syntax. It is possible to combine multiple imports, when they were exported in the same WidgetMode and Sketch-Resolution. When you do an export, this will export the Layout at the given time, so when it changes afterwords this will not be exported. It is recommended to export after the GUI is completely created and before runtime, which means most of time at the end of the setup() function in Processing. When exporting there are also certain dependencies that are exported too. These may be extern fonts, images or even functions that need to be defined in the Processing Sketch. You can ignore dependencies when importing with the seconds Parameter by setting it to false. This will load everything with default backgrounds and fonts. However keep in mind that BB_Image Widgets will not be imported at all since for them a given image is necessary. Of course it is also possible to combine a normal Layout import with a Preset. When exporting a Layout there are printouts that can be defined in the world container. These will be printed to the console when the Layout is imported and are useful to describe the Layout as well as to give some information about given IDs of Widgets that the Programmer might need a reference to because he needs to add extra functionality.
Logging
The automatic logging can be enabled from the BeastyWorld instance. This will log from the moment at that it is enabled. Logging is only available for the Mouse Handler and Hotkey Handler at the moment. Whether a Widget is taken in account or not when logging depends on if it is active or not. A new Logfile is created automatically. If the same Logfile already exists then the new log will be appended to that file.
Alignment
BeastyButtons provides an AlignmentHelper class which can be used to align Widgets quickly without the need of calculating positions. The AlignmentHelper provides horizontal, vertical and circle alignment. Since Processing does not allow passing an unlimited amount of variables into a method, it takes in a widgetlist - which can be either the widgetlist from BeastyWorld or from a BeastySurface - and changes the posititions of the Widgets in it.
Presets
BeastyButtons comes with predefined presets that can be imported just
like any import file and used as a starter point to create a new
Layout. The presets are accessible through the Info class, just like the
Logo, version etc. Of course nobody is bound to these Presets and
everyone can create their own costum Presets.
The general naming convention is :
1
Preset_(xresolution)x(yresolution)_widgetmode(surface amount)_name.beasty
so for example a file that imports 4 buttons in a vertical bar on 2 surfaces in SurfaceMode and at a 1280x720 sketch might be named like this:
1
Preset_1280x720_2surface_4leftbuttonbar.beasty
List of currently existing internal Presets:
- Preset_640x480_2surface_3topbuttonbar
- Preset_800x480_2surface_3topbuttonbar
- Preset_800x600_2surface_3topbuttonbar
- Preset_1280x720_2surface_3topbuttonbar
- Preset_1920x1080_2surface_3topbuttonbar
- Preset_3840x2160_2surface_3topbuttonbar
- Preset_640x480_2surface_4topbuttonbar
- Preset_800x480_2surface_4topbuttonbar
- Preset_800x600_2surface_4topbuttonbar
- Preset_1280x720_2surface_4topbuttonbar
- Preset_1920x1080_2surface_4topbuttonbar
- Preset_3840x2160_2surface_4topbuttonbar
- Preset_640x480_2surface_5buttonpiechart
- Preset_800x480_2surface_5buttonpiechart
- Preset_800x600_2surface_5buttonpiechart
- Preset_1280x720_2surface_5buttonpiechart
- Preset_1920x1080_2surface_5buttonpiechart
- Preset_3840x2160_2surface_5buttonpiechart
- Preset_640x480_2surface_6buttonpiechart
- Preset_800x480_2surface_6buttonpiechart
- Preset_800x600_2surface_6buttonpiechart
- Preset_1280x720_2surface_6buttonpiechart
- Preset_1920x1080_2surface_6buttonpiechart
- Preset_3840x2160_2surface_6buttonpiechart
Layer System
Each Widget is assigned to a specific Layer which determines the render order. The same render order also apllies for the render order of the tooltips. It is also possible to activate/deactivate or hide/unhide all Widgets on the same Layer at once when they are in the same container.
ID and Sourcepath
Each Widget and each Surface is assigned or to an ID and a sourcepath. The sourcepath changes if a Widget is added to or removed from a surface or if a surface is added to the world. The IDs are automatically generated to be individual, however they can be overridden. This is useful for marking a specific widget you need to get a reference later on or from an import file. To get a reference there are the getWidgetbyID(String id), getWidgetbySourcePath(String sourcepath) and getSurfacebyID(String id), getSurfacebySourcePath(String sourcepath) methods. Be aware that they search for the first available widget that matches so all other widgets that might have the same id or sourcepath will be ignored.
BB_Color
BB_Color is the Color Datatype of BeastyButtons. It is used in a static context and allows the use of HTML color codes inside of Beastybuttons and can also be used indipendent from the Library. It is just another alternative to setting the color via RGB or HSV.
