Skip to content

Commit

Permalink
Add number input control
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Dec 14, 2020
1 parent e0797b3 commit 00be778
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 27 deletions.
21 changes: 15 additions & 6 deletions Projects/Editor/Source/Editor/Space/Property/CSpaceProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,18 @@ namespace Skylicht

boxLayout = new GUI::CBoxLayout(transformColapsible);
boxLayout->setPadding(GUI::SPadding(5.0, 5.0, 5.0, 5.0));
addText(boxLayout, L"Position X", L"0.0");
addText(boxLayout, L"Y", L"0.0");
addText(boxLayout, L"Z", L"0.0");

addNumberInput(boxLayout, L"Position X", L"0.0");
addNumberInput(boxLayout, L"Y", L"0.0");
addNumberInput(boxLayout, L"Z", L"0.0");
boxLayout->addSpace(5.0f);
addNumberInput(boxLayout, L"Rotation(Deg) X", L"0.0");
addNumberInput(boxLayout, L"Y", L"0.0");
addNumberInput(boxLayout, L"Z", L"0.0");
boxLayout->addSpace(5.0f);
addNumberInput(boxLayout, L"Scale X", L"1.0");
addNumberInput(boxLayout, L"Y", L"1.0");
addNumberInput(boxLayout, L"Z", L"1.0");

transformColapsible->setExpand(true);

Expand All @@ -81,7 +90,7 @@ namespace Skylicht

}

void CSpaceProperty::addText(GUI::CBoxLayout* boxLayout, wchar_t* name, wchar_t* value)
void CSpaceProperty::addNumberInput(GUI::CBoxLayout* boxLayout, wchar_t* name, wchar_t* value)
{
GUI::CLayout* layout = boxLayout->beginVertical();

Expand All @@ -90,8 +99,8 @@ namespace Skylicht
label->setString(name);
label->setTextAlignment(GUI::TextRight);

GUI::CTextBox* text = new GUI::CTextBox(layout);
text->setString(value);
GUI::CNumberInput* input = new GUI::CNumberInput(layout);
input->setString(value);

boxLayout->endVertical();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Skylicht

virtual ~CSpaceProperty();

void addText(GUI::CBoxLayout* boxLayout, wchar_t* name, wchar_t* value);
void addNumberInput(GUI::CBoxLayout* boxLayout, wchar_t* name, wchar_t* value);
};
}
}
7 changes: 7 additions & 0 deletions Projects/Editor/Source/GUI/Controls/CBoxLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ namespace Skylicht
#endif
}

void CBoxLayout::addSpace(float height)
{
CBase* space = new CBase(m_layoutStack.top());
space->dock(EPosition::Top);
space->setHeight(height);
}

