Skip to content

Commit

Permalink
jx_layout_editor: store min window size in files; fix enclosed object…
Browse files Browse the repository at this point in the history
… positioning; draw dnd target border even if widget is selected
  • Loading branch information
jafl committed Mar 19, 2024
1 parent 8531272 commit 02dde80
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 25 deletions.
3 changes: 3 additions & 0 deletions 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

Expand Down
12 changes: 12 additions & 0 deletions tools/jx_layout_editor/code/ContainerWidget.cpp
Expand Up @@ -151,3 +151,15 @@ ContainerWidget::DrawOver
itsLayout->SetHint(ToString());
LayoutWidget::DrawOver(p, rect);
}

/******************************************************************************
IsDNDLayoutTarget (virtual protected)
******************************************************************************/

bool
ContainerWidget::IsDNDLayoutTarget()
const
{
return itsLayout->IsDNDTarget();
}
2 changes: 2 additions & 0 deletions tools/jx_layout_editor/code/ContainerWidget.h
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tools/jx_layout_editor/code/InputFieldBase.cpp
Expand Up @@ -83,7 +83,7 @@ InputFieldBase::Draw
{
p.SetPenColor(JColorManager::GetWhiteColor());
p.SetFilling(true);
p.Rect(GetFrameLocal());
p.Rect(GetBounds());
}

/******************************************************************************
Expand Down
36 changes: 22 additions & 14 deletions tools/jx_layout_editor/code/LayoutContainer.cpp
Expand Up @@ -99,7 +99,7 @@ LayoutContainer::LayoutContainer
LayoutContainer::LayoutContainer
(
LayoutContainer* parent,
LayoutWidget* owner,
LayoutWidget* owner,
JXContainer* enclosure,
const HSizingOption hSizing,
const VSizingOption vSizing,
Expand All @@ -125,7 +125,6 @@ LayoutContainer::LayoutContainer
itsDropRectList(nullptr)
{
LayoutContainerX();
SetBorderWidth(1);

itsEditMenu->AttachHandlers(this,
&LayoutContainer::UpdateEditMenu,
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -1973,14 +1980,15 @@ LayoutContainer::NewUndo
void
LayoutContainer::UpdateLayoutMenu()
{
if (HasFocus() && itsParent != nullptr)
const bool hasFocus = HasFocus();
if (hasFocus && itsParent != nullptr)
{
JPtrArray<LayoutWidget> list(JPtrArrayT::kForgetAll);
GetSelectedWidgets(&list);

itsLayoutMenu->SetItemEnabled(kSelectParentCmd, !list.IsEmpty());
}
else
else if (hasFocus)
{
itsLayoutMenu->DisableItem(kSelectParentCmd);
}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
46 changes: 37 additions & 9 deletions tools/jx_layout_editor/code/LayoutWidget.cpp
Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -1022,6 +1038,18 @@ LayoutWidget::DNDFinish
}
}

/******************************************************************************
IsDNDLayoutTarget (virtual protected)
******************************************************************************/

bool
LayoutWidget::IsDNDLayoutTarget()
const
{
return false;
}

/******************************************************************************
AddPanels (virtual protected)
Expand Down
2 changes: 2 additions & 0 deletions tools/jx_layout_editor/code/LayoutWidget.h
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tools/jx_layout_editor/code/fileVersions.h
Expand Up @@ -12,8 +12,10 @@

#include <jx-af/jcore/jTypes.h>

const JFileVersion kCurrentFileVersion = 8;
const JFileVersion kCurrentFileVersion = 9;

// version 9:
// saves window min size (wtf?)
// version 8:
// addes hideBorder to RadioGroup
// version 7:
Expand Down

0 comments on commit 02dde80

Please sign in to comment.