14 changed files with 175 additions and 8 deletions
@ -0,0 +1,16 @@ |
|||||||
|
.. :orphan: |
||||||
|
|
||||||
|
x |
||||||
|
default: ``0`` |
||||||
|
|
||||||
|
the x-coordinate to place, relative to the upper-left corner of the card and moving right as it increases. Supports :doc:`/units`. |
||||||
|
|
||||||
|
Also can be ``:center`` or ``:middle`` for half the width of the deck. |
||||||
|
|
||||||
|
|
||||||
|
y |
||||||
|
default: ``0`` |
||||||
|
|
||||||
|
the y-coordinate to place, relative to the upper-left corner of the card and moving downward as it increases. Supports :doc:`/units`. |
||||||
|
|
||||||
|
Also can be ``:center`` or ``:middle`` for half the height of the deck. |
||||||
@ -0,0 +1,35 @@ |
|||||||
|
module Squib |
||||||
|
module Args |
||||||
|
module XYWHShorthands |
||||||
|
|
||||||
|
def apply_x_shorthands(arg, deck_width) |
||||||
|
arg_s = arg.to_s |
||||||
|
case arg_s |
||||||
|
when 'middle' |
||||||
|
deck_width / 2.0 |
||||||
|
when 'center' |
||||||
|
deck_width / 2.0 |
||||||
|
when 'deck' |
||||||
|
deck_width |
||||||
|
else |
||||||
|
arg |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def apply_y_shorthands(arg, deck_height) |
||||||
|
arg_s = arg.to_s |
||||||
|
case arg_s |
||||||
|
when 'middle' |
||||||
|
deck_height / 2.0 |
||||||
|
when 'center' |
||||||
|
deck_height / 2.0 |
||||||
|
when 'deck' |
||||||
|
deck_height |
||||||
|
else |
||||||
|
arg |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
@ -0,0 +1,30 @@ |
|||||||
|
require_relative '../../lib/squib' |
||||||
|
|
||||||
|
# Lots of DSL methods have shorthands that are accepted for |
||||||
|
# x, y, width, and height parameters. |
||||||
|
Squib::Deck.new(width: '0.5in', height: '0.25in') do |
||||||
|
background color: :white |
||||||
|
|
||||||
|
text str: 'xymiddle', font: 'Sans Bold 3', hint: :red, |
||||||
|
x: 'middle', y: :middle |
||||||
|
|
||||||
|
# 'center' also works |
||||||
|
rect width: 30, height: 30, |
||||||
|
x: :center, y: 'center' |
||||||
|
|
||||||
|
# Layouts apply this too. |
||||||
|
use_layout file: 'shorthands.yml' |
||||||
|
rect layout: :example |
||||||
|
|
||||||
|
# The x and y coordinates can also be "centered", assuming the |
||||||
|
|
||||||
|
# HOWEVER! Shorthands don't combine in an "extends" situation, |
||||||
|
# e.g. this won't work: |
||||||
|
# parent: |
||||||
|
# x: middle |
||||||
|
# child: |
||||||
|
# extends: parent |
||||||
|
# x: += 0.5in |
||||||
|
|
||||||
|
save_png prefix: 'shorthand_' |
||||||
|
end |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
example: |
||||||
|
x: 0.15in |
||||||
|
y: middle |
||||||
|
stroke_color: blue |
||||||
|
width: 30 |
||||||
|
height: 30 |
||||||
|
|
||||||
Loading…
Reference in new issue