Skip to content

Commit

Permalink
<Update>[OglClass]: <Update AutoResize>
Browse files Browse the repository at this point in the history
[
* Enforce OglClass Dimension minimums
* Send event (bug)
* Put in hack fix for bug
]

[#102]
  • Loading branch information
Humberto Sanchez II committed Jan 19, 2024
1 parent 77e7258 commit 6828fef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/ogl/OglClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -197,16 +203,28 @@ 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
if self.selected is True:
self.selected = False
self.selected = True

self.eventEngine.sendEvent(OglEventType.DiagramFrameModified)

def OnRightDown(self, event: MouseEvent):
"""
Callback for right clicks
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ogl/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.1.5'
__version__ = '2.1.15'

0 comments on commit 6828fef

Please sign in to comment.