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

Rework text wrapping code #348

Open
enenra opened this issue Dec 14, 2022 · 1 comment
Open

Rework text wrapping code #348

enenra opened this issue Dec 14, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@enenra
Copy link
Owner

enenra commented Dec 14, 2022

This works reportedly correctly:

def wrap_text(text: str, width: int) -> List[str]:
    '''
    Wrap the given text to the given width.

    Args:
        width: The maximum pixel width of each row.
        text: The text to be split and returned.

    Returns:
        A list of the split up text and empty space if necessary.
    '''
    return_text = []
    row_text = ''

    system = bpy.context.preferences.system
    dpi = 72 if system.ui_scale >= 1 else system.dpi
    blf.size(0, 10, dpi)

    for word in text.split():
        word = f' {word}'
        line_len, _ = blf.dimensions(0, row_text + word)

        if line_len <= (width - 16):
            row_text += word
        else:
            return_text.append(row_text)
            row_text = word

    if row_text:
        return_text.append(row_text)

    return return_text

def draw(self, context):
    col = self.layout.column()
    width = context.region.width
    ui_scale = context.preferences.system.ui_scale
    MSG = f"Or move your already purchased {ds_props.product} pack into this folder:"
    for text in wrap_text(MSG, 0.8*(width/ui_scale)):
        col.label(text=text)

I'm thinking the main issue of my attempts has been forgetting to include uiscale.

@enenra enenra added the enhancement New feature or request label Dec 14, 2022
@enenra enenra added this to the SEUT 1.0.0+ milestone Dec 14, 2022
@enenra enenra self-assigned this Dec 14, 2022
@enenra enenra modified the milestones: SEUT 1.0.0+, SEUT 1.1.0 Jan 9, 2023
@enenra
Copy link
Owner Author

enenra commented Jan 20, 2023

@enenra enenra modified the milestones: SEUT 1.1.0, SEUT 1.0.0+ Jul 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant