From 02dde800c82e7b8e46d1c4924a4a8d15cb6764bf Mon Sep 17 00:00:00 2001 From: John Lindal Date: Mon, 18 Mar 2024 21:57:44 -0700 Subject: [PATCH] jx_layout_editor: store min window size in files; fix enclosed object positioning; draw dnd target border even if widget is selected --- todo-jxlayout | 3 ++ .../jx_layout_editor/code/ContainerWidget.cpp | 12 +++++ tools/jx_layout_editor/code/ContainerWidget.h | 2 + .../jx_layout_editor/code/InputFieldBase.cpp | 2 +- .../jx_layout_editor/code/LayoutContainer.cpp | 36 +++++++++------ tools/jx_layout_editor/code/LayoutWidget.cpp | 46 +++++++++++++++---- tools/jx_layout_editor/code/LayoutWidget.h | 2 + tools/jx_layout_editor/code/fileVersions.h | 4 +- 8 files changed, 82 insertions(+), 25 deletions(-) diff --git a/todo-jxlayout b/todo-jxlayout index 1c7781f91..0f51f3ab7 100644 --- a/todo-jxlayout +++ b/todo-jxlayout @@ -1,3 +1,6 @@ +changing partition sizes should set "needs save" + JPartition must broadcast + expand scrollbarSet vertically in main layout: too tall horizontally becomes too wide diff --git a/tools/jx_layout_editor/code/ContainerWidget.cpp b/tools/jx_layout_editor/code/ContainerWidget.cpp index fa5815a70..85b3dff0f 100644 --- a/tools/jx_layout_editor/code/ContainerWidget.cpp +++ b/tools/jx_layout_editor/code/ContainerWidget.cpp @@ -151,3 +151,15 @@ ContainerWidget::DrawOver itsLayout->SetHint(ToString()); LayoutWidget::DrawOver(p, rect); } + +/****************************************************************************** + IsDNDLayoutTarget (virtual protected) + + ******************************************************************************/ + +bool +ContainerWidget::IsDNDLayoutTarget() + const +{ + return itsLayout->IsDNDTarget(); +} diff --git a/tools/jx_layout_editor/code/ContainerWidget.h b/tools/jx_layout_editor/code/ContainerWidget.h index 5f72219c9..8934e6756 100644 --- a/tools/jx_layout_editor/code/ContainerWidget.h +++ b/tools/jx_layout_editor/code/ContainerWidget.h @@ -34,6 +34,8 @@ class ContainerWidget : public LayoutWidget void DrawBorder(JXWindowPainter& p, const JRect& frame) override; void DrawOver(JXWindowPainter& p, const JRect& rect) override; + bool IsDNDLayoutTarget() const override; + LayoutContainer* GetLayoutContainer() const; private: diff --git a/tools/jx_layout_editor/code/InputFieldBase.cpp b/tools/jx_layout_editor/code/InputFieldBase.cpp index 04a27a08d..238d46f32 100644 --- a/tools/jx_layout_editor/code/InputFieldBase.cpp +++ b/tools/jx_layout_editor/code/InputFieldBase.cpp @@ -83,7 +83,7 @@ InputFieldBase::Draw { p.SetPenColor(JColorManager::GetWhiteColor()); p.SetFilling(true); - p.Rect(GetFrameLocal()); + p.Rect(GetBounds()); } /****************************************************************************** diff --git a/tools/jx_layout_editor/code/LayoutContainer.cpp b/tools/jx_layout_editor/code/LayoutContainer.cpp index 476a8f8f9..4594f66d3 100644 --- a/tools/jx_layout_editor/code/LayoutContainer.cpp +++ b/tools/jx_layout_editor/code/LayoutContainer.cpp @@ -99,7 +99,7 @@ LayoutContainer::LayoutContainer LayoutContainer::LayoutContainer ( LayoutContainer* parent, - LayoutWidget* owner, + LayoutWidget* owner, JXContainer* enclosure, const HSizingOption hSizing, const VSizingOption vSizing, @@ -125,7 +125,6 @@ LayoutContainer::LayoutContainer itsDropRectList(nullptr) { LayoutContainerX(); - SetBorderWidth(1); itsEditMenu->AttachHandlers(this, &LayoutContainer::UpdateEditMenu, @@ -352,8 +351,12 @@ LayoutContainer::ReadConfig const JFileVersion vers ) { - input >> itsCodeTag; - input >> itsWindowTitle; + input >> itsCodeTag >> itsWindowTitle; + + if (vers >= 9) + { + input >> itsWindowMinWidth >> itsWindowMinHeight; + } if (vers >= 3) { @@ -762,6 +765,8 @@ LayoutContainer::WriteConfig { output << itsCodeTag << std::endl; output << itsWindowTitle << std::endl; + output << itsWindowMinWidth << std::endl; + output << itsWindowMinHeight << std::endl; output << itsXWMClass << std::endl; output << itsContainerName << std::endl; output << itsAdjustContainerToFitFlag << std::endl; @@ -1260,12 +1265,6 @@ LayoutContainer::DrawBorder { p.SetPenColor(JColorManager::GetDefaultDNDBorderColor()); } - else - { - p.SetPenColor(itsParent == nullptr ? JColorManager::GetBlackColor() : - HasFocus() ? JColorManager::GetYellowColor() : - JColorManager::GetWhiteColor()); - } p.SetFilling(true); p.Rect(frame); } @@ -1284,6 +1283,14 @@ LayoutContainer::DrawOver const JRect& rect ) { + if (itsParent != nullptr) + { + p.SetPenColor(IsDNDTarget() ? JColorManager::GetDefaultDNDBorderColor() : + HasFocus() ? JColorManager::GetYellowColor() : + JColorManager::GetWhiteColor()); + p.Rect(rect); + } + if (itsDropRectList == nullptr || (itsDropPt.x == -1 && itsDropPt.y == -1)) { return; @@ -1973,14 +1980,15 @@ LayoutContainer::NewUndo void LayoutContainer::UpdateLayoutMenu() { - if (HasFocus() && itsParent != nullptr) + const bool hasFocus = HasFocus(); + if (hasFocus && itsParent != nullptr) { JPtrArray list(JPtrArrayT::kForgetAll); GetSelectedWidgets(&list); itsLayoutMenu->SetItemEnabled(kSelectParentCmd, !list.IsEmpty()); } - else + else if (hasFocus) { itsLayoutMenu->DisableItem(kSelectParentCmd); } @@ -2291,7 +2299,7 @@ LayoutContainer::HandleArrangeMenu else if (index == kExpandHorizCmd && focus) { - const JCoordinate w1 = GetFrameWidth(); + const JCoordinate w1 = GetApertureWidth(); for (auto* w : list) { const JRect r = w->GetFrame(); @@ -2302,7 +2310,7 @@ LayoutContainer::HandleArrangeMenu } else if (index == kExpandVertCmd && focus) { - const JCoordinate h = GetFrameHeight(); + const JCoordinate h = GetApertureHeight(); for (auto* w : list) { const JRect r = w->GetFrame(); diff --git a/tools/jx_layout_editor/code/LayoutWidget.cpp b/tools/jx_layout_editor/code/LayoutWidget.cpp index 3075bbf29..db95b3679 100644 --- a/tools/jx_layout_editor/code/LayoutWidget.cpp +++ b/tools/jx_layout_editor/code/LayoutWidget.cpp @@ -500,9 +500,14 @@ LayoutWidget::SetSelected if (itsSelectedFlag) { - const bool ok = itsParent->Focus(); - assert( ok ); - GetWindow()->Refresh(); + // delay so "select parent" doesn't work it's way up the chain + auto* task = jnew JXUrgentFunctionTask(this, [this]() + { + const bool ok = itsParent->Focus(); + assert( ok ); + GetWindow()->Refresh(); + }); + task->Go(); } } } @@ -568,10 +573,21 @@ LayoutWidget::DrawOver r.SetSize(0,0); } - JRect f = GetFrameLocal(); - if (itsSelectedFlag) + bool drawBorder = false; + if (IsDNDLayoutTarget()) + { + p.SetPenColor(JColorManager::GetDefaultDNDBorderColor()); + drawBorder = true; + } + else if (itsSelectedFlag) { p.SetPenColor(JColorManager::GetDefaultSelectionColor()); + drawBorder = true; + } + + JRect f = GetFrameLocal(); + if (drawBorder) + { p.Rect(f); } @@ -615,23 +631,23 @@ LayoutWidget::DrawOver p.SetLineWidth(2); p.SetPenColor(JColorManager::GetOrangeColor()); - if (!itsSelectedFlag && GetHSizing() == JXWidget::kFixedLeft) + if (!drawBorder && GetHSizing() == JXWidget::kFixedLeft) { f.Shrink(1,0); p.Line(f.topLeft(), f.bottomLeft()); } - else if (!itsSelectedFlag && GetHSizing() == JXWidget::kFixedRight) + else if (!drawBorder && GetHSizing() == JXWidget::kFixedRight) { f.Shrink(2,0); p.Line(f.topRight(), f.bottomRight()); } - if (!itsSelectedFlag && GetVSizing() == JXWidget::kFixedTop) + if (!drawBorder && GetVSizing() == JXWidget::kFixedTop) { f.Shrink(0,1); p.Line(f.topLeft(), f.topRight()); } - else if (!itsSelectedFlag && GetVSizing() == JXWidget::kFixedBottom) + else if (!drawBorder && GetVSizing() == JXWidget::kFixedBottom) { f.Shrink(0,2); p.Line(f.bottomLeft(), f.bottomRight()); @@ -1022,6 +1038,18 @@ LayoutWidget::DNDFinish } } +/****************************************************************************** + IsDNDLayoutTarget (virtual protected) + + ******************************************************************************/ + +bool +LayoutWidget::IsDNDLayoutTarget() + const +{ + return false; +} + /****************************************************************************** AddPanels (virtual protected) diff --git a/tools/jx_layout_editor/code/LayoutWidget.h b/tools/jx_layout_editor/code/LayoutWidget.h index 82b172557..157931fe7 100644 --- a/tools/jx_layout_editor/code/LayoutWidget.h +++ b/tools/jx_layout_editor/code/LayoutWidget.h @@ -111,6 +111,8 @@ class LayoutWidget : public JXWidget const JXKeyModifiers& modifiers) override; void DNDFinish(const bool isDrop, const JXContainer* target) override; + virtual bool IsDNDLayoutTarget() const; + private: enum diff --git a/tools/jx_layout_editor/code/fileVersions.h b/tools/jx_layout_editor/code/fileVersions.h index 677c03e19..f7a0e1959 100644 --- a/tools/jx_layout_editor/code/fileVersions.h +++ b/tools/jx_layout_editor/code/fileVersions.h @@ -12,8 +12,10 @@ #include -const JFileVersion kCurrentFileVersion = 8; +const JFileVersion kCurrentFileVersion = 9; +// version 9: +// saves window min size (wtf?) // version 8: // addes hideBorder to RadioGroup // version 7: