diff options
| author | lstrzebinczyk <[email protected]> | 2017-03-29 21:28:14 +0200 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2017-04-02 12:22:49 -0400 |
| commit | 5cb0c0581b2ba9b9c436edb7b6699c2b44243e2f (patch) | |
| tree | 8f3308dc986139e0e4ed69d7e6c266afab8a4eaf /test | |
| parent | 02c1353d4fe6b4eef5c45d1ad45af53c782d2824 (diff) | |
| download | ruby2d-5cb0c0581b2ba9b9c436edb7b6699c2b44243e2f.tar.gz ruby2d-5cb0c0581b2ba9b9c436edb7b6699c2b44243e2f.zip | |
Implement Text#height and Text#width
Diffstat (limited to 'test')
| -rw-r--r-- | test/testcard.rb | 29 | ||||
| -rw-r--r-- | test/text_spec.rb | 26 |
2 files changed, 55 insertions, 0 deletions
diff --git a/test/testcard.rb b/test/testcard.rb index b25813b..1951390 100644 --- a/test/testcard.rb +++ b/test/testcard.rb @@ -179,6 +179,30 @@ flash = 0 opacity_square = Square.new(500, 255, 50, ["red", "green", "blue", "yellow"]) time_start = Time.now +# Text size +created_text = Text.new(10, 270, "Created text", 20, font) +created_text_background = Rectangle.new( + created_text.x - 10, + created_text.y - 10, + created_text.width + 20, + created_text.height + 20, + "red" +) +created_text.remove +created_text.add + +updated_text = Text.new(20 + created_text_background.x2, 270, "Updated text", 20, font) +updated_text_background = Rectangle.new( + updated_text.x - 10, + updated_text.y - 10, + updated_text.width + 20, + updated_text.height + 20, + "blue" +) +updated_text.remove +updated_text.add +UPDATED_TEXT_OPTIONS = "of various size".split(" ") + on key: 'escape' do close end @@ -210,6 +234,11 @@ update do elapsed_time = Time.now - time_start opacity = Math.sin(3 * elapsed_time.to_f).abs opacity_square.color.opacity = opacity + + if (get :frames) % 60 == 0 + updated_text.text = "Updated text " + UPDATED_TEXT_OPTIONS[Time.now.to_i % UPDATED_TEXT_OPTIONS.length] + updated_text_background.width = updated_text.width + 20 + end end show diff --git a/test/text_spec.rb b/test/text_spec.rb index 22e17a3..1dc6189 100644 --- a/test/text_spec.rb +++ b/test/text_spec.rb @@ -15,4 +15,30 @@ RSpec.describe Ruby2D::Text do expect(t.text).to eq "0" end end + + describe "#width" do + it "is known after creation" do + t = Text.new(0, 0, "Hello world!", 40, "test/media/bitstream_vera/vera.ttf") + expect(t.width).to eq(239) + end + + it "is known after updating" do + t = Text.new(0, 0, "Good morning world!", 40, "test/media/bitstream_vera/vera.ttf") + t.text = "Hello world!" + expect(t.width).to eq(239) + end + end + + describe "#height" do + it "is known after creation" do + t = Text.new(0, 0, "Hello world!", 40, "test/media/bitstream_vera/vera.ttf") + expect(t.height).to eq(48) + end + + it "is known after updating" do + t = Text.new(0, 0, "Good morning world!", 40, "test/media/bitstream_vera/vera.ttf") + t.text = "Hello world!" + expect(t.height).to eq(48) + end + end end |
