Implementing initial layout functionality

This commit is contained in:
Andy Meneely
2014-07-29 14:17:38 -04:00
parent 20bd850bb7
commit b0e65d3783
10 changed files with 99 additions and 9 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ module Squib
# @return [nil] Returns nil
# @api public
def png(opts = {})
opts = needs(opts, [:range, :files, :x, :y, :alpha])
opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout])
opts[:range].each do |i|
@cards[i].png(opts[:file][i], opts[:x], opts[:y], opts[:alpha])
end
@@ -37,7 +37,7 @@ module Squib
# @return [nil] Returns nil
# @api public
def svg(opts = {})
p = needs(opts,[:range, :files, :svgid, :x, :y, :width, :height])
p = needs(opts,[:range, :files, :svgid, :x, :y, :width, :height, :layout])
p[:range].each do |i|
@cards[i].svg(p[:file][i], p[:id], p[:x], p[:y], p[:width], p[:height])
end
+1 -1
View File
@@ -20,7 +20,7 @@ module Squib
# @api public
def rect(opts = {})
opts = needs(opts, [:range, :x, :y, :width, :height, :radius,
:fill_color, :stroke_color, :stroke_width])
:fill_color, :stroke_color, :stroke_width, :layout])
opts[:range].each do |i|
@cards[i].rect(opts[:x], opts[:y], opts[:width], opts[:height],
opts[:x_radius], opts[:y_radius],
+1 -1
View File
@@ -34,7 +34,7 @@ module Squib
# @api public
def text(opts = {})
opts = needs(opts, [:range, :str, :font, :x, :y, :width, :height, :text_color, :wrap,
:align, :justify, :valign, :ellipsize, :hint])
:align, :justify, :valign, :ellipsize, :hint, :layout])
opts[:str] = [opts[:str]] * @cards.size unless opts[:str].respond_to? :each
opts[:range].each do |i|
@cards[i].text(opts[:str][i], opts[:font], opts[:x], opts[:y], opts[:color], opts)
+2
View File
@@ -13,6 +13,8 @@ module Squib
:sheet => 0,
:x => 0,
:y => 0,
:x_radius => 0,
:y_radius => 0,
:align => :left,
:valign => :top,
:justify => false,
+9 -1
View File
@@ -45,13 +45,14 @@ module Squib
# @param config: [String] the file used for global settings of this deck
# @param block [Block] the main body of the script.
# @api public
def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', &block)
def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block)
@width=width; @height=height
@dpi = dpi
@font = Squib::SYSTEM_DEFAULTS[:default_font]
@cards = []
cards.times{ @cards << Squib::Card.new(self, width, height) }
load_config(config)
load_layout(layout)
if block_given?
instance_eval(&block)
end
@@ -81,6 +82,13 @@ module Squib
end
end
# Load the layout configuration file, if exists
# @api private
def load_layout(file)
return if file.nil?
@layout = YAML.load_file(file)
end
##################
### PUBLIC API ###
##################
+1
View File
@@ -4,6 +4,7 @@ module Squib
# :nodoc:
# @api private
def rect(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width)
width=@width if width==:native; height=@height if height==:native
cc = cairo_context
cc.rounded_rectangle(x, y, width, height, x_radius, y_radius)
cc.set_source_color(stroke_color)
+16
View File
@@ -7,6 +7,7 @@ module Squib
# @api private
def needs(opts, params)
opts = layoutify(opts) if params.include? :layout
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
opts = rangeify(opts) if params.include? :range
opts = fileify(opts) if params.include? :file
@@ -24,6 +25,21 @@ module Squib
end
module_function :needs
def layoutify(opts)
unless opts[:layout].nil?
entry = @layout[opts[:layout].to_s]
unless entry.nil?
%w(x y width height).each do |p|
opts[p.to_sym] ||= entry[p]
end
else
logger.warn "Layout entry #{opts[:layout]} does not exist."
end
end
opts
end
module_function :layoutify
# @api private
def formatify(opts)
opts[:format] = [opts[:format]].flatten