diff --git a/include/eepp/ui/css/propertydefinition.hpp b/include/eepp/ui/css/propertydefinition.hpp index 6b408e731..689594736 100644 --- a/include/eepp/ui/css/propertydefinition.hpp +++ b/include/eepp/ui/css/propertydefinition.hpp @@ -96,14 +96,90 @@ enum class PropertyId : Uint32 { Src = String::hash( "src" ), ScaleType = String::hash( "scale-type" ), Tint = String::hash( "tint" ), - // Possible shorthand - Background = String::hash( "background" ), - Foreground = String::hash( "foreground" ), - Padding = String::hash( "padding" ), BackgroundPosition = String::hash( "background-position" ), ForegroundPosition = String::hash( "foreground-position" ), RotationOriginPoint = String::hash( "rotation-origin-point" ), - ScaleOriginPoint = String::hash( "scale-origin-point" ) + ScaleOriginPoint = String::hash( "scale-origin-point" ), + MaxTextLength = String::hash( "max-text-length" ), + MinTabWidth = String::hash( "min-tab-width" ), + MaxTabWidth = String::hash( "max-tab-width" ), + TabClosable = String::hash( "tab-closable" ), + SpecialBorderTabs = String::hash( "special-border-tabs" ), + LineBelowTabs = String::hash( "line-below-tabs" ), + LineBelowTabsColor = String::hash( "line-below-tabs-color" ), + LineBelowTabsYOffset = String::hash( "line-below-tabs-y-offset" ), + TabSeparation = String::hash( "tax-separation" ), + Selected = String::hash( "selected" ), + PopUpToMainControl = String::hash( "popup-to-main-control" ), + MaxVisibleItems = String::hash( "max-visible-items" ), + SelectedIndex = String::hash( "selected-index" ), + SelectedText = String::hash( "selected-text" ), + ScrollBarType = String::hash( "scrollbar-type" ), + RowHeight = String::hash( "row-height" ), + VScrollMode = String::hash( "vscroll-mode" ), + HScrollMode = String::hash( "hscroll-mode" ), + ColumnSpan = String::hash( "column-span" ), + RowSpan = String::hash( "row-span" ), + Span = String::hash( "span" ), + ColumnMode = String::hash( "column-mode" ), + RowMode = String::hash( "row-mode" ), + ColumnWeight = String::hash( "column-weight" ), + ColumnHeight = String::hash( "column-height" ), + ColumnWidth = String::hash( "column-width" ), + RowWeight = String::hash( "row-weight" ), + ReverseDraw = String::hash( "reverse-draw" ), + Orientation = String::hash( "orientation" ), + Indeterminate = String::hash( "indeterminate" ), + MaxProgress = String::hash( "max-progress" ), + Progress = String::hash( "progress" ), + FillColor = String::hash( "fill-color" ), + Radius = String::hash( "radius" ), + OutlineThickness = String::hash( "outline-thickness" ), + AnimationSpeed = String::hash( "animation-speed" ), + ArcStartAngle = String::hash( "arc-start-angle" ), + MinWidth = String::hash( "min-width" ), + MinMarginRight = String::hash( "min-margin-right" ), + MinIconSpace = String::hash( "min-icon-space" ), + TotalSteps = String::hash( "total-steps" ), + VerticalExpand = String::hash( "vertical-expand" ), + DisplayPercent = String::hash( "display-percent" ), + FillerPaddingLeft = String::hash( "filler-padding-left" ), + FillerPaddingTop = String::hash( "filler-padding-top" ), + FillerPaddingRight = String::hash( "filler-padding-right" ), + FillerPaddingBottom = String::hash( "filler-padding-bottom" ), + MovementSpeed = String::hash( "movement-speed" ), + MinValue = String::hash( "min-value" ), + MaxValue = String::hash( "max-value" ), + Value = String::hash( "value" ), + ClickStep = String::hash( "click-step" ), + PageStep = String::hash( "page-step" ), + BackgroundExpand = String::hash( "background-expand" ), + ScrollBarMode = String::hash( "scrollbar-mode" ), + HalfSlider = String::hash( "half-slider" ), + Name = String::hash( "name" ), + Owns = String::hash( "owns" ), + AllowEditing = String::hash( "allow-editing" ), + MaxLength = String::hash( "max-length" ), + FreeEditing = String::hash( "free-editing" ), + OnlyNumbers = String::hash( "only-numbers" ), + AllowDot = String::hash( "allow-dot" ), + TouchDrag = String::hash( "touch-drag" ), + TouchDragDeceleration = String::hash( "touch-drag-deceleration" ), + Title = String::hash( "title" ), + BaseAlpha = String::hash( "base-alpha" ), + ButtonsPositionOffset = String::hash( "buttons-position-offset" ), + WindowFlags = String::hash( "window-flags" ), + DecorationSize = String::hash( "decoration-size" ), + BorderSize = String::hash( "border-size" ), + MinWindowSize = String::hash( "min-window-size" ), + ButtonsSeparation = String::hash( "buttons-separation" ), + MinCornerDistance = String::hash( "min-corner-distance" ), + DecorationAutoSize = String::hash( "decoration-auto-size" ), + BorderAutoSize = String::hash( "border-auto-size" ), + MarginBetweenButtons = String::hash( "margin-between-buttons" ), + ButtonMargin = String::hash( "button-margin" ), + MenuHeight = String::hash( "menu-height" ), + FirstButtonMarginLeft = String::hash( "first-button-margin-left" ) }; class EE_API PropertyDefinition { diff --git a/include/eepp/ui/uiwidget.hpp b/include/eepp/ui/uiwidget.hpp index f811aade2..845f9d06b 100644 --- a/include/eepp/ui/uiwidget.hpp +++ b/include/eepp/ui/uiwidget.hpp @@ -264,6 +264,8 @@ class EE_API UIWidget : public UINode, public CSS::StyleSheetElement { UIWidget * querySelector( const CSS::StyleSheetSelector& selector ); std::vector querySelectorAll( const CSS::StyleSheetSelector& selector ); + + bool checkPropertyDefinition( const StyleSheetProperty& property ); }; }} diff --git a/src/eepp/ui/css/stylesheetspecification.cpp b/src/eepp/ui/css/stylesheetspecification.cpp index 80f935964..0971ffcc0 100644 --- a/src/eepp/ui/css/stylesheetspecification.cpp +++ b/src/eepp/ui/css/stylesheetspecification.cpp @@ -135,13 +135,96 @@ void StyleSheetSpecification::registerDefaultProperties() { registerProperty( "scale-type", "", false ); registerProperty( "tint", "", false ); registerProperty( "rotation-origin-point", "", false ); + registerProperty( "max-text-length", "", false ); + registerProperty( "min-tab-width", "", false ); + registerProperty( "max-tab-width", "", false ); + registerProperty( "tab-closable", "", false ); + registerProperty( "special-border-tabs", "", false ); + registerProperty( "line-below-tabs", "", false ); + registerProperty( "line-below-tabs-color", "", false ); + registerProperty( "line-below-tabs-y-offset", "", false ); + registerProperty( "tab-separation", "", false ); + registerProperty( "selected", "", false ).addAlias( "active" ); + registerProperty( "popup-to-main-control", "", false ); + registerProperty( "max-visible-items", "", false ); + registerProperty( "selected-index", "", false ); + registerProperty( "selected-text", "", false ); + registerProperty( "scrollbar-type", "", false ); + registerProperty( "row-height", "", false ); + registerProperty( "vscroll-mode", "", false ); + registerProperty( "hscroll-mode", "", false ); + + registerProperty( "column-span", "", false ); + registerProperty( "row-span", "", false ); + registerProperty( "span", "", false ); + registerProperty( "column-mode", "", false ); + registerProperty( "row-mode", "", false ); + registerProperty( "column-weight", "", false ); + registerProperty( "column-width", "", false ); + registerProperty( "row-weight", "", false ); + registerProperty( "reverse-draw", "", false ); + + registerProperty( "orientation", "", false ); + registerProperty( "indeterminate", "", false ); + registerProperty( "max-progress", "", false ); + registerProperty( "progress", "", false ); + registerProperty( "fill-color", "", false ); + registerProperty( "radius", "", false ); + registerProperty( "outline-thickness", "", false ); + registerProperty( "animation-speed", "", false ); + registerProperty( "arc-start-angle", "", false ); + registerProperty( "min-width", "", false ); + registerProperty( "min-margin-right", "", false ); + registerProperty( "min-icon-space", "", false ); + + registerProperty( "total-steps", "", false ); + registerProperty( "vertical-expand", "", false ); + registerProperty( "display-percent", "", false ); + registerProperty( "filler-padding-left", "", false ); + registerProperty( "filler-padding-top", "", false ); + registerProperty( "filler-padding-right", "", false ); + registerProperty( "filler-padding-bottom", "", false ); + registerProperty( "movement-speed", "", false ); + registerProperty( "min-value", "", false ); + registerProperty( "max-value", "", false ); + registerProperty( "value", "", false ); + registerProperty( "click-step", "", false ); + registerProperty( "page-step", "", false ); + registerProperty( "background-expand", "", false ); + registerProperty( "scrollbar-mode", "", false ); + registerProperty( "half-slider", "", false ); + registerProperty( "name", "", false ); + registerProperty( "owns", "", false ); + registerProperty( "allow-editing", "", false ); + registerProperty( "max-length", "", false ); + registerProperty( "free-editing", "", false ); + registerProperty( "only-numbers", "", false ); + registerProperty( "allow-dot", "", false ); + registerProperty( "touch-drag", "", false ); + registerProperty( "touch-drag-deceleration", "", false ); + + registerProperty( "base-alpha", "", false ); + registerProperty( "buttons-position-offset", "", false ); + registerProperty( "window-flags", "", false ); + registerProperty( "decoration-size", "", false ); + registerProperty( "border-size", "", false ); + registerProperty( "min-window-size", "", false ); + registerProperty( "buttons-separation", "", false ); + registerProperty( "min-corner-distance", "", false ); + registerProperty( "decoration-auto-size", "", false ); + registerProperty( "border-auto-size", "", false ); + + registerProperty( "margin-between-buttons", "", false ); + registerProperty( "button-margin", "", false ); + registerProperty( "menu-height", "", false ); + registerProperty( "first-button-margin-left", "", false ); + registerProperty( "scale-origin-point", "", false ); // Shorthands registerProperty( "background-position", "", false ); registerProperty( "transition", "", false ); - //registerProperty( "background", "", false ); - //registerProperty( "padding", "", false ); + registerShorthand( "margin", {"margin-left", "margin-top", "margin-right", "margin-bottom"}, ShorthandDefinition::ShorthandType::Box ); registerShorthand( "padding", @@ -151,9 +234,13 @@ void StyleSheetSpecification::registerDefaultProperties() { ShorthandDefinition::ShorthandType::Background ); registerShorthand( "foreground", {"foreground-color", "foreground-image"}, ShorthandDefinition::ShorthandType::Background ); - /*registerShorthand( "rotation-origin-point", {"rotation-origin-point-x", "rotation-origin-point-y"}, - ShorthandDefinition::ShorthandType::Vector2 ); - registerShorthand( "scale-origin-point", {"scale-origin-point-x", "scale-origin-point-y"}, + registerShorthand( "filler-padding", + {"filler-padding-left", "filler-padding-top", "filler-padding-right", + "filler-padding-bottom"}, + ShorthandDefinition::ShorthandType::Box ); + /*registerShorthand( "rotation-origin-point", {"rotation-origin-point-x", + "rotation-origin-point-y"}, ShorthandDefinition::ShorthandType::Vector2 ); registerShorthand( + "scale-origin-point", {"scale-origin-point-x", "scale-origin-point-y"}, ShorthandDefinition::ShorthandType::Vector2 );*/ } diff --git a/src/eepp/ui/uicheckbox.cpp b/src/eepp/ui/uicheckbox.cpp index 99e7e4783..17ae12958 100644 --- a/src/eepp/ui/uicheckbox.cpp +++ b/src/eepp/ui/uicheckbox.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -195,12 +196,14 @@ void UICheckBox::setTextSeparation(const Int32 & textSeparation) { } bool UICheckBox::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "selected" == name || "active" == name ) { - setActive( attribute.asBool() ); - } else { - return UITextView::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Selected: + setActive( attribute.asBool() ); + break; + default: + return UITextView::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uidropdownlist.cpp b/src/eepp/ui/uidropdownlist.cpp index 7a5c82d10..9d4e8b628 100644 --- a/src/eepp/ui/uidropdownlist.cpp +++ b/src/eepp/ui/uidropdownlist.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -261,21 +262,24 @@ void UIDropDownList::destroyListBox() { } bool UIDropDownList::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "popup-to-main-control" == name || "popuptomaincontrol" == name ) { - setPopUpToMainControl( attribute.asBool() ); - } else if ( "max-visible-items" == name || "maxvisibleitems" == name ) { - setMaxNumVisibleItems( attribute.asUint() ); - } else if ( "selected-index" == name || "selected-text" == name || - "scrollbar-type" == name || "row-height" == name || - "vscroll-mode" == name || "hscroll-mode" == name || - "selectedindex" == name || "selectedtext" == name || - "scrollbartype" == name || "rowheight" == name || - "vscrollmode" == name || "hscrollmode" == name) { - mListBox->applyProperty( attribute, state ); - } else { - return UITextInput::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::PopUpToMainControl: + setPopUpToMainControl( attribute.asBool() ); + break; + case PropertyId::MaxVisibleItems: + setMaxNumVisibleItems( attribute.asUint() ); + break; + case PropertyId::SelectedIndex: + case PropertyId::SelectedText: + case PropertyId::ScrollBarType: + case PropertyId::RowHeight: + case PropertyId::VScrollMode: + case PropertyId::HScrollMode: + return mListBox->applyProperty( attribute, state ); + default: + return UITextInput::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uigridlayout.cpp b/src/eepp/ui/uigridlayout.cpp index 7d11981f7..93208b2b7 100644 --- a/src/eepp/ui/uigridlayout.cpp +++ b/src/eepp/ui/uigridlayout.cpp @@ -1,4 +1,5 @@ #include +#include namespace EE { namespace UI { @@ -205,34 +206,49 @@ Sizef UIGridLayout::getTargetElementSize() const { } bool UIGridLayout::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "column-span" == name || "columnspan" == name ) { - setSpan( Sizei( attribute.asDpDimensionI(), mSpan.y ) ); - } else if ( "row-span" == name || "rowspan" == name ) { - setSpan( Sizei( mSpan.x, attribute.asDpDimensionI() ) ); - } else if ( "span" == name ) { - setSpan( Sizei( attribute.asDpDimension(), attribute.asDpDimensionI() ) ); - } else if ( "column-mode" == name || "columnmode" == name ) { - std::string val( attribute.asString() ); - String::toLowerInPlace( val ); - setColumnMode( "size" == val ? Size : Weight ); - } else if ( "row-mode" == name || "rowmode" == name ) { - std::string val( attribute.asString() ); - String::toLowerInPlace( val ); - setRowMode( "size" == val ? Size : Weight ); - } else if ( "column-weight" == name || "columnweight" == name ) { - setColumnWeight( attribute.asFloat() ); - } else if ( "column-width" == name || "columnwidth" == name ) { - setColumnWidth( attribute.asDpDimensionI() ); - } else if ( "row-weight" == name || "rowweight" == name ) { - setRowWeight( attribute.asDpDimension() ); - } else if ( "row-height" == name || "rowheight" == name ) { - setRowHeight( attribute.asDpDimensionI() ); - } else if ( "reverse-draw" == name || "reversedraw" == name ) { - setReverseDraw( attribute.asBool() ); - } else { - return UILayout::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::ColumnSpan: + setSpan( Sizei( attribute.asDpDimensionI(), mSpan.y ) ); + break; + case PropertyId::RowSpan: + setSpan( Sizei( mSpan.x, attribute.asDpDimensionI() ) ); + break; + case PropertyId::Span: + setSpan( Sizei( attribute.asDpDimension(), attribute.asDpDimensionI() ) ); + break; + case PropertyId::ColumnMode: + { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); + setColumnMode( "size" == val ? Size : Weight ); + break; + } + case PropertyId::RowMode: + { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); + setRowMode( "size" == val ? Size : Weight ); + break; + } + case PropertyId::ColumnWeight: + setColumnWeight( attribute.asFloat() ); + break; + case PropertyId::ColumnWidth: + setColumnWidth( attribute.asDpDimensionI() ); + break; + case PropertyId::RowWeight: + setRowWeight( attribute.asDpDimension() ); + break; + case PropertyId::RowHeight: + setRowHeight( attribute.asDpDimensionI() ); + break; + case PropertyId::ReverseDraw: + setReverseDraw( attribute.asBool() ); + break; + default: + return UILayout::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uiimage.cpp b/src/eepp/ui/uiimage.cpp index 33b7343d5..955320d4f 100644 --- a/src/eepp/ui/uiimage.cpp +++ b/src/eepp/ui/uiimage.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -210,41 +211,49 @@ const Vector2f& UIImage::getAlignOffset() const { } bool UIImage::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "src" == name ) { - Drawable * res = NULL; + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Src: + { + Drawable * res = NULL; + if ( NULL != ( res = DrawableSearcher::searchByName( attribute.asString() ) ) ) { + if ( res->getDrawableType() == Drawable::SPRITE ) + mDrawableOwner = true; - if ( NULL != ( res = DrawableSearcher::searchByName( attribute.asString() ) ) ) { - if ( res->getDrawableType() == Drawable::SPRITE ) - mDrawableOwner = true; - - setDrawable( res ); + setDrawable( res ); + } + break; } - } else if ( "icon" == name ) { - std::string val = attribute.asString(); - Drawable * icon = NULL; - - if ( NULL != mTheme && NULL != ( icon = mTheme->getIconByName( val ) ) ) { - setDrawable( icon ); - } else if ( NULL != ( icon = DrawableSearcher::searchByName( val ) ) ) { - setDrawable( icon ); + case PropertyId::Icon: + { + std::string val = attribute.asString(); + Drawable * icon = NULL; + if ( NULL != mTheme && NULL != ( icon = mTheme->getIconByName( val ) ) ) { + setDrawable( icon ); + } else if ( NULL != ( icon = DrawableSearcher::searchByName( val ) ) ) { + setDrawable( icon ); + } + break; } - } else if ( "scale-type" == name || "scaletype" == name ) { - std::string val = attribute.asString(); - String::toLowerInPlace( val ); - - if ( "expand" == val ) { - setScaleType( UIScaleType::Expand ); - } else if ( "fit-inside" == val || "fit_inside" == val || "fitinside" == val ) { - setScaleType( UIScaleType::FitInside ); - } else if ( "none" == val ) { - setScaleType( UIScaleType::None ); + case PropertyId::ScaleType: + { + std::string val = attribute.asString(); + String::toLowerInPlace( val ); + if ( "expand" == val ) { + setScaleType( UIScaleType::Expand ); + } else if ( "fit-inside" == val || "fit_inside" == val || "fitinside" == val ) { + setScaleType( UIScaleType::FitInside ); + } else if ( "none" == val ) { + setScaleType( UIScaleType::None ); + } + break; } - } else if ( "tint" == name ) { - setColor( attribute.asColor() ); - } else { - return UIWidget::applyProperty( attribute, state ); + case PropertyId::Tint: + setColor( attribute.asColor() ); + break; + default: + return UIWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uilinearlayout.cpp b/src/eepp/ui/uilinearlayout.cpp index e45cf7174..8ba44f0ee 100644 --- a/src/eepp/ui/uilinearlayout.cpp +++ b/src/eepp/ui/uilinearlayout.cpp @@ -1,4 +1,5 @@ #include +#include namespace EE { namespace UI { @@ -408,18 +409,22 @@ Sizei UILinearLayout::getTotalUsedSize() { } bool UILinearLayout::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "orientation" == name ) { - std::string val = attribute.asString(); - String::toLowerInPlace( val ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Orientation: + { + std::string val = attribute.asString(); + String::toLowerInPlace( val ); - if ( "horizontal" == val ) - setOrientation( UI_HORIZONTAL ); - else if ( "vertical" == val ) - setOrientation( UI_VERTICAL ); - } else { - return UILayout::applyProperty( attribute, state ); + if ( "horizontal" == val ) + setOrientation( UI_HORIZONTAL ); + else if ( "vertical" == val ) + setOrientation( UI_VERTICAL ); + break; + } + default: + return UILayout::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index ed12658c3..8fa22e40e 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace EE { namespace UI { @@ -966,37 +967,50 @@ const UI_SCROLLBAR_MODE& UIListBox::getHorizontalScrollMode() { } bool UIListBox::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "row-height" == name || "rowheight" == name ) { - setRowHeight( attribute.asDpDimensionI() ); - } else if ( "vscroll-mode" == name || "vscrollmode" == name ) { - std::string val = attribute.asString(); - if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); - else if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); - } else if ( "hscroll-mode" == name || "hscrollmode" == name ) { - std::string val = attribute.asString(); - if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); - else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); - } else if ( "selected-index" == name || "selectedindex" == name ) { - setSelected( attribute.asUint() ); - } else if ( "selected-text" == name || "selectedtext" == name ) { - setSelected( attribute.asString() ); - } else if ( "scrollbar-type" == name || "scrollbartype" == name ) { - std::string val( attribute.asString() ); - String::toLowerInPlace( val ); - - if ( "no-buttons" == val || "nobuttons" == val ) { - mVScrollBar->setScrollBarType( UIScrollBar::NoButtons ); - mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); - } else if ( "two-buttons" == val || "twobuttons" == val ) { - mVScrollBar->setScrollBarType( UIScrollBar::TwoButtons ); - mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::RowHeight: + setRowHeight( attribute.asDpDimensionI() ); + break; + case PropertyId::VScrollMode: + { + std::string val = attribute.asString(); + if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + break; } - } else { - return UITouchDragableWidget::applyProperty( attribute, state ); + case PropertyId::HScrollMode: + { + std::string val = attribute.asString(); + if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + break; + } + case PropertyId::SelectedIndex: + setSelected( attribute.asUint() ); + break; + case PropertyId::SelectedText: + setSelected( attribute.asString() ); + break; + case PropertyId::ScrollBarType: + { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); + + if ( "no-buttons" == val || "nobuttons" == val ) { + mVScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + } else if ( "two-buttons" == val || "twobuttons" == val ) { + mVScrollBar->setScrollBarType( UIScrollBar::TwoButtons ); + mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + } + break; + } + default: + return UITouchDragableWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uiloader.cpp b/src/eepp/ui/uiloader.cpp index bbf2411b3..a35850bbd 100644 --- a/src/eepp/ui/uiloader.cpp +++ b/src/eepp/ui/uiloader.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace EE { namespace UI { @@ -221,26 +222,35 @@ UILoader * UILoader::setAnimationSpeed( const Float& animationSpeed ) { } bool UILoader::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - std::string name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "indeterminate" == name ) { - setIndeterminate( attribute.asBool() ); - } else if ( "max-progress" == name || "maxprogress" == name ) { - setMaxProgress( attribute.asFloat() ); - } else if ( "progress" == name ) { - setProgress( attribute.asFloat() ); - } else if ( "fill-color" == name || "fillcolor" == name ) { - setFillColor( attribute.asColor() ); - } else if ( "radius" == name ) { - setRadius( attribute.asDpDimension() ); - } else if ( "outline-thickness" == name || "outlinethickness" == name ) { - setOutlineThickness( attribute.asDpDimension() ); - } else if ( "animation-speed" == name || "animationspeed" == name ) { - setAnimationSpeed( attribute.asFloat() ); - } else if ( "arc-start-angle" == name || "arcstartangle" == name ) { - setArcStartAngle( attribute.asFloat() ); - } else { - return UIWidget::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Indeterminate: + setIndeterminate( attribute.asBool() ); + break; + case PropertyId::MaxProgress: + setMaxProgress( attribute.asFloat() ); + break; + case PropertyId::Progress: + setProgress( attribute.asFloat() ); + break; + case PropertyId::FillColor: + setFillColor( attribute.asColor() ); + break; + case PropertyId::Radius: + setRadius( attribute.asDpDimension() ); + break; + case PropertyId::OutlineThickness: + setOutlineThickness( attribute.asDpDimension() ); + break; + case PropertyId::AnimationSpeed: + setAnimationSpeed( attribute.asFloat() ); + break; + case PropertyId::ArcStartAngle: + setArcStartAngle( attribute.asFloat() ); + break; + default: + return UIWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uimenu.cpp b/src/eepp/ui/uimenu.cpp index 8b52cf023..31a5b8a5f 100644 --- a/src/eepp/ui/uimenu.cpp +++ b/src/eepp/ui/uimenu.cpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace EE { namespace UI { @@ -571,17 +572,21 @@ void UIMenu::loadFromXmlNode( const pugi::xml_node& node ) { } bool UIMenu::applyProperty(const StyleSheetProperty & attribute, const Uint32 & state) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "min-width" == name || "minwidth" == name ) { - mStyleConfig.MinWidth = attribute.asInt(); - onSizeChange(); - } else if ( "min-margin-right" == name || "minmarginright" == name ) { - setMinRightMargin( attribute.asDpDimensionUint() ); - } else if ( "min-icon-space" == name || "miniconspace" == name ) { - setMinSpaceForIcons( attribute.asDpDimensionUint() ); - } else { - return UIWidget::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::MinWidth: + mStyleConfig.MinWidth = attribute.asInt(); + onSizeChange(); + break; + case PropertyId::MinMarginRight: + setMinRightMargin( attribute.asDpDimensionUint() ); + break; + case PropertyId::MinIconSpace: + setMinSpaceForIcons( attribute.asDpDimensionUint() ); + break; + default: + return UIWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uiprogressbar.cpp b/src/eepp/ui/uiprogressbar.cpp index 0f38253a1..560a280b1 100644 --- a/src/eepp/ui/uiprogressbar.cpp +++ b/src/eepp/ui/uiprogressbar.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -207,31 +208,38 @@ UITextView * UIProgressBar::getTextBox() const { } bool UIProgressBar::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "total-steps" == name || "totalsteps" == name ) { - setTotalSteps( attribute.asFloat() ); - } else if ( "progress" == name ) { - setProgress( attribute.asFloat() ); - } else if ( "vertical-expand" == name || "verticalexpand" == name ) { - setVerticalExpand( attribute.asBool() ); - } else if ( "display-percent" == name || "displaypercent" == name ) { - setDisplayPercent( attribute.asBool() ); - } else if ( "filler-padding" == name || "fillerpadding" == name ) { - Float val = attribute.asDpDimension(); - setFillerPadding( Rectf( val, val, val, val ) ); - } else if ( "filler-padding-left" == name || "fillerpaddingleft" == name ) { - setFillerPadding( Rectf( attribute.asDpDimension(), mStyleConfig.FillerPadding.Top, mStyleConfig.FillerPadding.Right, mStyleConfig.FillerPadding.Bottom ) ); - } else if ( "filler-padding-right" == name || "fillerpaddingright" == name ) { - setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, mStyleConfig.FillerPadding.Top, attribute.asDpDimension(), mStyleConfig.FillerPadding.Bottom ) ); - } else if ( "filler-padding-top" == name || "fillerpaddingtop" == name ) { - setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, attribute.asDpDimension(), mStyleConfig.FillerPadding.Right, mStyleConfig.FillerPadding.Bottom ) ); - } else if ( "filler-padding-bottom" == name || "fillerpaddingbottom" == name ) { - setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, mStyleConfig.FillerPadding.Top, mStyleConfig.FillerPadding.Right, attribute.asDpDimension() ) ); - } else if ( "movement-speed" == name || "movementspeed" == name ) { - setMovementSpeed( attribute.asVector2f() ); - } else { - return UIWidget::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::TotalSteps: + setTotalSteps( attribute.asFloat() ); + break; + case PropertyId::Progress: + setProgress( attribute.asFloat() ); + break; + case PropertyId::VerticalExpand: + setVerticalExpand( attribute.asBool() ); + break; + case PropertyId::DisplayPercent: + setDisplayPercent( attribute.asBool() ); + break; + case PropertyId::FillerPaddingLeft: + setFillerPadding( Rectf( attribute.asDpDimension(), mStyleConfig.FillerPadding.Top, mStyleConfig.FillerPadding.Right, mStyleConfig.FillerPadding.Bottom ) ); + break; + case PropertyId::FillerPaddingTop: + setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, attribute.asDpDimension(), mStyleConfig.FillerPadding.Right, mStyleConfig.FillerPadding.Bottom ) ); + break; + case PropertyId::FillerPaddingRight: + setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, mStyleConfig.FillerPadding.Top, attribute.asDpDimension(), mStyleConfig.FillerPadding.Bottom ) ); + break; + case PropertyId::FillerPaddingBottom: + setFillerPadding( Rectf( mStyleConfig.FillerPadding.Left, mStyleConfig.FillerPadding.Top, mStyleConfig.FillerPadding.Right, attribute.asDpDimension() ) ); + break; + case PropertyId::MovementSpeed: + setMovementSpeed( attribute.asVector2f() ); + break; + default: + return UIWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uiradiobutton.cpp b/src/eepp/ui/uiradiobutton.cpp index 5659971e5..a02ea9cf3 100644 --- a/src/eepp/ui/uiradiobutton.cpp +++ b/src/eepp/ui/uiradiobutton.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -264,12 +265,14 @@ void UIRadioButton::setTextSeparation(const Int32 & textSeparation) { } bool UIRadioButton::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "selected" == name || "active" == name ) { - setActive( attribute.asBool() ); - } else { - return UITextView::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Selected: + setActive( attribute.asBool() ); + break; + default: + return UITextView::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uiscrollbar.cpp b/src/eepp/ui/uiscrollbar.cpp index f9194eeae..2af51795c 100644 --- a/src/eepp/ui/uiscrollbar.cpp +++ b/src/eepp/ui/uiscrollbar.cpp @@ -1,4 +1,5 @@ #include +#include #include namespace EE { namespace UI { @@ -305,39 +306,52 @@ void UIScrollBar::setExpandBackground( bool expandBackground ) { } bool UIScrollBar::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "orientation" == name ) { - std::string val = attribute.asString(); - String::toLowerInPlace( val ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Orientation: + { + std::string val = attribute.asString(); + String::toLowerInPlace( val ); - if ( "horizontal" == val ) - setOrientation( UI_HORIZONTAL ); - else if ( "vertical" == val ) - setOrientation( UI_VERTICAL ); - } else if ( "min-value" == name || "minvalue" == name ) { - setMinValue( attribute.asFloat() ); - } else if ( "max-value" == name || "maxvalue" == name ) { - setMaxValue( attribute.asFloat() ); - } else if ( "value" == name ) { - setValue( attribute.asFloat() ); - } else if ( "click-step" == name || "clickstep" == name ) { - setClickStep( attribute.asFloat() ); - } else if ( "page-step" == name || "pagestep" == name ) { - setPageStep( attribute.asFloat() ); - } else if ( "scrollbar-type" == name || "scrollbartype" == name ) { - std::string val = attribute.asString(); - String::toLowerInPlace( val ); - - if ( "no-buttons" == val || "nobuttons" == val ) { - setScrollBarType( NoButtons ); - } else if ( "two-buttons" == val || "twobuttons" == val ) { - setScrollBarType( TwoButtons ); + if ( "horizontal" == val ) + setOrientation( UI_HORIZONTAL ); + else if ( "vertical" == val ) + setOrientation( UI_VERTICAL ); + break; } - } else if ( "background-expand" == name || "backgroundexpand" == name ) { - setExpandBackground( attribute.asBool() ); - } else { - return UIWidget::applyProperty( attribute, state ); + case PropertyId::MinValue: + setMinValue( attribute.asFloat() ); + break; + case PropertyId::MaxValue: + setMaxValue( attribute.asFloat() ); + break; + case PropertyId::Value: + setValue( attribute.asFloat() ); + break; + case PropertyId::ClickStep: + setClickStep( attribute.asFloat() ); + break; + case PropertyId::PageStep: + setPageStep( attribute.asFloat() ); + break; + case PropertyId::ScrollBarType: + { + std::string val = attribute.asString(); + String::toLowerInPlace( val ); + + if ( "no-buttons" == val || "nobuttons" == val ) { + setScrollBarType( NoButtons ); + } else if ( "two-buttons" == val || "twobuttons" == val ) { + setScrollBarType( TwoButtons ); + } + break; + } + case PropertyId::BackgroundExpand: + setExpandBackground( attribute.asBool() ); + break; + default: + return UIWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uiscrollview.cpp b/src/eepp/ui/uiscrollview.cpp index 44dbd9d3c..aba4ce98d 100644 --- a/src/eepp/ui/uiscrollview.cpp +++ b/src/eepp/ui/uiscrollview.cpp @@ -1,5 +1,6 @@ #include #include +#include namespace EE { namespace UI { @@ -241,41 +242,53 @@ bool UIScrollView::isTouchOverAllowedChilds() { } bool UIScrollView::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "type" == name ) { - std::string val( attribute.asString() ); - String::toLowerInPlace( val ); - - if ( "inclusive" == val ) setViewType( Inclusive ); - else if ( "exclusive" == val ) setViewType( Exclusive ); - } else if ( "vscroll-mode" == name || "vscrollmode" == name ) { - std::string val( attribute.asString() ); - String::toLowerInPlace( val ); - - if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); - } else if ( "hscroll-mode" == name || "hscrollmode" == name ) { - std::string val( attribute.asString() ); - String::toLowerInPlace( val ); - - if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); - } else if ( "scrollbar-type" == name || "scrollbartype" == name ) { - std::string val( attribute.asString() ); - String::toLowerInPlace( val ); - - if ( "no-buttons" == val || "nobuttons" == val ) { - mVScroll->setScrollBarType( UIScrollBar::NoButtons ); - mHScroll->setScrollBarType( UIScrollBar::NoButtons ); - } else if ( "two-buttons" == val || "twobuttons" == val ) { - mVScroll->setScrollBarType( UIScrollBar::TwoButtons ); - mHScroll->setScrollBarType( UIScrollBar::NoButtons ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::ScrollBarMode: + { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); + if ( "inclusive" == val ) setViewType( Inclusive ); + else if ( "exclusive" == val ) setViewType( Exclusive ); + break; } - } else { - return UITouchDragableWidget::applyProperty( attribute, state ); + case PropertyId::VScrollMode: + { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); + + if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); + break; + } + case PropertyId::HScrollMode: + { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); + + if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); + break; + } + case PropertyId::ScrollBarType: + { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); + + if ( "no-buttons" == val || "nobuttons" == val ) { + mVScroll->setScrollBarType( UIScrollBar::NoButtons ); + mHScroll->setScrollBarType( UIScrollBar::NoButtons ); + } else if ( "two-buttons" == val || "twobuttons" == val ) { + mVScroll->setScrollBarType( UIScrollBar::TwoButtons ); + mHScroll->setScrollBarType( UIScrollBar::NoButtons ); + } + break; + } + default: + return UITouchDragableWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uislider.cpp b/src/eepp/ui/uislider.cpp index 991214576..b5d07658f 100644 --- a/src/eepp/ui/uislider.cpp +++ b/src/eepp/ui/uislider.cpp @@ -1,5 +1,6 @@ #include #include +#include #include namespace EE { namespace UI { @@ -436,32 +437,43 @@ Uint32 UISlider::onMessage(const NodeMessage * Msg) { } bool UISlider::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "orientation" == name ) { - std::string val = attribute.asString(); - String::toLowerInPlace( val ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Orientation: + { + std::string val = attribute.asString(); + String::toLowerInPlace( val ); - if ( "horizontal" == val ) - setOrientation( UI_HORIZONTAL ); - else if ( "vertical" == val ) - setOrientation( UI_VERTICAL ); - } else if ( "min-value" == name || "minvalue" == name ) { - setMinValue( attribute.asFloat() ); - } else if ( "max-value" == name || "maxvalue" == name ) { - setMaxValue( attribute.asFloat() ); - } else if ( "value" == name ) { - setValue( attribute.asFloat() ); - } else if ( "click-step" == name || "clickstep" == name ) { - setClickStep( attribute.asFloat() ); - } else if ( "page-step" == name || "pagestep" == name ) { - setPageStep( attribute.asFloat() ); - } else if ( "half-slider" == name || "halfslider" == name ) { - setAllowHalfSliderOut( attribute.asBool() ); - } else if ( "background-expand" == name || "backgroundexpand" == name ) { - setExpandBackground( attribute.asBool() ); - } else { - return UIWidget::applyProperty( attribute, state ); + if ( "horizontal" == val ) + setOrientation( UI_HORIZONTAL ); + else if ( "vertical" == val ) + setOrientation( UI_VERTICAL ); + break; + } + case PropertyId::MinValue: + setMinValue( attribute.asFloat() ); + break; + case PropertyId::MaxValue: + setMaxValue( attribute.asFloat() ); + break; + case PropertyId::Value: + setValue( attribute.asFloat() ); + break; + case PropertyId::ClickStep: + setClickStep( attribute.asFloat() ); + break; + case PropertyId::PageStep: + setPageStep( attribute.asFloat() ); + break; + case PropertyId::BackgroundExpand: + setExpandBackground( attribute.asBool() ); + break; + case PropertyId::HalfSlider: + setAllowHalfSliderOut( attribute.asBool() ); + break; + default: + return UIWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uispinbox.cpp b/src/eepp/ui/uispinbox.cpp index e509f12d1..0f13851c6 100644 --- a/src/eepp/ui/uispinbox.cpp +++ b/src/eepp/ui/uispinbox.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -270,20 +271,26 @@ void UISpinBox::onPaddingChange() { } bool UISpinBox::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; bool attributeSet = true; - if ( "min-value" == name || "minvalue" == name ) { - setMinValue(attribute.asFloat() ); - } else if ( "max-value" == name || "maxvalue" == name ) { - setMaxValue(attribute.asFloat() ); - } else if ( "value" == name ) { - setValue(attribute.asFloat() ); - } else if ( "click-step" == name || "clickstep" == name ) { - setClickStep(attribute.asFloat() ); - } else { - attributeSet = UIWidget::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::MinValue: + setMinValue(attribute.asFloat() ); + break; + case PropertyId::MaxValue: + setMaxValue(attribute.asFloat() ); + break; + case PropertyId::Value: + setValue(attribute.asFloat() ); + break; + case PropertyId::ClickStep: + setClickStep(attribute.asFloat() ); + break; + default: + attributeSet = UIWidget::applyProperty( attribute, state ); + break; } mInput->applyProperty( attribute ); diff --git a/src/eepp/ui/uisprite.cpp b/src/eepp/ui/uisprite.cpp index 2ba79beb0..d3a690eb6 100644 --- a/src/eepp/ui/uisprite.cpp +++ b/src/eepp/ui/uisprite.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -185,17 +186,21 @@ void UISprite::onSizeChange() { } bool UISprite::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "src" == name ) { - std::string val = attribute.asString(); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Src: + { + std::string val = attribute.asString(); - if ( val.size() ) { - setIsSpriteOwner( true ); - setSprite( Sprite::New( val ) ); + if ( val.size() ) { + setIsSpriteOwner( true ); + setSprite( Sprite::New( val ) ); + } + break; } - } else { - return UIWidget::applyProperty( attribute, state ); + default: + return UIWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uitab.cpp b/src/eepp/ui/uitab.cpp index 78c09fd91..8e4754d1d 100644 --- a/src/eepp/ui/uitab.cpp +++ b/src/eepp/ui/uitab.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace EE { namespace UI { @@ -144,16 +145,20 @@ void UITab::onAutoSize() { } bool UITab::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - std::string name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "name" == name || "text" == name ) { - if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) - setText( static_cast( mSceneNode )->getTranslatorString( attribute.asString() ) ); - } else if ( "owns" == name ) { - mOwnedName = attribute.asString(); - setOwnedControl(); - } else { - return UISelectButton::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Text: + case PropertyId::Name: + if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) + setText( static_cast( mSceneNode )->getTranslatorString( attribute.asString() ) ); + break; + case PropertyId::Owns: + mOwnedName = attribute.asString(); + setOwnedControl(); + break; + default: + return UISelectButton::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uitable.cpp b/src/eepp/ui/uitable.cpp index f62a252cd..1895c94dd 100644 --- a/src/eepp/ui/uitable.cpp +++ b/src/eepp/ui/uitable.cpp @@ -1,4 +1,5 @@ #include +#include #include namespace EE { namespace UI { @@ -623,33 +624,44 @@ bool UITable::isTouchOverAllowedChilds() { } bool UITable::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "row-height" == name || "rowheight" == name ) { - setRowHeight( attribute.asDpDimensionI() ); - } else if ( "vscroll-mode" == name || "vscrollmode" == name ) { - std::string val = attribute.asString(); - if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); - else if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); - } else if ( "hscroll-mode" == name || "hscrollmode" == name ) { - std::string val = attribute.asString(); - if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); - else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); - } else if ( "scrollbar-type" == name || "scrollbartype" == name ) { - std::string val( attribute.asString() ); - String::toLowerInPlace( val ); - - if ( "no-buttons" == val || "nobuttons" == val ) { - mVScrollBar->setScrollBarType( UIScrollBar::NoButtons ); - mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); - } else if ( "two-buttons" == val || "twobuttons" == val ) { - mVScrollBar->setScrollBarType( UIScrollBar::TwoButtons ); - mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::RowHeight: + setRowHeight( attribute.asDpDimensionI() ); + break; + case PropertyId::VScrollMode: + { + std::string val = attribute.asString(); + if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + break; } - } else { - return UITouchDragableWidget::applyProperty( attribute, state ); + case PropertyId::HScrollMode: + { + std::string val = attribute.asString(); + if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + break; + } + case PropertyId::ScrollBarType: + { + std::string val( attribute.asString() ); + String::toLowerInPlace( val ); + + if ( "no-buttons" == val || "nobuttons" == val ) { + mVScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + } else if ( "two-buttons" == val || "twobuttons" == val ) { + mVScrollBar->setScrollBarType( UIScrollBar::TwoButtons ); + mHScrollBar->setScrollBarType( UIScrollBar::NoButtons ); + } + break; + } + default: + return UITouchDragableWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uitabwidget.cpp b/src/eepp/ui/uitabwidget.cpp index a1f92155e..e221e2c71 100644 --- a/src/eepp/ui/uitabwidget.cpp +++ b/src/eepp/ui/uitabwidget.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace EE { namespace UI { @@ -119,28 +120,41 @@ void UITabWidget::setStyleConfig(const StyleConfig & styleConfig) { } bool UITabWidget::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( attribute.getPropertyDefinition() == NULL ) { + eePRINTL( "applyProperty: Property %s not defined!", attribute.getName().c_str() ); + return false; + } - if ( "max-text-length" == name || "maxtextlength" == name ) { - setMaxTextLength( attribute.asUint(1) ); - } else if ( "min-tab-width" == name || "mintabwidth" == name ) { - setMinTabWidth( attribute.asUint(1) ); - } else if ( "max-tab-width" == name || "maxtabwidth" == name ) { - setMaxTabWidth( attribute.asUint() ); - } else if ( "tab-closable" == name || "tabclosable" == name ) { - setTabsClosable( attribute.asBool() ); - } else if ( "special-border-tabs" == name || "specialbordertabs" == name ) { - setSpecialBorderTabs( attribute.asBool() ); - } else if ( "line-below-tabs" == name || "linebelowtabs" == name ) { - setDrawLineBelowTabs( attribute.asBool() ); - } else if ( "line-below-tabs-color" == name || "linebelowtabscolor" == name ) { - setLineBelowTabsColor( attribute.asColor() ); - } else if ( "line-below-tabs-y-offset" == name || "linebelowtabsyoffset" == name ) { - setLineBelowTabsYOffset( attribute.asDpDimensionI() ); - } else if ( "tab-separation" == name || "tabseparation" == name ) { - setTabSeparation( attribute.asDpDimensionI() ); - } else { - return UIWidget::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::MaxTextLength: + setMaxTextLength( attribute.asUint(1) ); + break; + case PropertyId::MinTabWidth: + setMinTabWidth( attribute.asUint(1) ); + break; + case PropertyId::MaxTabWidth: + setMaxTabWidth( attribute.asUint() ); + break; + case PropertyId::TabClosable: + setTabsClosable( attribute.asBool() ); + break; + case PropertyId::SpecialBorderTabs: + setSpecialBorderTabs( attribute.asBool() ); + break; + case PropertyId::LineBelowTabs: + setDrawLineBelowTabs( attribute.asBool() ); + break; + case PropertyId::LineBelowTabsColor: + setLineBelowTabsColor( attribute.asColor() ); + break; + case PropertyId::LineBelowTabsYOffset: + setLineBelowTabsYOffset( attribute.asDpDimensionI() ); + break; + case PropertyId::TabSeparation: + setTabSeparation( attribute.asDpDimensionI() ); + break; + default: + return UIWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uitextedit.cpp b/src/eepp/ui/uitextedit.cpp index 7873bd811..626482631 100644 --- a/src/eepp/ui/uitextedit.cpp +++ b/src/eepp/ui/uitextedit.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -474,31 +475,40 @@ UIFontStyleConfig UITextEdit::getFontStyleConfig() const { } bool UITextEdit::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; bool attributeSet = true; - if ( "text" == name ) { - if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) { - setText( static_cast( mSceneNode )->getTranslatorString( attribute.asString() ) ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Text: + if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) { + setText( static_cast( mSceneNode )->getTranslatorString( attribute.asString() ) ); + } + break; + case PropertyId::AllowEditing: + setAllowEditing( attribute.asBool() ); + break; + case PropertyId::VScrollMode: + { + std::string val = attribute.asString(); + if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + break; } - } else if ( "allow-editing" == name || "allowediting" == name ) { - setAllowEditing( attribute.asBool() ); - } else if ( "vscroll-mode" == name || "vscrollmode" == name ) { - std::string val = attribute.asString(); - if ( "auto" == val ) setVerticalScrollMode( UI_SCROLLBAR_AUTO ); - else if ( "on" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setVerticalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); - } else if ( "hscroll-mode" == name || "hscrollmode" == name ) { - std::string val = attribute.asString(); - if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); - else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); - else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); - } else { - attributeSet = UIWidget::applyProperty( attribute, state ); + case PropertyId::HScrollMode: + { + std::string val = attribute.asString(); + if ( "auto" == val ) setHorizontalScrollMode( UI_SCROLLBAR_AUTO ); + else if ( "on" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_ON ); + else if ( "off" == val ) setHorizontalScrollMode( UI_SCROLLBAR_ALWAYS_OFF ); + break; + } + default: + attributeSet = UIWidget::applyProperty( attribute, state ); } - if ( !attributeSet && ( String::startsWith( name, "text" ) || String::startsWith( name, "font" ) ) ) + if ( !attributeSet && ( String::startsWith( attribute.getName(), "text" ) || String::startsWith( attribute.getName(), "font" ) ) ) mTextInput->applyProperty( attribute, state ); return attributeSet; diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index e53c1a6b7..5c313864b 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace EE { namespace UI { @@ -393,24 +394,31 @@ bool UITextInput::isFreeEditingEnabled() { } bool UITextInput::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "text" == name ) { - if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) { - setText( static_cast( mSceneNode )->getTranslatorString( attribute.asString() ) ); - } - } else if ( "allow-editing" == name || "allowediting" == name ) { - setAllowEditing( attribute.asBool() ); - } else if ( "max-length" == name || "maxlength" == name ) { - setMaxLength( attribute.asUint() ); - } else if ( "free-editing" == name || "freeediting" == name ) { - setFreeEditing( attribute.asBool() ); - } else if ( "only-numbers" == name || "onlynumbers" == name ) { - getInputTextBuffer()->setAllowOnlyNumbers( attribute.asBool(), getInputTextBuffer()->dotsInNumbersAllowed() ); - } else if ( "allow-dot" == name || "allowdot" == name ) { - getInputTextBuffer()->setAllowOnlyNumbers( getInputTextBuffer()->onlyNumbersAllowed(), attribute.asBool() ); - } else { - return UITextView::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Text: + if ( NULL != mSceneNode && mSceneNode->isUISceneNode() ) { + setText( static_cast( mSceneNode )->getTranslatorString( attribute.asString() ) ); + } + break; + case PropertyId::AllowEditing: + setAllowEditing( attribute.asBool() ); + break; + case PropertyId::MaxLength: + setMaxLength( attribute.asUint() ); + break; + case PropertyId::FreeEditing: + setFreeEditing( attribute.asBool() ); + break; + case PropertyId::OnlyNumbers: + getInputTextBuffer()->setAllowOnlyNumbers( attribute.asBool(), getInputTextBuffer()->dotsInNumbersAllowed() ); + break; + case PropertyId::AllowDot: + getInputTextBuffer()->setAllowOnlyNumbers( getInputTextBuffer()->onlyNumbersAllowed(), attribute.asBool() ); + break; + default: + return UITextView::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uitextureregion.cpp b/src/eepp/ui/uitextureregion.cpp index b2f3f7374..db097c622 100644 --- a/src/eepp/ui/uitextureregion.cpp +++ b/src/eepp/ui/uitextureregion.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -197,29 +198,37 @@ const Vector2f& UITextureRegion::getAlignOffset() const { } bool UITextureRegion::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "src" == name ) { - Drawable * res = NULL; + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Src: + { + Drawable * res = NULL; - if ( NULL != ( res = TextureAtlasManager::instance()->getTextureRegionByName( attribute.asString() ) ) && res->getDrawableType() == Drawable::TEXTUREREGION ) { - setTextureRegion( static_cast( res ) ); + if ( NULL != ( res = TextureAtlasManager::instance()->getTextureRegionByName( attribute.asString() ) ) && res->getDrawableType() == Drawable::TEXTUREREGION ) { + setTextureRegion( static_cast( res ) ); + } + break; } - } else if ( "scale-type" == name || "scaletype" == name ) { - std::string val = attribute.asString(); - String::toLowerInPlace( val ); + case PropertyId::ScaleType: + { + std::string val = attribute.asString(); + String::toLowerInPlace( val ); - if ( "expand" == val ) { - setScaleType( UIScaleType::Expand ); - } else if ( "fit_inside" == val || "fitinside" == val ) { - setScaleType( UIScaleType::FitInside ); - } else if ( "none" == val ) { - setScaleType( UIScaleType::None ); + if ( "expand" == val ) { + setScaleType( UIScaleType::Expand ); + } else if ( "fit_inside" == val || "fitinside" == val ) { + setScaleType( UIScaleType::FitInside ); + } else if ( "none" == val ) { + setScaleType( UIScaleType::None ); + } + break; } - } else if ( "tint" == name ) { - setColor( attribute.asColor() ); - } else { - return UIWidget::applyProperty( attribute, state ); + case PropertyId::Tint: + setColor( attribute.asColor() ); + break; + default: + return UIWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uitextview.cpp b/src/eepp/ui/uitextview.cpp index 18d4d894f..7aa3a2c71 100644 --- a/src/eepp/ui/uitextview.cpp +++ b/src/eepp/ui/uitextview.cpp @@ -568,10 +568,7 @@ void UITextView::resetSelCache() { } bool UITextView::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - if ( attribute.getPropertyDefinition() == NULL ) { - eePRINTL( "applyProperty: Property %s not defined!", attribute.getName().c_str() ); - return false; - } + if ( !checkPropertyDefinition( attribute ) ) return false; switch ( attribute.getPropertyDefinition()->getPropertyId() ) { case PropertyId::Text: diff --git a/src/eepp/ui/uitooltip.cpp b/src/eepp/ui/uitooltip.cpp index 8c69e4dd4..b9357d718 100644 --- a/src/eepp/ui/uitooltip.cpp +++ b/src/eepp/ui/uitooltip.cpp @@ -1,8 +1,9 @@ #include #include -#include #include +#include #include +#include #include namespace EE { namespace UI { @@ -328,24 +329,40 @@ void UITooltip::setFontStyleConfig(const UIFontStyleConfig & styleConfig) { } bool UITooltip::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "color" == name ) { - setFontColor( attribute.asColor() ); - } else if ( "shadow-color" == name || "textshadowcolor" == name ) { - setFontShadowColor( attribute.asColor() ); - } else if ( "font-family" == name || "font-name" == name || "fontfamily" == name || "fontname" == name ) { - setFont( FontManager::instance()->getByName( attribute.asString() ) ); - } else if ( "font-size" == name || "textsize" == name || "fontsize" == name ) { - setCharacterSize( attribute.asDpDimensionI() ); - } else if ( "font-style" == name || "textstyle" == name || "fontstyle" == name ) { - setFontStyle( attribute.asFontStyle() ); - } else if ( "text-stroke-width" == name || "fontoutlinethickness" == name ) { - setOutlineThickness( attribute.asDpDimension() ); - } else if ( "text-stroke-color" == name || "fontoutlinecolor" == name ) { - setOutlineColor( attribute.asColor() ); - } else { - return UIWidget::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Color: + setFontColor( attribute.asColor() ); + break; + case PropertyId::ShadowColor: + setFontShadowColor( attribute.asColor() ); + break; + case PropertyId::FontFamily: + setFont( FontManager::instance()->getByName( attribute.asString() ) ); + break; + case PropertyId::FontSize: + setCharacterSize( attribute.asDpDimensionI() ); + break; + case PropertyId::FontStyle: + setFontStyle( attribute.asFontStyle() ); + break; + case PropertyId::TextStrokeWidth: + setOutlineThickness( PixelDensity::dpToPx( attribute.asDpDimension() ) ); + break; + case PropertyId::TextStrokeColor: + setOutlineColor( attribute.asColor() ); + break; + case PropertyId::TextAlign: + { + std::string align = String::toLower( attribute.value() ); + if ( align == "center" ) setFlags( UI_HALIGN_CENTER ); + else if ( align == "left" ) setFlags( UI_HALIGN_LEFT ); + else if ( align == "right" ) setFlags( UI_HALIGN_RIGHT ); + break; + } + default: + return UIWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uitouchdragablewidget.cpp b/src/eepp/ui/uitouchdragablewidget.cpp index cc27df774..c40a23c51 100644 --- a/src/eepp/ui/uitouchdragablewidget.cpp +++ b/src/eepp/ui/uitouchdragablewidget.cpp @@ -1,4 +1,5 @@ #include +#include #include namespace EE { namespace UI { @@ -146,14 +147,17 @@ void UITouchDragableWidget::scheduledUpdate( const Time& time ) { } bool UITouchDragableWidget::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "touch-drag" == name || "touchdrag" == name ) { - setTouchDragEnabled( attribute.asBool() ); - } else if ( "touchdrag-deceleration" == name || "touchdragdeceleration" == name ) { - setTouchDragDeceleration( Vector2f( attribute.asFloat(), attribute.asFloat() ) ); - } else { - return UIWidget::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::TouchDrag: + setTouchDragEnabled( attribute.asBool() ); + break; + case PropertyId::TouchDragDeceleration: + setTouchDragDeceleration( attribute.asVector2f() ); + break; + default: + return UIWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index e7d08190f..abc7fe1f9 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -895,6 +895,14 @@ std::vector UIWidget::querySelectorAll( const CSS::StyleSheetSelector return widgets; } +bool UIWidget::checkPropertyDefinition( const StyleSheetProperty& property ) { + if ( property.getPropertyDefinition() == NULL ) { + eePRINTL( "applyProperty: Property %s not defined!", property.getName().c_str() ); + return false; + } + return true; +} + UIWidget* UIWidget::querySelector( const std::string& selector ) { return querySelector( CSS::StyleSheetSelector( selector ) ); } @@ -917,13 +925,9 @@ void UIWidget::setStyleSheetProperty( const std::string& name, const std::string } bool UIWidget::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { + if ( !checkPropertyDefinition( attribute ) ) return false; bool attributeSet = true; - if ( attribute.getPropertyDefinition() == NULL ) { - eePRINTL( "applyProperty: Property %s not defined!", attribute.getName().c_str() ); - return false; - } - switch ( static_cast( attribute.getPropertyDefinition()->getId() ) ) { case PropertyId::Id: setId( attribute.value() ); @@ -1256,20 +1260,6 @@ bool UIWidget::applyProperty( const StyleSheetProperty& attribute, const Uint32& SAVE_NORMAL_STATE_ATTR( getForeground()->getLayer(0)->getPositionEq() ); setForegroundPosition( attribute.value(), 0 ); break; - case PropertyId::Background: - if ( Color::isColorString( attribute.getValue() ) ) { - applyProperty( StyleSheetProperty( "background-color", attribute.getValue() ) ); - } else { - applyProperty( StyleSheetProperty( "background-image", attribute.getValue() ) ); - } - break; - case PropertyId::Foreground: - if ( Color::isColorString( attribute.getValue() ) ) { - applyProperty( StyleSheetProperty( "foreground-color", attribute.getValue() ) ); - } else { - applyProperty( StyleSheetProperty( "foreground-image", attribute.getValue() ) ); - } - break; case PropertyId::RotationOriginPoint: SAVE_NORMAL_STATE_ATTR( getRotationOriginPoint().toString() ); setRotationOriginPoint( attribute.asOriginPoint() ); diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index f97e89e59..d8af4cdba 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -1,18 +1,19 @@ #include #include +#include +#include +#include +#include #include #include #include #include #include #include -#include -#include #include -#include -#include #include #include +#include namespace EE { namespace UI { @@ -1379,72 +1380,86 @@ void UIWindow::resizeCursor() { } bool UIWindow::applyProperty( const StyleSheetProperty& attribute, const Uint32& state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "width" == name ) { - setSize( attribute.asDpDimension(), getSize().getHeight() ); - } else if ( "height" == name ) { - setSize( getSize().getWidth(), attribute.asDpDimension() ); - } else if ( "title" == name ) { - setTitle( attribute.asString() ); - } else if ( "base-alpha" == name || "basealpha" == name ) { - unsigned int val = attribute.asUint(); - if ( val <= 255 ) - setBaseAlpha( (Uint8)val ); - } else if ( "buttons-position-offset" == name || "buttonspositionoffset" == name ) { - mStyleConfig.ButtonsPositionFixer = attribute.asVector2i(); - fixChildsSize(); - } else if ( "window-flags" == name || "winflags" == name ) { - std::string flagsStr = attribute.asString(); - String::toLowerInPlace( flagsStr ); - std::vector strings = String::split( flagsStr, '|' ); - Uint32 winflags = 0; + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::Width: + setSize( attribute.asDpDimension(), getSize().getHeight() ); + break; + case PropertyId::Height: + setSize( getSize().getWidth(), attribute.asDpDimension() ); + break; + case PropertyId::Title: + setTitle( attribute.asString() ); + break; + case PropertyId::BaseAlpha: + setBaseAlpha( (Uint8)eemin( attribute.asUint(), 255u ) ); + break; + case PropertyId::ButtonsPositionOffset: + mStyleConfig.ButtonsPositionFixer = attribute.asVector2i(); + fixChildsSize(); + break; + case PropertyId::WindowFlags: + { + std::string flagsStr = attribute.asString(); + String::toLowerInPlace( flagsStr ); + std::vector strings = String::split( flagsStr, '|' ); + Uint32 winflags = 0; - if ( strings.size() ) { - for ( std::size_t i = 0; i < strings.size(); i++ ) { - std::string cur = strings[i]; + if ( strings.size() ) { + for ( std::size_t i = 0; i < strings.size(); i++ ) { + std::string cur = strings[i]; - if ( "default" == cur ) winflags |= UI_WIN_DEFAULT_FLAGS; - else if ( "close" == cur ) winflags |= UI_WIN_CLOSE_BUTTON; - else if ( "maximize" == cur ) winflags |= UI_WIN_MAXIMIZE_BUTTON; - else if ( "minimize" == cur ) winflags |= UI_WIN_MINIMIZE_BUTTON; - else if ( "dragable" == cur ) winflags |= UI_WIN_DRAGABLE_CONTAINER; - else if ( "shadow" == cur ) winflags |= UI_WIN_SHADOW; - else if ( "modal" == cur ) winflags |= UI_WIN_MODAL; - else if ( "noborder" == cur || "borderless" == cur ) winflags |= UI_WIN_NO_DECORATION; - else if ( "resizeable" == cur ) winflags |= UI_WIN_RESIZEABLE; - else if ( "sharealpha" == cur ) winflags |= UI_WIN_SHARE_ALPHA_WITH_CHILDS; - else if ( "buttonactions" == cur ) winflags |= UI_WIN_USE_DEFAULT_BUTTONS_ACTIONS; - else if ( "framebuffer"== cur ) winflags |= UI_WIN_FRAME_BUFFER; - else if ( "colorbuffer"== cur ) winflags |= UI_WIN_COLOR_BUFFER; + if ( "default" == cur ) winflags |= UI_WIN_DEFAULT_FLAGS; + else if ( "close" == cur ) winflags |= UI_WIN_CLOSE_BUTTON; + else if ( "maximize" == cur ) winflags |= UI_WIN_MAXIMIZE_BUTTON; + else if ( "minimize" == cur ) winflags |= UI_WIN_MINIMIZE_BUTTON; + else if ( "dragable" == cur ) winflags |= UI_WIN_DRAGABLE_CONTAINER; + else if ( "shadow" == cur ) winflags |= UI_WIN_SHADOW; + else if ( "modal" == cur ) winflags |= UI_WIN_MODAL; + else if ( "noborder" == cur || "borderless" == cur ) winflags |= UI_WIN_NO_DECORATION; + else if ( "resizeable" == cur ) winflags |= UI_WIN_RESIZEABLE; + else if ( "sharealpha" == cur ) winflags |= UI_WIN_SHARE_ALPHA_WITH_CHILDS; + else if ( "buttonactions" == cur ) winflags |= UI_WIN_USE_DEFAULT_BUTTONS_ACTIONS; + else if ( "framebuffer"== cur ) winflags |= UI_WIN_FRAME_BUFFER; + else if ( "colorbuffer"== cur ) winflags |= UI_WIN_COLOR_BUFFER; + } + + /// TODO: WinFlags should replace old winFlags + mStyleConfig.WinFlags |= winflags; + updateWinFlags(); } - - /// TODO: WinFlags should replace old winFlags - mStyleConfig.WinFlags |= winflags; - updateWinFlags(); + break; } - } else if ( "decoration-size" == name || "decorationsize" == name ) { - mStyleConfig.DecorationSize = attribute.asSizei(); - fixChildsSize(); - } else if ( "border-size" == name || "bordersize" == name ) { - mStyleConfig.BorderSize = attribute.asSizei(); - fixChildsSize(); - } else if ( "min-window-size" == name || "minwindowsize" == name ) { - mStyleConfig.MinWindowSize = attribute.asSizef(); - fixChildsSize(); - } else if ( "buttons-separation" == name || "buttonsseparation" == name ) { - mStyleConfig.ButtonsSeparation = attribute.asDpDimensionUint(); - fixChildsSize(); - } else if ( "min-corner-distance" == name || "mincornerdistance" == name ) { - mStyleConfig.MinCornerDistance = attribute.asDpDimensionI(); - } else if ( "decoration-auto-size" == name || "decorationautosize" == name ) { - mStyleConfig.DecorationAutoSize = attribute.asBool(); - fixChildsSize(); - } else if ( "border-auto-size" == name || "borderautosize" == name ) { - mStyleConfig.BorderAutoSize = attribute.asBool(); - fixChildsSize(); - } else { - return UIWidget::applyProperty( attribute, state ); + case PropertyId::DecorationSize: + mStyleConfig.DecorationSize = attribute.asSizei(); + fixChildsSize(); + break; + case PropertyId::BorderSize: + mStyleConfig.BorderSize = attribute.asSizei(); + fixChildsSize(); + break; + case PropertyId::MinWindowSize: + mStyleConfig.MinWindowSize = attribute.asSizef(); + fixChildsSize(); + break; + case PropertyId::ButtonsSeparation: + mStyleConfig.ButtonsSeparation = attribute.asDpDimensionUint(); + fixChildsSize(); + break; + case PropertyId::MinCornerDistance: + mStyleConfig.MinCornerDistance = attribute.asDpDimensionI(); + break; + case PropertyId::DecorationAutoSize: + mStyleConfig.DecorationAutoSize = attribute.asBool(); + fixChildsSize(); + break; + case PropertyId::BorderAutoSize: + mStyleConfig.BorderAutoSize = attribute.asBool(); + fixChildsSize(); + break; + default: + return UIWidget::applyProperty( attribute, state ); } return true; diff --git a/src/eepp/ui/uiwinmenu.cpp b/src/eepp/ui/uiwinmenu.cpp index 03e8e5bb4..593f0c4ef 100644 --- a/src/eepp/ui/uiwinmenu.cpp +++ b/src/eepp/ui/uiwinmenu.cpp @@ -1,8 +1,9 @@ #include #include +#include +#include #include #include -#include #include namespace EE { namespace UI { @@ -159,18 +160,23 @@ void UIWinMenu::setFirstButtonMargin( const Uint32& buttonMargin ) { } bool UIWinMenu::applyProperty( const StyleSheetProperty& attribute, const Uint32 & state ) { - const std::string& name = attribute.getName(); + if ( !checkPropertyDefinition( attribute ) ) return false; - if ( "margin-between-buttons" == name || "marginbetweenbuttons" == name ) { - setMarginBetweenButtons( attribute.asDpDimensionUint() ); - } else if ( "button-margin" == name || "buttonmargin" == name ) { - setButtonMargin( attribute.asDpDimensionUint() ); - } else if ( "menu-height" == name || "menuheight" == name ) { - setMenuHeight( attribute.asDpDimensionUint() ); - } else if ( "first-button-margin-left" == name || "firstbuttonmarginleft" == name ) { - setFirstButtonMargin( attribute.asDpDimensionUint() ); - } else { - return UIWidget::applyProperty( attribute, state ); + switch ( attribute.getPropertyDefinition()->getPropertyId() ) { + case PropertyId::MarginBetweenButtons: + setMarginBetweenButtons( attribute.asDpDimensionUint() ); + break; + case PropertyId::ButtonMargin: + setButtonMargin( attribute.asDpDimensionUint() ); + break; + case PropertyId::MenuHeight: + setMenuHeight( attribute.asDpDimensionUint() ); + break; + case PropertyId::FirstButtonMarginLeft: + setFirstButtonMargin( attribute.asDpDimensionUint() ); + break; + default: + return UIWidget::applyProperty( attribute, state ); } return true;