Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(canvas): implement half block marker #550

Merged
merged 3 commits into from
Sep 30, 2023
Merged

feat(canvas): implement half block marker #550

merged 3 commits into from
Sep 30, 2023

Conversation

joshka
Copy link
Member

@joshka joshka commented Sep 30, 2023

A useful technique for the terminal is to use half blocks to draw a grid
of "pixels" on the screen. Because we can set two colors per cell, and
because terminal cells are about twice as tall as they are wide, we can
draw a grid of half blocks that looks like a grid of square pixels.

This commit adds a new HalfBlock marker that can be used in the Canvas
widget and the associated HalfBlockGrid.

Made with VHS

Made with VHS

@codecov
Copy link

codecov bot commented Sep 30, 2023

Codecov Report

Merging #550 (c831448) into main (2fd85af) will increase coverage by 0.02%.
The diff coverage is 94.44%.

@@            Coverage Diff             @@
##             main     #550      +/-   ##
==========================================
+ Coverage   89.51%   89.53%   +0.02%     
==========================================
  Files          41       41              
  Lines       11451    11557     +106     
==========================================
+ Hits        10250    10348      +98     
- Misses       1201     1209       +8     
Files Coverage Δ
src/symbols.rs 72.72% <ø> (ø)
src/widgets/canvas/rectangle.rs 99.31% <100.00%> (+0.20%) ⬆️
src/widgets/canvas.rs 91.38% <92.72%> (-0.52%) ⬇️

A useful technique for the terminal is to use half blocks to draw a grid
of "pixels" on the screen. Because we can set two colors per cell, and
because terminal cells are about twice as tall as they are wide, we can
draw a grid of half blocks that looks like a grid of square pixels.

This commit adds a new `HalfBlock` marker that can be used in the Canvas
widget and the associated HalfBlockGrid.

Also updated demo2 to use the new marker as it looks much nicer.
src/widgets/canvas.rs Outdated Show resolved Hide resolved
src/widgets/canvas.rs Outdated Show resolved Hide resolved
correct the error in my understanding of the coordinate systems, change halfblock cells to pixels, update demo2, document the half block algorithm
src/widgets/canvas.rs Outdated Show resolved Hide resolved
src/widgets/canvas.rs Outdated Show resolved Hide resolved
src/widgets/canvas.rs Outdated Show resolved Hide resolved
src/widgets/canvas.rs Outdated Show resolved Hide resolved
@joshka
Copy link
Member Author

joshka commented Sep 30, 2023

Comments addressed in c831448

@kdheepak
Copy link
Collaborator

Awesome! Excited to see what people make with this!

@joshka joshka merged commit 4541336 into main Sep 30, 2023
32 of 33 checks passed
tonogdlp pushed a commit to tonogdlp/ratatui that referenced this pull request Oct 6, 2023
* feat(canvas): implement half block marker

A useful technique for the terminal is to use half blocks to draw a grid
of "pixels" on the screen. Because we can set two colors per cell, and
because terminal cells are about twice as tall as they are wide, we can
draw a grid of half blocks that looks like a grid of square pixels.

This commit adds a new `HalfBlock` marker that can be used in the Canvas
widget and the associated HalfBlockGrid.

Also updated demo2 to use the new marker as it looks much nicer.

Adds docs for many of the methods and structs on canvas.

Changes the grid resolution method to return the pixel count
rather than the index of the last pixel.
This is an internal detail with no user impact.
@joshka joshka deleted the canvas-half-block branch December 10, 2023 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants