On 20/06/2015 at 13:32, xxxxxxxx wrote:
Andreas,
I understand. I'm used to perfectly aligning everything in my programs, so accepting this approach towards a UI has been frustrating. The biggest hurdle is to work around the fact that you let users set the UI font to anything in C4D. That is a pain.
For users that are having issues with this, I worked out a system that lets you adjust your 'GeUserArea' to whatever the user sets their font to.
It works like this:
- Layout your UI the way to want without changing the font in C4D, I used 'Segoe UI'.
- Calculate a baseline width for a known amount of text at the design-time font.
- Then, when the UserArea is first drawn, when the plugin opens, measure the current width for the same known text.
- Calculate an adjustment factor for the width difference and resize the UserArea to that factor.
#----Adjust the size of the 'UserArea' to accomodate different fonts.
current_width = user_area_info_box.DrawGetTextWidth('abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ')
print current_width # 331
baseline_width = 331 # Calculated with the font 'Segoe UI' which was used with initial design.
user_area_info_box.font_width_factor = current_width / float(baseline_width)
user_area_info_box.txt_height = user_area_info_box.DrawGetFontHeight()
# Limit the range of the adjustment with 'min' and 'max' for crazy fonts.
width = min(max(int(round(user_area_info_box.font_width_factor * 435 )) , 350), 700) # 435 was the design-time width.
ScaleInfoBox(width)
Then, resize the box like this:
def ScaleInfoBox(width) :
global user_area_info_box
# Calculate a height adjustment, if needed, a similar way using 'user_area_info_box.txt_height'
height = 200
InfoBox.width = width
InfoBox.height = height
gl_dialog.LayoutFlushGroup(DISPLAY_SCREEN_GROUP)
user_area_info_box = InfoBox(None) 'InfoBox' is the class name for the 'GeUserArea'.
LayoutInfoBox(gl_dialog)
gl_dialog.LayoutChanged(DISPLAY_SCREEN_GROUP)
# This function was used initially to add the 'UserArea' to the dialog.
def LayoutInfoBox(self) : # 'self' is the dialog.
self.AddUserArea(INFO_BOX, c4d.BFH_LEFT)
self.AttachUserArea(user_area_info_box, INFO_BOX)
The works well to adjust the width of a 'GeUserArea' to different user fonts.
Hope it helps save someone some time.
Chris