Skip to content

Conversation

@jlp765
Copy link
Contributor

@jlp765 jlp765 commented Dec 24, 2020

( Only tested on win platform)

Currently the text of a radiobox or checkbox can overflow the bounds of the button. This means that clicking the text to the right of the button bound does not click the button.

This PR clips the text to match the width of the button bounds (which should be picked up by the developer and trigger them to adjust the sizing of the control).

Test code (there should be a gap of 10 between the two checkboxes where the user clicks neither checkboxes):

import nimx / [ view, button, window ]

runApplication:
    let w = newWindow(newRect(50, 50, 500, 150))
    let checkbox1 = newCheckbox(newRect(10, 20, 75, 16))
    #echo "Frame: " & $checkbox1.frame() & " bounds: " & $checkbox1.bounds()
    checkbox1.title = "Checkbox1"
    checkbox1.name = checkbox1.title
    w.addSubview(checkbox1)
    let checkbox2 = newCheckbox(newRect(95, 20, 75, 16))
    checkbox2.title = "Checkbox2"
    checkbox2.name = checkbox2.title
    w.addSubview(checkbox2)

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.

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