CLayoutVertical* CBoxLayout::beginVertical()
{
CBase* parent = m_layoutStack.top();
Expand Down
2 changes: 2 additions & 0 deletions Projects/Editor/Source/GUI/Controls/CBoxLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ namespace Skylicht

void endHorizontal();

void addSpace(float height);

CLayoutVertical* beginVertical();

void endVertical();
Expand Down
60 changes: 60 additions & 0 deletions Projects/Editor/Source/GUI/Controls/CNumberInput.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
!@
MIT License
Copyright (c) 2020 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#include "pch.h"
#include "CNumberInput.h"

namespace Skylicht
{
namespace Editor
{
namespace GUI
{
CNumberInput::CNumberInput(CBase* base) :
CTextBox(base)
{
m_textContainer->setTextAlignment(ETextAlign::TextCenter);
}

CNumberInput::~CNumberInput()
{

}

bool CNumberInput::onChar(u32 c)
{
if ((c >= '0' && c <= '9') || c == '.' || c == '\b')
{
return CTextBox::onChar(c);
}
else if (c == '\r')
{
return true;
}

return false;
}
}
}
}
45 changes: 45 additions & 0 deletions Projects/Editor/Source/GUI/Controls/CNumberInput.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
!@
MIT License
Copyright (c) 2020 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/
#pragma once

#include "CTextBox.h"

namespace Skylicht
{
namespace Editor
{
namespace GUI
{
class CNumberInput : public CTextBox
{
public:
CNumberInput(CBase* base);

virtual ~CNumberInput();

virtual bool onChar(u32 c);
};
}
}
}
22 changes: 13 additions & 9 deletions Projects/Editor/Source/GUI/Controls/CTextBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Skylicht
{
namespace GUI
{
CTextBox::CTextBox(CBase *base) :
CTextBox::CTextBox(CBase* base) :
CScrollControl(base),
m_press(false),
m_editable(true),
Expand Down Expand Up @@ -114,7 +114,7 @@ namespace Skylicht
{
if (m_drawTextbox)
{
CTheme *theme = CTheme::getTheme();
CTheme* theme = CTheme::getTheme();
theme->drawTextbox(getRenderBounds(), m_textBoxColor);

if (m_textContainer->isActivate())
Expand Down Expand Up @@ -389,6 +389,10 @@ namespace Skylicht
if (m_textContainer->isWrapMultiline())
m_textContainer->doInsertCharacter('\n');
}
else if (c == '\t')
{
m_textContainer->doInsertCharacter(' ');
}
else
{
m_textContainer->doInsertCharacter(c);
Expand All @@ -408,7 +412,7 @@ namespace Skylicht

void CTextBox::scrollToLine(u32 line, u32 pos)
{
CText *text = m_textContainer->getLine(line);
CText* text = m_textContainer->getLine(line);

SDimension s = text->getCharacterPosition(pos);
SPoint localCaretPosition(s.Width, 0.0f);
Expand Down Expand Up @@ -513,15 +517,15 @@ namespace Skylicht
m_textContainer->resetCaretBlink();
}

void CTextBox::onCopy(CBase *base)
void CTextBox::onCopy(CBase* base)
{
std::wstring data;
m_textContainer->getSelectString(data);
if (data.size() > 0)
CClipboard::get()->copyTextToClipboard(data);
}

void CTextBox::onCut(CBase *base)
void CTextBox::onCut(CBase* base)
{
if (m_editable)
{
Expand All @@ -535,7 +539,7 @@ namespace Skylicht
}
}

void CTextBox::onPaste(CBase *base)
void CTextBox::onPaste(CBase* base)
{
if (m_editable)
{
Expand All @@ -555,7 +559,7 @@ namespace Skylicht
}
}

void CTextBox::onSelectAll(CBase *base)
void CTextBox::onSelectAll(CBase* base)
{
m_textContainer->setCaretEnd(0, 0);

Expand All @@ -566,7 +570,7 @@ namespace Skylicht
scrollToLine(line, pos);
}

void CTextBox::onOpenMenuContext(CBase *base)
void CTextBox::onOpenMenuContext(CBase* base)
{
if (base != m_contextMenu)
return;
Expand All @@ -583,7 +587,7 @@ namespace Skylicht
}
}

void CTextBox::onOpenMenuCommand(CBase *base)
void CTextBox::onOpenMenuCommand(CBase* base)
{
CMenuItem* item = dynamic_cast<CMenuItem*>(base);
if (item != NULL)
Expand Down
22 changes: 11 additions & 11 deletions Projects/Editor/Source/GUI/Controls/CTextBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ namespace Skylicht
class CTextBox : public CScrollControl
{
protected:
CIcon *m_icon;
CTextContainer *m_textHint;
CTextContainer *m_textContainer;
CMenu *m_contextMenu;
CIcon* m_icon;
CTextContainer* m_textHint;
CTextContainer* m_textContainer;
CMenu* m_contextMenu;

bool m_press;
bool m_editable;
Expand All @@ -53,7 +53,7 @@ namespace Skylicht
SGUIColor m_textBoxColor;

public:
CTextBox(CBase *base);
CTextBox(CBase* base);

virtual ~CTextBox();

Expand Down Expand Up @@ -89,17 +89,17 @@ namespace Skylicht

void hideIcon();

void onCopy(CBase *base);
void onCopy(CBase* base);

void onCut(CBase *base);
void onCut(CBase* base);

void onPaste(CBase *base);
void onPaste(CBase* base);

void onSelectAll(CBase *base);
void onSelectAll(CBase* base);

void onOpenMenuContext(CBase *base);
void onOpenMenuContext(CBase* base);

void onOpenMenuCommand(CBase *base);
void onOpenMenuCommand(CBase* base);

inline void setString(const std::wstring& string)
{
Expand Down
1 change: 1 addition & 0 deletions Projects/Editor/Source/GUI/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ This file is part of the "Skylicht Engine".
#include "GUI/Controls/CTableRow.h"
#include "GUI/Controls/CToolbar.h"
#include "GUI/Controls/CTextBox.h"
#include "GUI/Controls/CNumberInput.h"
#include "GUI/Controls/CCollapsibleGroup.h"
#include "GUI/Controls/CBoxLayout.h"

0 comments on commit 00be778

Please sign in to comment.