Trying to render a percentage bar

Hey, I’m currently writing a todo list style for my classes that has a percentage bar to 100.
Currently I thought I could overlap two lines and have the line at the top grow but there is no way for that in typst that I’ve found. Another way I thought to go about it is to draw a rectangle and only fill its color to a certain extend 20% and the rest be another color for the background 100%.

Is there any other way that I’m not looking to do this in typst?

A block in a block is another way

#let progress(percent, height: 100%, width: 100%, bg: gray, fg: blue, stroke: 1pt) = {
  block(height: height, width: width, stroke: stroke, fill: bg, {
    block(height: height, width: width * percent, fill: fg, stroke: stroke)
  })
}

#progress(37%, width: 200pt, height: 30pt)
#progress(75%, width: 200pt, height: 30pt)

You can also draw filled shapes with curve, or even with the package cetz, so there are many ways to do it.

4 Likes