Skip to content

Commit

Permalink
Frames in a Screen can now be offset by arbitrary values from point o…
Browse files Browse the repository at this point in the history
…f origin
  • Loading branch information
acook committed Oct 8, 2023
1 parent 3c4fff3 commit 06097bf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/remedy/frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ def initialize name: self.object_id
@nl = ?\n
end

attr_accessor :vorigin, :horigin, :offset, :depth
attr_accessor :vorigin, :horigin, :depth
attr_accessor :name, :size, :available_size
attr_accessor :nl, :fill, :halign, :valign
attr_accessor :contents, :arrangement

# Sets the offset from the origin point.
# @note Positive offsets always move the frame right and down,
# so negative values are more useful when `horigin = :right` and/or `vorigin = :bottom`.
# @return [Remedy::Tuple] the vertical and horizontal offset to apply
attr_accessor :offset

def to_a
compile_contents
end
Expand Down
3 changes: 3 additions & 0 deletions lib/remedy/screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def populate_buffer
raise "Unknown horigin:#{frame.horigin}"
end

voffset += frame.offset.height
hoffset += frame.offset.width

buffer[voffset,hoffset] = frame
end
end
Expand Down
32 changes: 32 additions & 0 deletions spec/screen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,36 @@
expect(actual).to eq expected
end
end

describe "offset frames" do
let(:new_size_override){ Tuple 5, 9 }

before do
frame.vorigin = :bottom
frame.horigin = :right
frame.halign = :center
frame.valign = :center
frame.offset = Tuple -1, -2
frame.size = Tuple(4, 0.5)
frame.fill = "."
end

it "moves the frame away from the point of origin" do

expected = [
" foo. ",
" bar. ",
" baz. ",
" .... ",
" "
].join ?\n

s.buffer.fill = " "
s.frames << frame
s.resized new_size_override, redraw: false
actual = s.to_s

expect(actual).to eq expected
end
end
end

0 comments on commit 06097bf

Please sign in to comment.