Skip to content

Commit

Permalink
jx_layout_editor: integer & float input
Browse files Browse the repository at this point in the history
  • Loading branch information
jafl committed Jan 16, 2024
1 parent 3bb4c5a commit 4fbb858
Show file tree
Hide file tree
Showing 38 changed files with 1,620 additions and 566 deletions.
7 changes: 0 additions & 7 deletions todo-jxlayout
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
JXStaticText
text
center

snap-to-grid for bottom & right is offset

generate code when save
Expand Down Expand Up @@ -35,8 +31,6 @@ JXImageRadioButton
JXProgressIndicator
JXCharInput
JXFileInput
JXFloatInput
JXIntegerInput
JXPasswordInput
same as JXInputField
JXPathInput
Expand All @@ -47,7 +41,6 @@ JXSlider

-----

JXWidgetSet
JXScrollbarSet
JXToolBar
JXRadioGroup
Expand Down
11 changes: 8 additions & 3 deletions tools/jx_layout_editor/Make.files
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@
.cpp ./code/ChooseWidgetDialog
.cpp ./code/BaseWidget
.cpp ./code/CustomWidget
.cpp ./code/WidgetSet
.cpp ./code/CoreWidget
.cpp ./code/FloatInput
.cpp ./code/InputFieldBase
.cpp ./code/InputField
.cpp ./code/IntegerInput
.cpp ./code/StaticText
.cpp ./code/TextButtonBase
.cpp ./code/TextButton
.cpp ./code/TextCheckbox
.cpp ./code/StaticText
.cpp ./code/InputField
.cpp ./code/WidgetSet
.cpp ./code/WidgetParametersDialog
.cpp ./code/WidgetPanelBase
.cpp ./code/CustomWidgetPanel
.cpp ./code/WidgetLabelPanel
.cpp ./code/FileInputPanel
.cpp ./code/FloatInputPanel
.cpp ./code/InputFieldPanel
.cpp ./code/IntegerInputPanel
.cpp ./code/PathInputPanel
.cpp ./code/SaveFileInputPanel
.cpp ./code/StaticTextPanel
Expand Down
2 changes: 2 additions & 0 deletions tools/jx_layout_editor/code/ChooseWidgetDialog-Widget-enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ enum {
kCustomWidgetIndex=1,
kStaticTextIndex,
kInputFieldIndex,
kIntegerInputIndex,
kFloatInputIndex,
kTextButtonIndex,
kTextCheckboxIndex,
kWidgetSetIndex,
Expand Down
4 changes: 3 additions & 1 deletion tools/jx_layout_editor/code/ChooseWidgetDialog-Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
static const JUtf8Byte* kWidgetMenuStr =
"* %i __CustomWidget::ChooseWidgetDialog %l"
"|* %i __StaticText::ChooseWidgetDialog %l"
"|* %i __InputField::ChooseWidgetDialog %l"
"|* %i __InputField::ChooseWidgetDialog"
"|* %i __IntegerInput::ChooseWidgetDialog"
"|* %i __FloatInput::ChooseWidgetDialog %l"
"|* %i __TextButton::ChooseWidgetDialog"
"|* %i __TextCheckbox::ChooseWidgetDialog %l"
"|* %i __WidgetSet::ChooseWidgetDialog"
Expand Down
20 changes: 20 additions & 0 deletions tools/jx_layout_editor/code/ChooseWidgetDialog-Widget.jxm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ jx_menu_editor 0
'
"__InputField"
"kInputFieldIndex"
0

1
0
0 ""
"Integer input"
""
'
"__IntegerInput"
"kIntegerInputIndex"
0

1
0
0 ""
"Float input"
""
'
"__FloatInput"
"kFloatInputIndex"
1

1
Expand Down
1 change: 0 additions & 1 deletion tools/jx_layout_editor/code/CustomWidgetPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
class JString;
class JXInputField;
class JXTextCheckbox;
class WidgetParametersDialog;

class CustomWidgetPanel : public WidgetPanelBase
{
Expand Down
1 change: 0 additions & 1 deletion tools/jx_layout_editor/code/FileInputPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "WidgetPanelBase.h"

class JXTextCheckbox;
class WidgetParametersDialog;

class FileInputPanel : public WidgetPanelBase
{
Expand Down
215 changes: 215 additions & 0 deletions tools/jx_layout_editor/code/FloatInput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/******************************************************************************
FloatInput.cpp
BASE CLASS = InputFieldBase
Copyright (C) 2023 by John Lindal.
******************************************************************************/

#include "FloatInput.h"
#include "FloatInputPanel.h"
#include "LayoutContainer.h"
#include <jx-af/jx/JXWindowPainter.h>
#include <jx-af/jx/jXPainterUtil.h>
#include <jx-af/jcore/JColorManager.h>
#include <jx-af/jcore/jGlobals.h>
#include <jx-af/jcore/jAssert.h>

/******************************************************************************
Constructor
******************************************************************************/

FloatInput::FloatInput
(
LayoutContainer* layout,
const HSizingOption hSizing,
const VSizingOption vSizing,
const JCoordinate x,
const JCoordinate y,
const JCoordinate w,
const JCoordinate h
)
:
InputFieldBase(layout, hSizing, vSizing, x,y, w,h),
itsIsRequiredFlag(false),
itsHasMinValue(false),
itsMinValue(0.0),
itsHasMaxValue(false),
itsMaxValue(0.0)
{
}

FloatInput::FloatInput
(
std::istream& input,
LayoutContainer* layout,
const HSizingOption hSizing,
const VSizingOption vSizing,
const JCoordinate x,
const JCoordinate y,
const JCoordinate w,
const JCoordinate h
)
:
InputFieldBase(input, layout, hSizing, vSizing, x,y, w,h)
{
input >> itsIsRequiredFlag;
input >> itsHasMinValue >> itsMinValue;
input >> itsHasMaxValue >> itsMaxValue;
}

/******************************************************************************
Destructor
******************************************************************************/

FloatInput::~FloatInput()
{
}

/******************************************************************************
StreamOut (virtual)
******************************************************************************/

void
FloatInput::StreamOut
(
std::ostream& output
)
const
{
output << JString("FloatInput") << std::endl;

InputFieldBase::StreamOut(output);

output << itsIsRequiredFlag << std::endl;
output << itsHasMinValue << ' ' << itsMinValue << std::endl;
output << itsHasMaxValue << ' ' << itsMaxValue << std::endl;
}

/******************************************************************************
ToString (virtual)
******************************************************************************/

JString
FloatInput::ToString()
const
{
JString s = InputFieldBase::ToString();

if (itsIsRequiredFlag)
{
s += JString::newline;
s += JGetString("RequiredLabel::InputField");
}

if (itsHasMinValue)
{
s += JString::newline;
s += JGetString("MinValueLabel::InputField");
s += JString(itsMinValue);
}

if (itsHasMaxValue)
{
s += JString::newline;
s += JGetString("MaxValueLabel::InputField");
s += JString(itsMaxValue);
}

return s;
}

/******************************************************************************
GetClassName (virtual protected)
******************************************************************************/

JString
FloatInput::GetClassName()
const
{
return "JXFloatInput";
}

/******************************************************************************
PrintConfiguration (virtual protected)
******************************************************************************/

void
FloatInput::PrintConfiguration
(
std::ostream& output,
const JString& indent,
const JString& varName,
JStringManager* stringdb
)
const
{
bool used = false;

if (itsIsRequiredFlag)
{
indent.Print(output);
varName.Print(output);
output << "->SetIsRequired();" << std::endl;
used = true;
}

if (itsHasMinValue)
{
indent.Print(output);
varName.Print(output);
output << "->SetLowerLimit(" << itsMinValue << ");" << std::endl;
used = true;
}

if (itsHasMaxValue)
{
indent.Print(output);
varName.Print(output);
output << "->SetUpperLimit(" << itsMaxValue << ");" << std::endl;
used = true;
}

if (!used)
{
InputFieldBase::PrintConfiguration(output, indent, varName, stringdb);
}
}

/******************************************************************************
AddPanels (virtual protected)
******************************************************************************/

void
FloatInput::AddPanels
(
WidgetParametersDialog* dlog
)
{
itsPanel =
jnew FloatInputPanel(dlog, itsIsRequiredFlag,
itsHasMinValue, itsMinValue,
itsHasMaxValue, itsMaxValue);
}

/******************************************************************************
SavePanelData (virtual protected)
******************************************************************************/

void
FloatInput::SavePanelData()
{
itsPanel->GetValues(&itsIsRequiredFlag,
&itsHasMinValue, &itsMinValue,
&itsHasMaxValue, &itsMaxValue);
itsPanel = nullptr;
}
54 changes: 54 additions & 0 deletions tools/jx_layout_editor/code/FloatInput.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/******************************************************************************
FloatInput.h
Copyright (C) 2023 by John Lindal.
******************************************************************************/

#ifndef _H_FloatInput
#define _H_FloatInput

#include "InputFieldBase.h"

class FloatInputPanel;

class FloatInput : public InputFieldBase
{
public:

FloatInput(LayoutContainer* layout,
const HSizingOption hSizing, const VSizingOption vSizing,
const JCoordinate x, const JCoordinate y,
const JCoordinate w, const JCoordinate h);
FloatInput(std::istream& input, LayoutContainer* layout,
const HSizingOption hSizing, const VSizingOption vSizing,
const JCoordinate x, const JCoordinate y,
const JCoordinate w, const JCoordinate h);

~FloatInput() override;

void StreamOut(std::ostream& output) const override;
JString ToString() const override;

protected:

JString GetClassName() const override;
void PrintConfiguration(std::ostream& output,
const JString& indent,
const JString& varName,
JStringManager* stringdb) const override;

void AddPanels(WidgetParametersDialog* dlog) override;
void SavePanelData() override;

private:

bool itsIsRequiredFlag;
bool itsHasMinValue;
JFloat itsMinValue;
bool itsHasMaxValue;
JFloat itsMaxValue;
FloatInputPanel* itsPanel; // nullptr unless editing
};

#endif
Loading

0 comments on commit 4fbb858

Please sign in to comment.