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

button.nim - Clip the radiobox/checkbox text to match the button bounds #459

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions nimx/button.nim
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,20 @@ proc drawTitle(b: Button, xOffset: Coord) =
else:
blackColor()

let font = systemFont()
var titleRect = b.bounds
var pt = centerInRect(font.sizeOfString(b.title), titleRect)
# truncate title to bounds if required
var
titleRect = b.bounds
title = b.title
let
font = systemFont()
sz = font.sizeOfString(title)
# reduce by size of checkbox/radiobox
titleRect.size.width -= titleRect.size.height
if sz.width > titleRect.size.width:
title.setLen(int(title.len.float * titleRect.size.width / sz.width))
var pt = centerInRect(sz, titleRect)
if pt.x < xOffset: pt.x = xOffset
Copy link
Owner

Choose a reason for hiding this comment

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

I might be wrong but you'll have to account for xOffset before trimming. Otherwise trimming done above might not be sufficient and the text will still escape the bounds by up to xOffset.

c.drawText(font, pt, b.title)
c.drawText(font, pt, title)

var regularButtonComposition = newComposition """
uniform vec4 uStrokeColor;
Expand Down