From f0c73425991f0ec204bfa4367d1d788bd37e2461 Mon Sep 17 00:00:00 2001 From: jomaway Date: Mon, 1 Jul 2024 11:43:27 +0200 Subject: [PATCH] fix: set equastion numbering does not break anymore fixes #37 --- lib/api.typ | 52 +++++++++++++++++++++++++++------------------------- typst.toml | 14 +++++++++++--- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/lib/api.typ b/lib/api.typ index 83c38c5..c25fee3 100644 --- a/lib/api.typ +++ b/lib/api.typ @@ -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, @@ -44,14 +44,14 @@ /// - 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` /// @@ -59,16 +59,16 @@ /// 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` /// @@ -76,16 +76,16 @@ /// 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` @@ -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. @@ -107,7 +107,7 @@ side, row: auto, rowspan:1, - level:0, + level:0, inset: 5pt, bracket: false, content, @@ -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 @@ -133,6 +134,7 @@ } let body = if (bracket == false) { content } else { + set math.equation(block: false, numbering: none) grid( columns:2, gutter: inset, @@ -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) } @@ -165,9 +167,9 @@ /// - 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] @@ -175,34 +177,34 @@ ])) } -/// 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 ) = { @@ -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 } @@ -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 diff --git a/typst.toml b/typst.toml index fe74cff..b4d3783 100644 --- a/typst.toml +++ b/typst.toml @@ -1,6 +1,6 @@ [package] -name="bytefield" -version = "0.0.6" +name = "bytefield" +version = "0.0.7" entrypoint = "bytefield.typ" authors = ["Jomaway "] license = "MIT" @@ -8,4 +8,12 @@ description = "A package to create network protocol headers, memory map, registe 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", +]