Skip to content

Commit

Permalink
#6 Implement draw keyboard focus/unfocus
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Nov 20, 2020
1 parent 8eb88bd commit 799b3c3
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 7 deletions.
1 change: 1 addition & 0 deletions Projects/Editor/Source/GUI/Controls/CBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace Skylicht
m_renderFillRect(false),
m_fillRectColor(CThemeConfig::WindowInnerColor),
m_accelOnlyFocus(true),
m_keyboardFocus(false),
m_debugValue(0),
m_tagInt(0),
m_tagFloat(0.0f),
Expand Down
18 changes: 16 additions & 2 deletions Projects/Editor/Source/GUI/Controls/CBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,20 @@ namespace Skylicht
virtual void onMouseEnter();
virtual void onMouseLeave();

virtual void onLostKeyboardFocus() {}
virtual void onKeyboardFocus() {}
virtual void onLostKeyboardFocus()
{
m_keyboardFocus = false;
}

virtual void onKeyboardFocus()
{
m_keyboardFocus = true;
}

inline bool isKeyboardFocus()
{
return m_keyboardFocus;
}

virtual void setTransparentMouseInput(bool b) { m_transparentMouseInput = b; }
virtual void setMouseInputEnabled(bool b) { m_mouseInputEnabled = b; }
Expand Down Expand Up @@ -514,6 +526,8 @@ namespace Skylicht
std::wstring m_tagWString;
void *m_tagData;

bool m_keyboardFocus;

AccelMap m_accelerators;
bool m_accelOnlyFocus;
};
Expand Down
2 changes: 1 addition & 1 deletion Projects/Editor/Source/GUI/Controls/CListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Skylicht
CListBox::CListBox(CBase *parent) :
CScrollControl(parent)
{

setKeyboardInputEnabled(true);
}

CListBox::~CListBox()
Expand Down
13 changes: 11 additions & 2 deletions Projects/Editor/Source/GUI/Controls/CListRowItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ namespace Skylicht
namespace GUI
{
CListRowItem::CListRowItem(CBase *base) :
CButton(base)
CButton(base),
m_owner(base)
{
setIsToggle(true);

setHoverColor(CThemeConfig::ListItemBackgroundHoverColor);
setPressColor(CThemeConfig::ListItemBackgroundFocusColor);

m_icon->setMargin(SMargin(0.0f, 0.0f, 5.0f, 0.0f));
m_label->setMargin(SMargin(0.0f, 4.0f, 0.0f, 0.0f));
m_label->setColor(CThemeConfig::ButtonTextColor);
Expand Down Expand Up @@ -89,7 +93,12 @@ namespace Skylicht
if (isToggle())
{
if (m_toggleStatus)
c = m_pressColor;
{
if (m_owner->isKeyboardFocus() == true)
c = m_pressColor;
else
c = CThemeConfig::ListItemBackgroundUnfocusColor;
}
}

SRect r = getRenderBounds();
Expand Down
1 change: 1 addition & 0 deletions Projects/Editor/Source/GUI/Controls/CListRowItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace Skylicht
class CListRowItem : public CButton
{
protected:
CBase *m_owner;

public:
CListRowItem(CBase *base);
Expand Down
4 changes: 4 additions & 0 deletions Projects/Editor/Source/GUI/Controls/CTextBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,17 @@ namespace Skylicht
if (m_editable)
m_textContainer->showCaret(true);
m_textContainer->setActivate(true);

CScrollControl::onKeyboardFocus();
}

void CTextBox::onLostKeyboardFocus()
{
if (m_editable)
m_textContainer->showCaret(false);
m_textContainer->setActivate(false);

CScrollControl::onLostKeyboardFocus();
}

bool CTextBox::onKeyPress(EKey key, bool press)
Expand Down
1 change: 1 addition & 0 deletions Projects/Editor/Source/GUI/Controls/CTreeControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace Skylicht
m_innerPanel = m_scrollControl->getInnerPanel();

setTransparentMouseInput(false);
setKeyboardInputEnabled(true);
}

CTreeControl::~CTreeControl()
Expand Down
11 changes: 10 additions & 1 deletion Projects/Editor/Source/GUI/Controls/CTreeRowItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This file is part of the "Skylicht Engine".
#include "pch.h"
#include "CTreeRowItem.h"
#include "CTreeNode.h"
#include "GUI/Theme/CThemeConfig.h"

namespace Skylicht
{
Expand All @@ -37,6 +38,9 @@ namespace Skylicht
m_root(root)
{
setIsToggle(true);

setHoverColor(CThemeConfig::ListItemBackgroundHoverColor);
setPressColor(CThemeConfig::ListItemBackgroundFocusColor);
}

CTreeRowItem::~CTreeRowItem()
Expand Down Expand Up @@ -68,7 +72,12 @@ namespace Skylicht
if (isToggle())
{
if (m_toggleStatus)
c = m_pressColor;
{
if (m_root->isKeyboardFocus() == true)
c = m_pressColor;
else
c = CThemeConfig::ListItemBackgroundUnfocusColor;
}
}

SRect r = getRenderBounds();
Expand Down
4 changes: 4 additions & 0 deletions Projects/Editor/Source/GUI/Theme/CThemeConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ namespace Skylicht
SGUIColor CThemeConfig::ScrollBarBarColor = ButtonColor;
SGUIColor CThemeConfig::ScrollBarBarHoverColor = ButtonHoverColor;

SGUIColor CThemeConfig::ListItemBackgroundHoverColor = SGUIColor(100, 110, 110, 110);
SGUIColor CThemeConfig::ListItemBackgroundFocusColor = ButtonPressColor;
SGUIColor CThemeConfig::ListItemBackgroundUnfocusColor = SGUIColor(100, 80, 120, 180);

float CThemeConfig::TreeIndentationSize = 25.0f;

float CThemeConfig::getFontSizePt(EFontSize size)
Expand Down
6 changes: 5 additions & 1 deletion Projects/Editor/Source/GUI/Theme/CThemeConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Skylicht

static SGUIColor WindowBackgroundColor;
static SGUIColor WindowInnerColor;
static SGUIColor DefaultTextColor;
static SGUIColor DefaultTextColor;
static SGUIColor DisableTextColor;
static SGUIColor DefaultIconColor;
static SGUIColor IconPressColor;
Expand Down Expand Up @@ -83,6 +83,10 @@ namespace Skylicht
static SGUIColor ScrollBarBarColor;
static SGUIColor ScrollBarBarHoverColor;

static SGUIColor ListItemBackgroundHoverColor;
static SGUIColor ListItemBackgroundFocusColor;
static SGUIColor ListItemBackgroundUnfocusColor;

static float getFontSizePt(EFontSize size);

static float TreeIndentationSize;
Expand Down

0 comments on commit 799b3c3

Please sign in to comment.