From 6828fefeadc204c36893d93b84ae729ea944a355 Mon Sep 17 00:00:00 2001 From: Humberto Sanchez II Date: Fri, 19 Jan 2024 15:26:44 -0600 Subject: [PATCH] [OglClass]: [ * Enforce OglClass Dimension minimums * Send event (bug) * Put in hack fix for bug ] [https://github.com/hasii2011/ogl/issues/102] --- src/ogl/OglClass.py | 19 +++++++++++++++++++ src/ogl/_version.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ogl/OglClass.py b/src/ogl/OglClass.py index 94702e3..4a2806e 100644 --- a/src/ogl/OglClass.py +++ b/src/ogl/OglClass.py @@ -30,6 +30,7 @@ from miniogl.MiniOglColorEnum import MiniOglColorEnum from miniogl.SelectAnchorPoint import SelectAnchorPoint +from ogl.OglDimensions import OglDimensions from ogl.OglObject import OglObject from ogl.OglObject import DEFAULT_FONT_SIZE @@ -43,6 +44,11 @@ CONSTRUCTOR_NAME: str = '__init__' MARGIN: int = 10 +# +# When I added optional display of constructor and/or dunder methods, I introduced this bug +# I'll fix this later +# +HACK_FIX_AUTO_RESIZE: bool = True # TODO: This should be a debug flag @dataclass @@ -197,9 +203,19 @@ def autoResize(self): else: methodW, methodH = 0, 0 + print(f'{headerW=} {fieldsW=} {methodW}') w = max(headerW, fieldsW, methodW) h = y - headerY w += 2 * MARGIN + + minDimensions: OglDimensions = self._oglPreferences.classDimensions + if w < minDimensions.width: + w = minDimensions.width + if h < minDimensions.height: + h = minDimensions.height + + if HACK_FIX_AUTO_RESIZE is True: + w = w - 20 # Hack keeps growing self.SetSize(w, h) # to automatically replace the sizer objects at a correct place @@ -207,6 +223,8 @@ def autoResize(self): self.selected = False self.selected = True + self.eventEngine.sendEvent(OglEventType.DiagramFrameModified) + def OnRightDown(self, event: MouseEvent): """ Callback for right clicks @@ -348,6 +366,7 @@ def _drawClassFields(self, dc, draw=False, initialX=None, initialY=None, calcWid if initialY is not None: y = initialY w = self._width + print(f'{w=}') h = 0 if calcWidth: w = 0 diff --git a/src/ogl/_version.py b/src/ogl/_version.py index cfb007c..a1d9bb6 100644 --- a/src/ogl/_version.py +++ b/src/ogl/_version.py @@ -1 +1 @@ -__version__ = '2.1.5' +__version__ = '2.1.15'