Skip to content

Add BorderLabels to Border widget #214

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

CosmicPredator
Copy link

Added BorderLabels to Border Widget to show text inline along the borders. Currently, it has the following alignment options,

  • Top Left
  • Top Center
  • Top Right
  • Bottom Left
  • Bottom Center
  • Bottom Right

Here is a screenshot,
image

Example code snippet,

self.border.labels = &[_]vxfw.Border.BorderLabel {
    .{ .text = "TopLeft", .alignment = .TopLeft },
    .{ .text = "TopCenter", .alignment = .TopCenter },
    .{ .text = "TopRight", .alignment = .TopRight },
    .{ .text = "BottomLeft", .alignment = .BottomLeft },
    .{ .text = "BottomCenter", .alignment = .BottomCenter },
    .{ .text = "BottomRight", .alignment = .BottomRight },
};

Copy link
Owner

@rockorager rockorager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good feature to add. Approach is good but you just need to make sure you are working on graphemes vs bytes.

- used Grapheme Iterator instead of old range based loop.
- used `ctx.stringWidth()` instead of `text.len`.
- added empty label guard.
@CosmicPredator
Copy link
Author

@rockorager I have made the changes requested.
Btw, thanks for the helper snippets, really appreciate it 😃.

Copy link
Owner

@rockorager rockorager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One remaining issue on the loop.

@CosmicPredator
Copy link
Author

@rockorager Done. (I think I need to get a good grasp on grapheme iterator)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants