Skip to content

Commit

Permalink
fix: set equastion numbering does not break anymore
Browse files Browse the repository at this point in the history
fixes #37
  • Loading branch information
jomaway committed Jul 1, 2024
1 parent e9e8bfa commit f0c7342
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
52 changes: 27 additions & 25 deletions lib/api.typ
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
/// - pre (auto, int , relative , fraction , array): This is specifies the columns for annotations on the *left* side of the bytefield
/// - post (auto, int , relative , fraction , array): This is specifies the columns for annotations on the *right* side of the bytefield
///
/// - ..fields (bf-field): arbitrary number of data fields, annotations and headers which build the bytefield.
/// -> bytefield
/// - ..fields (bf-field): arbitrary number of data fields, annotations and headers which build the bytefield.
/// -> bytefield
#let bytefield(
bpr: 32,
bpr: 32,
msb: right,
rows: auto,
pre: auto,
Expand Down Expand Up @@ -44,48 +44,48 @@
/// - fill (color): The background color for the field.
/// - body (content): The label which is displayed inside the field.
#let _field(size, fill: none, body) = {
if size != auto { assert.eq(type(size), int, message: strfmt("expected size to be an integer or auto, found {}", type(size))) }
if size != auto { assert.eq(type(size), int, message: strfmt("expected size to be an integer or auto, found {}", type(size))) }
if fill != none { assert(type(fill) in (color, gradient, pattern), message: strfmt("expected fill to be an color or gradient, found {}.", type(fill)))}
data-field(none, size, none, none, body, format: (fill: fill))
}

/// Add a field of the size of *one bit* to the bytefield
///
/// Basically just a wrapper for @@_field()
/// Basically just a wrapper for @@_field()
///
/// - ..args (arguments): All arguments which are accepted by `_field`
///
#let bit(..args) = _field(1, ..args)

/// Add a field of a given size of bits to the bytefield
///
/// Basically just a wrapper for @@_field()
/// Basically just a wrapper for @@_field()
///
/// - len (int): Size of the field in bits
/// - len (int): Size of the field in bits
/// - ..args (arguments): All arguments which are accepted by `_field`
///
#let bits(len, ..args) = _field(len, ..args)

/// Add a field of the size of one byte to the bytefield
///
/// Basically just a wrapper for @@_field()
/// Basically just a wrapper for @@_field()
///
/// - ..args (arguments): All arguments which are accepted by `_field`
///
#let byte(..args) = _field(8, ..args)

/// Add a field of the size of multiple bytes to the bytefield
///
/// Basically just a wrapper for @@_field()
/// Basically just a wrapper for @@_field()
///
/// - len (int): Size of the field in bytes
/// - len (int): Size of the field in bytes
/// - ..args (arguments): All arguments which are accepted by `_field`
///
#let bytes(len, ..args) = _field(len * 8, ..args)

/// Add a flag to the bytefield.
///
/// Basically just a wrapper for @@_field()
/// Basically just a wrapper for @@_field()
///
/// - text (content): The label of the flag which is rotated by `270deg`
/// - ..args (arguments): All arguments which are accepted by `_field`
Expand All @@ -94,7 +94,7 @@

/// Create a annotation
///
/// The note is always shown in the same row as the next data field which is specified.
/// The note is always shown in the same row as the next data field which is specified.
///
/// - side (left, right): Where the annotation should be displayed
/// - row (int, auto): Define a row where the note should be displayed.
Expand All @@ -107,7 +107,7 @@
side,
row: auto,
rowspan:1,
level:0,
level:0,
inset: 5pt,
bracket: false,
content,
Expand All @@ -118,6 +118,7 @@
assert.eq(type(level), int, message: strfmt("expected level to be a integer, found {}.", type(level)));
assert(type(inset) in (length, dictionary), message: strfmt("expected inset to be a length or dictionary, found {}.", type(inset)));


let _align = none
let _first = none
let _second = none
Expand All @@ -133,6 +134,7 @@
}

let body = if (bracket == false) { content } else {
set math.equation(block: false, numbering: none)
grid(
columns:2,
gutter: inset,
Expand All @@ -152,7 +154,7 @@
/// Shows a note with a bracket and spans over multiple rows.
///
/// Basically just a shortcut for the `note` field with the argument `bracket:true` by default.
///
///
#let group(side, rowspan, level:0, bracket:true, content) = {
note(side, level:level, rowspan:rowspan, bracket:bracket, content)
}
Expand All @@ -165,44 +167,44 @@
/// - end-addr (string, content): The end address will be bottom aligned
#let section(start-addr, end-addr, span: 1) = {
note(
left,
rowspan: span,
inset: (x:5pt, y:2pt),
left,
rowspan: span,
inset: (x:5pt, y:2pt),
box(height:100%, [
#set text(0.8em, font: "Noto Mono", weight: 100)
#align(top + end)[#start-addr]
#align(bottom + end)[#end-addr]
]))
}

/// Config the header on top of the bytefield
/// Config the header on top of the bytefield
///
/// By default no header is shown.
///
///
/// - range (array): Specify the range of number which are displayed on the header. Format: `(start, end)`
/// - autofill (string): Specify on of the following options and let bytefield calculate the numbers for you.
/// - `"bytes"` shows each multiple of 8 and the last number of the row.
/// - `"all"` shows all numbers.
/// - `"bounds"` shows a number for every start and end bit of a field.
/// - `"offsets"` shows a number for every start bit of a field.
/// - `"offsets"` shows a number for every start bit of a field.
/// - numbers (auto, none): if none is specified no numbers will be shown on the header. This is useful to show only labels.
/// - marker (bool, array): defines if marker lines are shown under a label.
/// - angle (angle): The rotation angle of the label.
/// - fill (color): The background of the header.
/// - stroke (color): The border stroke of the header.
/// - text-size(length): The text-size for the header labels and numbers.
/// - ..args (int, content): The numbers and labels which should be shown on the header.
/// - ..args (int, content): The numbers and labels which should be shown on the header.
/// The number will only be shown if it is inside the range.
/// If a `content` value follows a `int` value it will be interpreted as label for this number.
/// For more information see the _manual_.
#let bitheader(
range: (auto,auto),
range: (auto,auto),
autofill: auto,
numbers: auto,
marker: true,
fill: auto,
stroke: auto,
text-size: auto,
text-size: auto,
angle: -60deg,
..args
) = {
Expand All @@ -221,7 +223,7 @@
last = calc.abs(arg)
} else if type(arg) == str {
autofill = arg
} else if type(arg) == content {
} else if type(arg) == content {
labels.insert(str(last),arg)
last += 1
}
Expand All @@ -235,7 +237,7 @@
fill: fill,
stroke: stroke,
)

return header-field(
start: range.at(0, default: auto), // todo. fix this
end: range.at(1, default: auto), // todo. fix this
Expand Down
14 changes: 11 additions & 3 deletions typst.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
[package]
name="bytefield"
version = "0.0.6"
name = "bytefield"
version = "0.0.7"
entrypoint = "bytefield.typ"
authors = ["Jomaway <https://github.com/jomaway>"]
license = "MIT"
description = "A package to create network protocol headers, memory map, register definitions and more."
repository = "https://github.com/jomaway/typst-bytefield"
keywords = ["bytefields", "protocol", "header", "memory", "map", "register"]
compiler = "0.10.0"
exclude = ["examples/**", "docs/**", "**.pdf", "**.png", "tests/*", "justfile", "CHANGELOG.md"]
exclude = [
"examples/**",
"docs/**",
"**.pdf",
"**.png",
"tests/*",
"justfile",
"CHANGELOG.md",
]

0 comments on commit f0c7342

Please sign in to comment.