Skip to content

The Helpful Macros

Emerald edited this page Oct 5, 2023 · 1 revision

Constraint

This simplifies the way to create a constraint for a layout!

A simple constraint looks like this:

constraint!(%20) // A Constraint that takes up 20 percent

Constraint Types

% A percentage of the screen

# An exact length

> A minimum value

< A maximum value

num ; num A ratio

Layout

This is a macro that will simplify the creation of your chunks!

Example:

layout![
   frame.size()
   (#3),
   (%100) => { #3, %50, %50 },
   (#3)
]

Ok, ok, this could be confusing. First, we must always provide a Rect that will be the size that we are splitting up.

Then, within the () we can define a constraint! You don't need to call the constraint! macro, but you will type it the same as it would look within that macro.

Next, we can either define the horizontal parts of the layout, using a =>, followed by your constraints within {}s Now that you mostly understand, I'll provide a few more examples before describing the end.

Examples

layout![
   frame.size()
   (#3),
   (%100) => { #3, %50, %50 },
   (#3)
]
layout![
   frame.size()
   (<50),
   (%100) => { #3, %50, %50 },
   (>3) => { #3, <5, >50 }
]
layout![
   frame.size()
   (22 ; 50) => { %15, #3, %25, %50 },
]

Warning, no promises any of these layouts will look good.

Clone this wiki locally