add new style states (first,middle,last,alternate)
This commit is contained in:
parent
41c2d18b93
commit
7fc4ebd89e
|
@ -266,11 +266,10 @@ namespace Fw
|
||||||
DisabledState = 16,
|
DisabledState = 16,
|
||||||
CheckedState = 32,
|
CheckedState = 32,
|
||||||
OnState = 64,
|
OnState = 64,
|
||||||
LastState = 128
|
FirstState = 128,
|
||||||
//FirstState,
|
MiddleState = 256,
|
||||||
//MiddleState,
|
AlternateState = 512,
|
||||||
//LastState,
|
LastState = 1024,
|
||||||
//AlternateState
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum AppicationFlags {
|
enum AppicationFlags {
|
||||||
|
|
|
@ -83,6 +83,10 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("isFocused", &UIWidget::isFocused);
|
g_lua.bindClassMemberFunction<UIWidget>("isFocused", &UIWidget::isFocused);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("isHovered", &UIWidget::isHovered);
|
g_lua.bindClassMemberFunction<UIWidget>("isHovered", &UIWidget::isHovered);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("isPressed", &UIWidget::isPressed);
|
g_lua.bindClassMemberFunction<UIWidget>("isPressed", &UIWidget::isPressed);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("isFirst", &UIWidget::isFirst);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("isMiddle", &UIWidget::isMiddle);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("isLast", &UIWidget::isLast);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("isAlternate", &UIWidget::isAlternate);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("isVisible", &UIWidget::isVisible);
|
g_lua.bindClassMemberFunction<UIWidget>("isVisible", &UIWidget::isVisible);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("isHidden", &UIWidget::isHidden);
|
g_lua.bindClassMemberFunction<UIWidget>("isHidden", &UIWidget::isHidden);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("isExplicitlyEnabled", &UIWidget::isExplicitlyEnabled);
|
g_lua.bindClassMemberFunction<UIWidget>("isExplicitlyEnabled", &UIWidget::isExplicitlyEnabled);
|
||||||
|
@ -142,11 +146,6 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("getChildIndex", &UIWidget::getChildIndex);
|
g_lua.bindClassMemberFunction<UIWidget>("getChildIndex", &UIWidget::getChildIndex);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("updateParentLayout", &UIWidget::updateParentLayout);
|
g_lua.bindClassMemberFunction<UIWidget>("updateParentLayout", &UIWidget::updateParentLayout);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("updateLayout", &UIWidget::updateLayout);
|
g_lua.bindClassMemberFunction<UIWidget>("updateLayout", &UIWidget::updateLayout);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("updateStates", &UIWidget::updateStates);
|
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("updateState", &UIWidget::updateState);
|
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("setState", &UIWidget::setState);
|
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("hasState", &UIWidget::hasState);
|
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("updateStyle", &UIWidget::updateStyle);
|
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("applyStyle", &UIWidget::applyStyle);
|
g_lua.bindClassMemberFunction<UIWidget>("applyStyle", &UIWidget::applyStyle);
|
||||||
|
|
||||||
// UILayout
|
// UILayout
|
||||||
|
|
|
@ -70,7 +70,7 @@ Fw::AnchorEdge Fw::translateAnchorEdge(std::string anchorEdge)
|
||||||
Fw::WidgetState Fw::translateState(std::string state)
|
Fw::WidgetState Fw::translateState(std::string state)
|
||||||
{
|
{
|
||||||
boost::to_lower(state);
|
boost::to_lower(state);
|
||||||
boost::erase_all(state, " ");
|
boost::trim(state);
|
||||||
if(state == "active")
|
if(state == "active")
|
||||||
return Fw::ActiveState;
|
return Fw::ActiveState;
|
||||||
else if(state == "focus")
|
else if(state == "focus")
|
||||||
|
@ -85,6 +85,14 @@ Fw::WidgetState Fw::translateState(std::string state)
|
||||||
return Fw::DisabledState;
|
return Fw::DisabledState;
|
||||||
else if(state == "on")
|
else if(state == "on")
|
||||||
return Fw::OnState;
|
return Fw::OnState;
|
||||||
|
else if(state == "first")
|
||||||
|
return Fw::FirstState;
|
||||||
|
else if(state == "middle")
|
||||||
|
return Fw::MiddleState;
|
||||||
|
else if(state == "last")
|
||||||
|
return Fw::LastState;
|
||||||
|
else if(state == "alternate")
|
||||||
|
return Fw::AlternateState;
|
||||||
else
|
else
|
||||||
return Fw::InvalidState;
|
return Fw::InvalidState;
|
||||||
}
|
}
|
||||||
|
|
|
@ -422,6 +422,7 @@ void UIWidget::addChild(const UIWidgetPtr& child)
|
||||||
|
|
||||||
// update new child states
|
// update new child states
|
||||||
child->updateStates();
|
child->updateStates();
|
||||||
|
updateChildrenIndexStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWidget::insertChild(int index, const UIWidgetPtr& child)
|
void UIWidget::insertChild(int index, const UIWidgetPtr& child)
|
||||||
|
@ -454,6 +455,7 @@ void UIWidget::insertChild(int index, const UIWidgetPtr& child)
|
||||||
|
|
||||||
// update new child states
|
// update new child states
|
||||||
child->updateStates();
|
child->updateStates();
|
||||||
|
updateChildrenIndexStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWidget::removeChild(const UIWidgetPtr& child)
|
void UIWidget::removeChild(const UIWidgetPtr& child)
|
||||||
|
@ -481,6 +483,7 @@ void UIWidget::removeChild(const UIWidgetPtr& child)
|
||||||
|
|
||||||
// update child states
|
// update child states
|
||||||
child->updateStates();
|
child->updateStates();
|
||||||
|
updateChildrenIndexStates();
|
||||||
|
|
||||||
if(focusAnother && !m_focusedChild)
|
if(focusAnother && !m_focusedChild)
|
||||||
focusPreviousChild(Fw::ActiveFocusReason);
|
focusPreviousChild(Fw::ActiveFocusReason);
|
||||||
|
@ -549,6 +552,7 @@ void UIWidget::moveChildToTop(const UIWidgetPtr& child)
|
||||||
assert(it != m_children.end());
|
assert(it != m_children.end());
|
||||||
m_children.erase(it);
|
m_children.erase(it);
|
||||||
m_children.push_back(child);
|
m_children.push_back(child);
|
||||||
|
updateChildrenIndexStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWidget::moveChildToIndex(const UIWidgetPtr& child, int index)
|
void UIWidget::moveChildToIndex(const UIWidgetPtr& child, int index)
|
||||||
|
@ -561,6 +565,7 @@ void UIWidget::moveChildToIndex(const UIWidgetPtr& child, int index)
|
||||||
assert(it != m_children.end());
|
assert(it != m_children.end());
|
||||||
m_children.erase(it);
|
m_children.erase(it);
|
||||||
m_children.insert(m_children.begin() + index - 1, child);
|
m_children.insert(m_children.begin() + index - 1, child);
|
||||||
|
updateChildrenIndexStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWidget::lockChild(const UIWidgetPtr& child)
|
void UIWidget::lockChild(const UIWidgetPtr& child)
|
||||||
|
@ -663,6 +668,16 @@ void UIWidget::updateLayout()
|
||||||
m_layout->update();
|
m_layout->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
onStyleApply(styleNode);
|
||||||
|
callLuaField("onStyleApply", styleNode);
|
||||||
|
} catch(Exception& e) {
|
||||||
|
logError("Failed to apply style to widget '", m_id, "' style: ", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool UIWidget::setState(Fw::WidgetState state, bool on)
|
bool UIWidget::setState(Fw::WidgetState state, bool on)
|
||||||
{
|
{
|
||||||
if(state == Fw::InvalidState)
|
if(state == Fw::InvalidState)
|
||||||
|
@ -694,54 +709,76 @@ void UIWidget::updateState(Fw::WidgetState state)
|
||||||
bool oldStatus = hasState(state);
|
bool oldStatus = hasState(state);
|
||||||
bool updateChildren = false;
|
bool updateChildren = false;
|
||||||
|
|
||||||
if(state == Fw::ActiveState) {
|
switch(state) {
|
||||||
UIWidgetPtr widget = asUIWidget();
|
case Fw::ActiveState: {
|
||||||
UIWidgetPtr parent;
|
UIWidgetPtr widget = asUIWidget();
|
||||||
do {
|
UIWidgetPtr parent;
|
||||||
parent = widget->getParent();
|
do {
|
||||||
if(!widget->isExplicitlyEnabled() ||
|
parent = widget->getParent();
|
||||||
((parent && parent->getFocusedChild() != widget))) {
|
if(!widget->isExplicitlyEnabled() ||
|
||||||
newStatus = false;
|
((parent && parent->getFocusedChild() != widget))) {
|
||||||
break;
|
newStatus = false;
|
||||||
}
|
break;
|
||||||
} while(widget = parent);
|
}
|
||||||
|
} while(widget = parent);
|
||||||
|
|
||||||
updateChildren = true;
|
updateChildren = true;
|
||||||
}
|
break;
|
||||||
else if(state == Fw::FocusState) {
|
}
|
||||||
newStatus = (getParent() && getParent()->getFocusedChild() == asUIWidget());
|
case Fw::FocusState: {
|
||||||
}
|
newStatus = (getParent() && getParent()->getFocusedChild() == asUIWidget());
|
||||||
else if(state == Fw::HoverState) {
|
break;
|
||||||
updateChildren = true;
|
}
|
||||||
Point mousePos = g_window.getMousePos();
|
case Fw::HoverState: {
|
||||||
UIWidgetPtr widget = asUIWidget();
|
updateChildren = true;
|
||||||
UIWidgetPtr parent;
|
Point mousePos = g_window.getMousePos();
|
||||||
do {
|
UIWidgetPtr widget = asUIWidget();
|
||||||
parent = widget->getParent();
|
UIWidgetPtr parent;
|
||||||
if(!widget->isExplicitlyEnabled() || !widget->isExplicitlyVisible() || !widget->containsPoint(mousePos) ||
|
do {
|
||||||
(parent && widget != parent->getChildByPos(mousePos))) {
|
parent = widget->getParent();
|
||||||
newStatus = false;
|
if(!widget->isExplicitlyEnabled() || !widget->isExplicitlyVisible() || !widget->containsPoint(mousePos) ||
|
||||||
break;
|
(parent && widget != parent->getChildByPos(mousePos))) {
|
||||||
}
|
newStatus = false;
|
||||||
} while(widget = parent);
|
break;
|
||||||
}
|
}
|
||||||
else if(state == Fw::PressedState) {
|
} while(widget = parent);
|
||||||
newStatus = m_pressed;
|
break;
|
||||||
}
|
}
|
||||||
else if(state == Fw::DisabledState) {
|
case Fw::PressedState: {
|
||||||
bool enabled = true;
|
newStatus = m_pressed;
|
||||||
updateChildren = true;
|
break;
|
||||||
UIWidgetPtr widget = asUIWidget();
|
}
|
||||||
do {
|
case Fw::DisabledState: {
|
||||||
if(!widget->isExplicitlyEnabled()) {
|
bool enabled = true;
|
||||||
enabled = false;
|
updateChildren = true;
|
||||||
break;
|
UIWidgetPtr widget = asUIWidget();
|
||||||
}
|
do {
|
||||||
} while(widget = widget->getParent());
|
if(!widget->isExplicitlyEnabled()) {
|
||||||
newStatus = !enabled;
|
enabled = false;
|
||||||
}
|
break;
|
||||||
else {
|
}
|
||||||
return;
|
} while(widget = widget->getParent());
|
||||||
|
newStatus = !enabled;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Fw::FirstState: {
|
||||||
|
newStatus = (getParent() && getParent()->getFirstChild() == asUIWidget());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Fw::MiddleState: {
|
||||||
|
newStatus = (getParent() && getParent()->getFirstChild() != asUIWidget() && getParent()->getLastChild() != asUIWidget());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Fw::LastState: {
|
||||||
|
newStatus = (getParent() && getParent()->getLastChild() == asUIWidget());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Fw::AlternateState: {
|
||||||
|
newStatus = (getParent() && (getParent()->getChildIndex(asUIWidget()) % 2) == 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(updateChildren) {
|
if(updateChildren) {
|
||||||
|
@ -765,6 +802,16 @@ void UIWidget::updateStates()
|
||||||
updateState((Fw::WidgetState)state);
|
updateState((Fw::WidgetState)state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UIWidget::updateChildrenIndexStates()
|
||||||
|
{
|
||||||
|
for(const UIWidgetPtr& child : m_children) {
|
||||||
|
child->updateState(Fw::FirstState);
|
||||||
|
child->updateState(Fw::MiddleState);
|
||||||
|
child->updateState(Fw::LastState);
|
||||||
|
child->updateState(Fw::AlternateState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UIWidget::updateStyle()
|
void UIWidget::updateStyle()
|
||||||
{
|
{
|
||||||
if(!m_style)
|
if(!m_style)
|
||||||
|
@ -814,16 +861,6 @@ void UIWidget::updateStyle()
|
||||||
m_stateStyle = newStateStyle;
|
m_stateStyle = newStateStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIWidget::applyStyle(const OTMLNodePtr& styleNode)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
onStyleApply(styleNode);
|
|
||||||
callLuaField("onStyleApply", styleNode);
|
|
||||||
} catch(Exception& e) {
|
|
||||||
logError("Failed to apply style to widget '", m_id, "' style: ", e.what());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
|
void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
|
||||||
{
|
{
|
||||||
// first set id
|
// first set id
|
||||||
|
|
|
@ -84,49 +84,53 @@ public:
|
||||||
void grabKeyboard();
|
void grabKeyboard();
|
||||||
void ungrabKeyboard();
|
void ungrabKeyboard();
|
||||||
|
|
||||||
bool isActive() { return hasState(Fw::ActiveState); }
|
bool isActive() { return hasState(Fw::ActiveState); }
|
||||||
bool isEnabled() { return !hasState(Fw::DisabledState); }
|
bool isEnabled() { return !hasState(Fw::DisabledState); }
|
||||||
bool isDisabled() { return hasState(Fw::DisabledState); }
|
bool isDisabled() { return hasState(Fw::DisabledState); }
|
||||||
bool isFocused() { return hasState(Fw::FocusState); }
|
bool isFocused() { return hasState(Fw::FocusState); }
|
||||||
bool isHovered() { return hasState(Fw::HoverState); }
|
bool isHovered() { return hasState(Fw::HoverState); }
|
||||||
bool isPressed() { return hasState(Fw::PressedState); }
|
bool isPressed() { return hasState(Fw::PressedState); }
|
||||||
|
bool isFirst() { return hasState(Fw::FirstState); }
|
||||||
|
bool isMiddle() { return hasState(Fw::MiddleState); }
|
||||||
|
bool isLast() { return hasState(Fw::LastState); }
|
||||||
|
bool isAlternate() { return hasState(Fw::AlternateState); }
|
||||||
bool isVisible();
|
bool isVisible();
|
||||||
bool isHidden() { return !isVisible(); }
|
bool isHidden() { return !isVisible(); }
|
||||||
bool isExplicitlyEnabled() { return m_enabled; }
|
bool isExplicitlyEnabled() { return m_enabled; }
|
||||||
bool isExplicitlyVisible() { return m_visible; }
|
bool isExplicitlyVisible() { return m_visible; }
|
||||||
bool isFocusable() { return m_focusable; }
|
bool isFocusable() { return m_focusable; }
|
||||||
bool isPhantom() { return m_phantom; }
|
bool isPhantom() { return m_phantom; }
|
||||||
bool isSizeFixed() { return m_fixedSize; }
|
bool isSizeFixed() { return m_fixedSize; }
|
||||||
bool containsPoint(const Point& point) { return m_rect.contains(point); }
|
bool containsPoint(const Point& point) { return m_rect.contains(point); }
|
||||||
bool hasChildren() { return m_children.size() > 0; }
|
bool hasChildren() { return m_children.size() > 0; }
|
||||||
bool hasChild(const UIWidgetPtr& child);
|
bool hasChild(const UIWidgetPtr& child);
|
||||||
|
|
||||||
std::string getId() { return m_id; }
|
std::string getId() { return m_id; }
|
||||||
int getChildCount() { return m_children.size(); }
|
int getChildCount() { return m_children.size(); }
|
||||||
UILayoutPtr getLayout() { return m_layout; }
|
UILayoutPtr getLayout() { return m_layout; }
|
||||||
UIWidgetPtr getParent() { return m_parent.lock(); }
|
UIWidgetPtr getParent() { return m_parent.lock(); }
|
||||||
UIWidgetPtr getRootParent();
|
UIWidgetPtr getRootParent();
|
||||||
Point getPosition() { return m_rect.topLeft(); }
|
Point getPosition() { return m_rect.topLeft(); }
|
||||||
Size getSize() { return m_rect.size(); }
|
Size getSize() { return m_rect.size(); }
|
||||||
Rect getRect() { return m_rect; }
|
Rect getRect() { return m_rect; }
|
||||||
int getX() { return m_rect.x(); }
|
int getX() { return m_rect.x(); }
|
||||||
int getY() { return m_rect.y(); }
|
int getY() { return m_rect.y(); }
|
||||||
int getWidth() { return m_rect.width(); }
|
int getWidth() { return m_rect.width(); }
|
||||||
int getHeight() { return m_rect.height(); }
|
int getHeight() { return m_rect.height(); }
|
||||||
ImagePtr getImage() { return m_image; }
|
ImagePtr getImage() { return m_image; }
|
||||||
FontPtr getFont() { return m_font; }
|
FontPtr getFont() { return m_font; }
|
||||||
Color getForegroundColor() { return m_foregroundColor; }
|
Color getForegroundColor() { return m_foregroundColor; }
|
||||||
Color getBackgroundColor() { return m_backgroundColor; }
|
Color getBackgroundColor() { return m_backgroundColor; }
|
||||||
int getOpacity() { return m_opacity; }
|
int getOpacity() { return m_opacity; }
|
||||||
int getMarginTop() { return m_marginTop; }
|
int getMarginTop() { return m_marginTop; }
|
||||||
int getMarginRight() { return m_marginRight; }
|
int getMarginRight() { return m_marginRight; }
|
||||||
int getMarginBottom() { return m_marginBottom; }
|
int getMarginBottom() { return m_marginBottom; }
|
||||||
int getMarginLeft() { return m_marginLeft; }
|
int getMarginLeft() { return m_marginLeft; }
|
||||||
Fw::FocusReason getLastFocusReason() { return m_lastFocusReason; }
|
Fw::FocusReason getLastFocusReason() { return m_lastFocusReason; }
|
||||||
OTMLNodePtr getStyle() { return m_style; }
|
OTMLNodePtr getStyle() { return m_style; }
|
||||||
|
|
||||||
UIWidgetList getChildren() { return m_children; }
|
UIWidgetList getChildren() { return m_children; }
|
||||||
UIWidgetPtr getFocusedChild() { return m_focusedChild; }
|
UIWidgetPtr getFocusedChild() { return m_focusedChild; }
|
||||||
UIWidgetPtr getChildAfter(const UIWidgetPtr& relativeChild);
|
UIWidgetPtr getChildAfter(const UIWidgetPtr& relativeChild);
|
||||||
UIWidgetPtr getChildBefore(const UIWidgetPtr& relativeChild);
|
UIWidgetPtr getChildBefore(const UIWidgetPtr& relativeChild);
|
||||||
UIWidgetPtr getChildById(const std::string& childId);
|
UIWidgetPtr getChildById(const std::string& childId);
|
||||||
|
@ -153,17 +157,21 @@ public:
|
||||||
|
|
||||||
void updateParentLayout();
|
void updateParentLayout();
|
||||||
void updateLayout();
|
void updateLayout();
|
||||||
|
|
||||||
void updateStates();
|
|
||||||
virtual void updateState(Fw::WidgetState state);
|
|
||||||
bool setState(Fw::WidgetState state, bool on);
|
|
||||||
bool hasState(Fw::WidgetState state);
|
|
||||||
|
|
||||||
void updateStyle();
|
|
||||||
void applyStyle(const OTMLNodePtr& styleNode);
|
void applyStyle(const OTMLNodePtr& styleNode);
|
||||||
|
|
||||||
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
|
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool setState(Fw::WidgetState state, bool on);
|
||||||
|
bool hasState(Fw::WidgetState state);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateState(Fw::WidgetState state);
|
||||||
|
void updateStates();
|
||||||
|
void updateChildrenIndexStates();
|
||||||
|
|
||||||
|
void updateStyle();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Triggered when widget style is changed
|
/// Triggered when widget style is changed
|
||||||
virtual void onStyleApply(const OTMLNodePtr& styleNode);
|
virtual void onStyleApply(const OTMLNodePtr& styleNode);
|
||||||
|
|
Loading…
Reference in New Issue