Putting together a global `set` method for defaults
parent
50c4da8e1a
commit
10890be8a1
|
|
@ -6,12 +6,28 @@ module Squib
|
||||||
# Setting a hint to nil or to :off will disable hints. @see samples/text.rb
|
# Setting a hint to nil or to :off will disable hints. @see samples/text.rb
|
||||||
#
|
#
|
||||||
# @param [Color] text the color of the text hint. To turn off use nil or :off. @see API.md
|
# @param [Color] text the color of the text hint. To turn off use nil or :off. @see API.md
|
||||||
# @return nil
|
# @return [nil] Returns nothing
|
||||||
# @api public
|
# @api public
|
||||||
def hint(text: nil)
|
def hint(text: nil)
|
||||||
text = nil if text == :off
|
text = nil if text == :off
|
||||||
@text_hint = text
|
@text_hint = text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Sets various defaults for this deck. Defaults can be overriden by the commands themselves
|
||||||
|
# @example
|
||||||
|
# set font: 'Arial 26'
|
||||||
|
# text 'blah' # in Arial 26
|
||||||
|
# text 'blah24', font: 'Arial 24' # in Arial 24
|
||||||
|
# set font: :default # Back to Squib-wide default
|
||||||
|
#
|
||||||
|
# @param opts: the hash of options.
|
||||||
|
# @option font: the font string to set as default. Can also be set to `:default` to use the Squib-wide default.
|
||||||
|
# @return [nil] Returns nothing
|
||||||
|
# @api public
|
||||||
|
def set(opts = {})
|
||||||
|
opts = needs(opts, [:font])
|
||||||
|
@font = opts[:font]
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,6 @@
|
||||||
module Squib
|
module Squib
|
||||||
class Deck
|
class Deck
|
||||||
|
|
||||||
# @api private todo
|
|
||||||
def font(type: 'Arial', size: 12, **options)
|
|
||||||
raise 'Not implemented!'
|
|
||||||
end
|
|
||||||
|
|
||||||
# @api private todo
|
|
||||||
def set_font(type: 'Arial', size: 12, **options)
|
|
||||||
raise 'Not implemented!'
|
|
||||||
end
|
|
||||||
|
|
||||||
# Renders a string at a given location, width, alignment, font, etc.
|
# Renders a string at a given location, width, alignment, font, etc.
|
||||||
# Unix-like newlines are interpreted even on Windows.
|
# Unix-like newlines are interpreted even on Windows.
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ module Squib
|
||||||
:fill_color => '#0000',
|
:fill_color => '#0000',
|
||||||
:stroke_color => :black,
|
:stroke_color => :black,
|
||||||
:stroke_width => 2.0,
|
:stroke_width => 2.0,
|
||||||
:font => 'Arial, Sans 36',
|
:font => :use_set,
|
||||||
:sheet => 0,
|
:sheet => 0,
|
||||||
:x => 0,
|
:x => 0,
|
||||||
:y => 0,
|
:y => 0,
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ module Squib
|
||||||
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', &block)
|
||||||
@width=width; @height=height
|
@width=width; @height=height
|
||||||
@dpi = dpi
|
@dpi = dpi
|
||||||
@font = 'Sans 36'
|
@font = Squib::SYSTEM_DEFAULTS[:font]
|
||||||
@cards = []
|
@cards = []
|
||||||
cards.times{ @cards << Squib::Card.new(self, width, height) }
|
cards.times{ @cards << Squib::Card.new(self, width, height) }
|
||||||
load_config(config)
|
load_config(config)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
|
||||||
'level' => [1,2,3]}
|
'level' => [1,2,3]}
|
||||||
|
|
||||||
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
puts background color: :white
|
background color: :white
|
||||||
rect x: 38, y: 38, width: 750, height: 1050, radius: 38
|
rect x: 38, y: 38, width: 750, height: 1050, radius: 38
|
||||||
rect x: 75, y: 75, width: 128, height: 128, radius: 25
|
rect x: 75, y: 75, width: 128, height: 128, radius: 25
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
require 'squib'
|
||||||
|
|
||||||
|
describe Squib::Deck, '#text' do
|
||||||
|
|
||||||
|
context "when working with fonts" do
|
||||||
|
it"should use the default font when #text and #set_font don't specify" do
|
||||||
|
card = instance_double(Squib::Card)
|
||||||
|
expect(card).to receive(:text).with('a', Squib::SYSTEM_DEFAULTS[:font], anything, anything, anything, anything).once
|
||||||
|
Squib::Deck.new do
|
||||||
|
@cards = [card]
|
||||||
|
text str: 'a'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should use the #set_font when #text doesn't specify" do
|
||||||
|
card = instance_double(Squib::Card)
|
||||||
|
expect(card).to receive(:text).with('a', 'Times New Roman 16', anything, anything, anything, anything).once
|
||||||
|
Squib::Deck.new do
|
||||||
|
@cards = [card]
|
||||||
|
set font: 'Times New Roman 16'
|
||||||
|
text str: 'a'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should use the specified font no matter what" do
|
||||||
|
card = instance_double(Squib::Card)
|
||||||
|
expect(card).to receive(:text).with('a', 'Arial 18', anything, anything, anything, anything).once
|
||||||
|
Squib::Deck.new do
|
||||||
|
@cards = [card]
|
||||||
|
set font: 'Times New Roman 16'
|
||||||
|
text str: 'a', font: 'Arial 18'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue