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

Shift lines affected by .wrap() for less flat text layouts #392

Open
ElectroDev1 opened this issue Nov 27, 2022 · 2 comments
Open

Shift lines affected by .wrap() for less flat text layouts #392

ElectroDev1 opened this issue Nov 27, 2022 · 2 comments
Labels
feature 💭 It would be extra good if...

Comments

@ElectroDev1
Copy link

The feature could work like this:

scribble_element.wrap(maxWidth, [maxHeight], [characterWrap], [lineShift]);

-----------------------

Example:

scribble("Hello world, how are you?").wrap(40, -1, false, 10);

Hello
     world,
         how are
                you?

lineShift would shift by a specific amount every new wrapped line relatively to the previous one.


The feature could also be its own method to allow for even more customization without bloating the .wrap() method.

scribble_element.wrapShift(shift1, [shift2] ...);

-----------------------

Example:

scribble("Hello world, how are you?").wrapShift(40,-20);

       Hello
              World
    how are
you?

Where the last argument would affect every line going down if no more arguments are provided

@JujuAdams JujuAdams added the feature 💭 It would be extra good if... label Nov 30, 2022
@JujuAdams
Copy link
Owner

JujuAdams commented Dec 5, 2022

Thought about this a little bit and I think I'll go for a .lineXOffsetFunc() text element method. This method would take a function as a parameter. Whenever a new line is created (either via \n, [/page], or text wrapping) then this function would be called.

The function is handed 4 arguments:

  • lineIndex: The index of the line on the page, with 0 being the first line of text on the page
  • indentX: The horizontal indentation relative to the first line of text on the page, measured in pixels. This currently would always be 0 but this may change in the future if/when the [indent] command tag is introduced
  • lineY: The vertical offset relative to the first line of text on the page, measured in pixels
  • breakType: From the SCRIBBLE_BREAK_TYPE enum, either .FIRST_LINE .LINEBREAK, .PAGEBREAK, or .WRAP

This function provided to .lineOffset() should then return a number indicating the x-offset for that particular new line of text. This allows for a lot of different kinds of behaviours without lots of perculiar arithmetic inside the parser itself.

@JujuAdams
Copy link
Owner

This does also raise the possiblity of a .lineWidthFunc() method for irregular-shaped containers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 💭 It would be extra good if...
Projects
None yet
Development

No branches or pull requests

2 participants