BitmapButton not work
-
Hi,
I created a Bitmaobutton GUI, but the GUI only works in the right area of the image, and clicking on the left does not work。
my code:custom_gui = self.AddCustomGui(ID, c4d.CUSTOMGUI_BITMAPBUTTON, "", c4d.BFH_SCALEFIT, 0, 0, bc) custom_gui.SetImage(bitmap)
Thanks for any help!
-
Hey @chuanzhen,
Thank you for reaching out to us. Can you please provide an executable code example for your problem, i.e., a little dialog which creates your rig there. Please also provide the bitmap you load there. I have a hunch why this might happen, but I need your code and bitmap to confirm.
Cheers,
Ferdinand -
@ferdinand
--video:
-
Hello @chuanzhen,
In short, I would say you are simply misusing bitmap buttons here. They are not meant to be used with
BFH_SCALEFIT
. My hunch was thatBITMAPBUTTON_FORCE_SIZE
will have an impact here and that turned out to be true, but will also align the image to the left in the button (the extrude icon button below is an example for that). In general, you must useBFH_FIT/BFV_FIT
for bitmap buttons (sweep icon), as our bitmap buttons are not meant to hold text or be wider than the image that they display. You can add custom spacing between buttons with an extra group (sweep icon button).Cheers,
FerdinandResult
Code
"""Demonstrates how to add bitmap buttons to a dialog with different layout options. """ import c4d class TestDialog(c4d.gui.GeDialog): """ """ ID_GRP_MAIN: int = 1000 ID_GROUP_SUB: int = 1001 ID_BTN_1: int = 2000 ID_BTN_2: int = 2001 ID_BTN_3: int = 2002 ID_BTN_4: int = 2003 ID_ICON_1: int = 431000053 ID_ICON_2: int = 5116 ID_ICON_3: int = 5117 ID_ICON_4: int = 5118 def AddBitmapButton(self, gid: int, iid: int, flags: int, forceSize: int = 0) -> c4d.gui.BitmapButtonCustomGui: """Adds a bitmap button to the dialog with the given gadget ID, icon ID, flags, and optional forced size. """ bmp: c4d.bitmaps.BaseBitmap = c4d.bitmaps.InitResourceBitmap(iid) if bmp is None: raise ValueError(f"Failed to load the icon with the ID {iid}.") bc: c4d.BaseContainer = c4d.BaseContainer() bc.SetBool(c4d.BITMAPBUTTON_BUTTON, True) bc.SetInt32(c4d.BITMAPBUTTON_BACKCOLOR, c4d.COLOR_BGEDIT) if forceSize: bc.SetInt32(c4d.BITMAPBUTTON_FORCE_SIZE, forceSize) gui: c4d.gui.BitmapButtonCustomGui = self.AddCustomGui( gid, c4d.CUSTOMGUI_BITMAPBUTTON, "", flags, 0, 0, bc) if not isinstance(gui, c4d.gui.BitmapButtonCustomGui): raise ValueError("Failed to add the custom GUI.") gui.SetImage(bmp) def CreateLayout(self) -> bool: """Creates the layout of the dialog. """ self.SetTitle("Test Dialog") # Open an explicit outer group for the main layout. This group scales horizontally and # vertically and has 4 columns. self.GroupBegin(self.ID_GRP_MAIN, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=4) # Add a bitmap button just like you did with BFH_SCALEFIT. This results in the "broken" left # whitespace as a non-clickable area. self.AddBitmapButton(self.ID_BTN_1, self.ID_ICON_1, c4d.BFH_SCALEFIT) # Do the same but force the size of the button to 32x32 pixels, this will work, but the # image will be left aligned. self.AddBitmapButton(self.ID_BTN_2, self.ID_ICON_2, c4d.BFH_SCALEFIT, forceSize=32) # This is how bitmap buttons are actually meant to be used, with BFH_FIT and BFV_FIT. Bitmap # buttons are not meant to have white space to their left or right. self.AddBitmapButton(self.ID_BTN_3, self.ID_ICON_3, c4d.BFH_FIT) # When you want whitespace to the left and right of the button, you can use a group with # BFH_SCALEFIT and add the button with BFH_SCALE | BFH_CENTER. This will add whitespace to # the left and right of the button. self.GroupBegin(self.ID_GROUP_SUB, c4d.BFH_SCALEFIT, initw=100) self.AddBitmapButton(self.ID_BTN_4, self.ID_ICON_4, c4d.BFH_SCALE | c4d.BFH_CENTER) self.GroupEnd() # An even easier way to add whitespace to the left and right of a button is to use the # GroupSpace method to set the spacing between elements in a group. But with that you cannot # control a single element individually. # self.GroupSpace(10, 2) self.GroupEnd() return True def Command(self, cid: int, msg: int) -> bool: """Handles the command messages. """ if cid in (self.ID_BTN_1, self.ID_BTN_2, self.ID_BTN_3, self.ID_BTN_4): c4d.gui.MessageDialog(f"Button {cid} clicked.") return True return True dlg: TestDialog = TestDialog() # Execute main() if __name__=='__main__': dlg.Open(c4d.DLG_TYPE_ASYNC, defaultw=200, defaulth=200)
-
@ferdinand Thanks