|
|
The purpose of the returned xmax is used to calculate the horizontal scrollbar's width (as described in the docs for draw_item_content()) which is based on the widest item in the entire tree.
When a widget is assigned to the item, it appears to the right of the item, its position determined by label_x() + label_w(), and therefore when it's drawn, its xmax always overrides the item's xmax, because it will be drawn to the right of the item.
If you override draw_item_content(), you're supposed to draw within the xywh of the label_x()/label_y()/label_w()/label_h() dimensions, as shown in the example code, and return the xmax of your actually drawn content, in case it's less than the label's width. This helps the horizontal scrollbar be as precise as possible so when the scroller hits the right-most position, the right-most edge of the widest item is just touching the inner right edge of the window. But that's not the case when a widget is assigned, as the widget becomes the right-most content, which is why xmax is updated after the item is drawn.
I understand your logic here, but I think the whole point of overriding the draw_item_content() method is to draw custom content, which is very likely to be a different width than the label. It's unlikely that I'll override draw_item_content() just to draw the predefined label. An obvious use case for overriding the draw_item_content() method is to implement localisation, where I can have a translation table to translate the labels. In this scenario, the widget would be wrongly positioned for just about every language except the original label language.
I suppose it would be good to know what it is you're trying to do.
You can have a look at this discussion on the rust binding repo to have an understanding of what I'm trying to achieve, and a little bit of what I've tried and the challenges I've had with each approach - including the group-based approach. Even though, it was posted on the rust binding repo, it doesn't contain much code and you should still be able to follow along.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.
[ Direct Link to Message ] | |
|
| |