mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-10-25 23:57:53 +03:00
Added "border" CSS shorthand.
Fixed "background" CSS shorthand parsing. All UI Widgets emit "OnClose" event when being destroyed. Minor fixes in UIDropDownList and UIImage. Added aliases for "layout_width" -> "lw", "layout_height" -> "lh", "layout_weight" -> "lw8". And for "wrap_content" -> "wc" and "match_parent" -> "mp".
This commit is contained in:
@@ -217,7 +217,7 @@ It should look really familiar to any Android developer. This is a window with
|
||||
the most basic widgets in a vertical linear layout display.
|
||||
|
||||
```xml
|
||||
<window layout_width="300dp" layout_height="300dp" winflags="default|maximize">
|
||||
<window layout_width="300dp" layout_height="300dp" window-flags="default|maximize|shadow">
|
||||
<LinearLayout id="testlayout" orientation="vertical" layout_width="match_parent" layout_height="match_parent" layout_margin="8dp">
|
||||
<TextView text="Hello World!" gravity="center" layout_gravity="center_horizontal" layout_width="match_parent" layout_height="wrap_content" backgroundColor="black" />
|
||||
<PushButton text="OK!" textSize="16dp" icon="ok" gravity="center" layout_gravity="center_horizontal" layout_width="match_parent" layout_height="wrap_content" />
|
||||
|
||||
@@ -856,7 +856,7 @@ or one of the special constants.
|
||||
* `match_parent`: The element must be as big as its parent.
|
||||
* `wrap_content`: The element should be only big enough to enclose its content (plus padding).
|
||||
* Default value: `wrap_content`
|
||||
* Aliases: `layout_height`
|
||||
* Aliases: `layout_height`, `lh`
|
||||
|
||||
---
|
||||
|
||||
@@ -928,7 +928,7 @@ layout weight.
|
||||
* Applicable to: Any element child of a EE::UI::UILinearLayout (LinearLayout)
|
||||
* Data Type: [number](#number-data-type) (normalized from `0` to `1`)
|
||||
* Default value: `0`
|
||||
* Aliases: `layout_weight`
|
||||
* Aliases: `layout_weight`, `lw8`
|
||||
|
||||
---
|
||||
|
||||
@@ -946,7 +946,7 @@ or one of the special constants.
|
||||
* `match_parent`: The element must be as big as its parent.
|
||||
* `wrap_content`: The element should be only big enough to enclose its content (plus padding).
|
||||
* Default value: `wrap_content`
|
||||
* Aliases: `layout_width`
|
||||
* Aliases: `layout_width`, `lw`
|
||||
|
||||
---
|
||||
|
||||
@@ -2067,6 +2067,13 @@ Read [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/back
|
||||
|
||||
---
|
||||
|
||||
### border
|
||||
|
||||
Read [border](https://developer.mozilla.org/en-US/docs/Web/CSS/border) documentation.
|
||||
`border-style` is not implemented yet.
|
||||
|
||||
---
|
||||
|
||||
### border-color
|
||||
|
||||
Read [border-color](https://developer.mozilla.org/en-US/docs/Web/CSS/border-color) documentation.
|
||||
|
||||
@@ -60,7 +60,7 @@ class EE_API Event {
|
||||
OnTabAdded,
|
||||
OnTabClosed,
|
||||
OnTabNavigate,
|
||||
OnClose, // Warning: Only some nodes will report this event.
|
||||
OnClose,
|
||||
OnDragStart,
|
||||
OnDragStop,
|
||||
OnPaddingChange,
|
||||
|
||||
@@ -390,7 +390,6 @@ Uint32 Node::onCalculateDrag( const Vector2f&, const Uint32& ) {
|
||||
|
||||
void Node::onClose() {
|
||||
sendCommonEvent( Event::OnClose );
|
||||
invalidateDraw();
|
||||
}
|
||||
|
||||
Node* Node::getNextNode() const {
|
||||
|
||||
@@ -148,10 +148,11 @@ void StyleSheetSpecification::registerDefaultProperties() {
|
||||
registerProperty( "tooltip", "" ).setType( PropertyType::String );
|
||||
registerProperty( "layout-weight", "" )
|
||||
.addAlias( "layout_weight" )
|
||||
.addAlias( "lw8" )
|
||||
.setType( PropertyType::NumberFloat );
|
||||
registerProperty( "layout-gravity", "" ).addAlias( "layout_gravity" );
|
||||
registerProperty( "layout-width", "" ).addAlias( "layout_width" );
|
||||
registerProperty( "layout-height", "" ).addAlias( "layout_height" );
|
||||
registerProperty( "layout-width", "" ).addAlias( "layout_width" ).addAlias( "lw" );
|
||||
registerProperty( "layout-height", "" ).addAlias( "layout_height" ).addAlias( "lh" );
|
||||
registerProperty( "layout-to-left-of", "" ).addAlias( "layout_to_left_of" );
|
||||
registerProperty( "layout-to-right-of", "" ).addAlias( "layout_to_right_of" );
|
||||
registerProperty( "layout-to-top-of", "" ).addAlias( "layout_to_top_of" );
|
||||
@@ -417,6 +418,7 @@ void StyleSheetSpecification::registerDefaultProperties() {
|
||||
"vector2" );
|
||||
registerShorthand( "min-size", { "min-width", "min-height" }, "vector2" );
|
||||
registerShorthand( "max-size", { "max-width", "max-height" }, "vector2" );
|
||||
registerShorthand( "border", { "border-width", "border-style", "border-color" }, "border" );
|
||||
}
|
||||
|
||||
void StyleSheetSpecification::registerNodeSelector( const std::string& name,
|
||||
@@ -715,7 +717,7 @@ void StyleSheetSpecification::registerDefaultShorthandParsers() {
|
||||
if ( value.empty() )
|
||||
return {};
|
||||
std::vector<StyleSheetProperty> properties;
|
||||
const std::vector<std::string> propNames( shorthand->getProperties() );
|
||||
const std::vector<std::string>& propNames = shorthand->getProperties();
|
||||
auto ltrbSplit = String::split( value, " ", "", "(\"" );
|
||||
if ( !ltrbSplit.empty() ) {
|
||||
for ( size_t i = 0; i < propNames.size(); i++ ) {
|
||||
@@ -732,7 +734,7 @@ void StyleSheetSpecification::registerDefaultShorthandParsers() {
|
||||
if ( value.empty() )
|
||||
return {};
|
||||
std::vector<StyleSheetProperty> properties;
|
||||
const std::vector<std::string> propNames( shorthand->getProperties() );
|
||||
const std::vector<std::string>& propNames = shorthand->getProperties();
|
||||
auto splits = String::split( value, '/' );
|
||||
auto widths = String::split( splits[0], ' ' );
|
||||
std::vector<std::string> heights;
|
||||
@@ -758,7 +760,7 @@ void StyleSheetSpecification::registerDefaultShorthandParsers() {
|
||||
if ( value.empty() )
|
||||
return {};
|
||||
std::vector<StyleSheetProperty> properties;
|
||||
const std::vector<std::string> propNames( shorthand->getProperties() );
|
||||
const std::vector<std::string>& propNames = shorthand->getProperties();
|
||||
std::vector<std::string> values = String::split( value, ',' );
|
||||
std::map<std::string, std::vector<std::string>> tmpProperties;
|
||||
|
||||
@@ -809,12 +811,10 @@ void StyleSheetSpecification::registerDefaultShorthandParsers() {
|
||||
mShorthandParsers["background"] = [&]( const ShorthandDefinition* shorthand,
|
||||
std::string value ) -> std::vector<StyleSheetProperty> {
|
||||
value = String::trim( value );
|
||||
if ( value.empty() )
|
||||
return {};
|
||||
if ( "none" == value )
|
||||
if ( value.empty() || "none" == value )
|
||||
return {};
|
||||
std::vector<StyleSheetProperty> properties;
|
||||
const std::vector<std::string> propNames( shorthand->getProperties() );
|
||||
const std::vector<std::string>& propNames = shorthand->getProperties();
|
||||
std::vector<std::string> tokens = String::split( value, " ", "", "(" );
|
||||
std::string positionStr;
|
||||
|
||||
@@ -843,8 +843,55 @@ void StyleSheetSpecification::registerDefaultShorthandParsers() {
|
||||
int pos = getIndexEndingWith( propNames, "-position" );
|
||||
if ( pos != -1 ) {
|
||||
const ShorthandDefinition* shorthand = getShorthand( propNames[pos] );
|
||||
if ( NULL != shorthand )
|
||||
mShorthandParsers["background-position"]( shorthand, positionStr );
|
||||
if ( NULL != shorthand ) {
|
||||
auto bpVec = mShorthandParsers["background-position"]( shorthand, positionStr );
|
||||
for ( auto& bp : bpVec )
|
||||
properties.emplace_back( bp );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return properties;
|
||||
};
|
||||
|
||||
mShorthandParsers["border"] = [&]( const ShorthandDefinition* shorthand,
|
||||
std::string value ) -> std::vector<StyleSheetProperty> {
|
||||
value = String::trim( value );
|
||||
if ( value.empty() || "none" == value )
|
||||
return {};
|
||||
|
||||
std::vector<StyleSheetProperty> properties;
|
||||
const std::vector<std::string>& propNames = shorthand->getProperties();
|
||||
std::vector<std::string> tokens = String::split( value, " ", "", "(" );
|
||||
|
||||
for ( auto& tok : tokens ) {
|
||||
if ( -1 !=
|
||||
String::valueIndex(
|
||||
tok, "none;hidden;dotted;dashed;solid;double;groove;ridge;inset;outset" ) ) {
|
||||
int pos = getIndexEndingWith( propNames, "-style" );
|
||||
// boder-style is not implemented yet
|
||||
if ( pos != -1 )
|
||||
continue;
|
||||
} else if ( Color::isColorString( tok ) ) {
|
||||
int pos = getIndexEndingWith( propNames, "-color" );
|
||||
if ( pos != -1 ) {
|
||||
const ShorthandDefinition* shorthand = getShorthand( propNames[pos] );
|
||||
if ( NULL != shorthand ) {
|
||||
auto bbVec = mShorthandParsers["border-box"]( shorthand, tok );
|
||||
for ( auto& bb : bbVec )
|
||||
properties.emplace_back( bb );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int pos = getIndexEndingWith( propNames, "-width" );
|
||||
if ( pos != -1 ) {
|
||||
const ShorthandDefinition* shorthand = getShorthand( propNames[pos] );
|
||||
if ( NULL != shorthand ) {
|
||||
auto bbVec = mShorthandParsers["border-box"]( shorthand, tok );
|
||||
for ( auto& bb : bbVec )
|
||||
properties.emplace_back( bb );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,9 @@ UIDropDownList::UIDropDownList( const std::string& tag ) :
|
||||
cb::Make1( this, &UIDropDownList::onItemKeyDown ) );
|
||||
mListBox->addEventListener( Event::KeyDown, cb::Make1( this, &UIDropDownList::onItemKeyDown ) );
|
||||
mListBox->addEventListener( Event::OnClear, cb::Make1( this, &UIDropDownList::onWidgetClear ) );
|
||||
mListBox->addEventListener( Event::OnClose, [&]( const Event* ) {
|
||||
mListBox = nullptr;
|
||||
} );
|
||||
}
|
||||
|
||||
UIDropDownList::~UIDropDownList() {
|
||||
|
||||
@@ -71,9 +71,8 @@ UIImage* UIImage::setDrawable( Drawable* drawable, bool ownIt ) {
|
||||
|
||||
void UIImage::onAutoSize() {
|
||||
if ( NULL != mDrawable ) {
|
||||
if ( ( mFlags & UI_AUTO_SIZE ) && Sizef::Zero == getSize() ) {
|
||||
setInternalSize( mDrawable->getSize() );
|
||||
}
|
||||
if ( ( mFlags & UI_AUTO_SIZE ) && Sizef::Zero == getSize() )
|
||||
setInternalSize( mDrawable->getSize().asInt().asFloat() );
|
||||
|
||||
Sizef size( getSize() );
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ UIPopUpMenu::UIPopUpMenu() : UIMenu() {
|
||||
}
|
||||
|
||||
UIPopUpMenu::~UIPopUpMenu() {
|
||||
onClose();
|
||||
}
|
||||
|
||||
Uint32 UIPopUpMenu::getType() const {
|
||||
|
||||
@@ -57,6 +57,8 @@ UIWidget::UIWidget( const std::string& tag ) :
|
||||
UIWidget::UIWidget() : UIWidget( "widget" ) {}
|
||||
|
||||
UIWidget::~UIWidget() {
|
||||
onClose();
|
||||
|
||||
if ( mUISceneNode && mUISceneNode->getUIEventDispatcher() &&
|
||||
mUISceneNode->getUIEventDispatcher()->getNodeDragging() == this )
|
||||
mUISceneNode->getUIEventDispatcher()->setNodeDragging( nullptr );
|
||||
@@ -1474,9 +1476,9 @@ bool UIWidget::applyProperty( const StyleSheetProperty& attribute ) {
|
||||
std::string val = attribute.asString();
|
||||
String::toLowerInPlace( val );
|
||||
|
||||
if ( "match_parent" == val || "match-parent" == val ) {
|
||||
if ( "match_parent" == val || "match-parent" == val || "mp" == val ) {
|
||||
setLayoutWidthPolicy( SizePolicy::MatchParent );
|
||||
} else if ( "wrap_content" == val || "wrap-content" == val ) {
|
||||
} else if ( "wrap_content" == val || "wrap-content" == val || "wc" == val ) {
|
||||
setLayoutWidthPolicy( SizePolicy::WrapContent );
|
||||
} else if ( "fixed" == val ) {
|
||||
setLayoutWidthPolicy( SizePolicy::Fixed );
|
||||
@@ -1497,9 +1499,9 @@ bool UIWidget::applyProperty( const StyleSheetProperty& attribute ) {
|
||||
std::string val = attribute.asString();
|
||||
String::toLowerInPlace( val );
|
||||
|
||||
if ( "match_parent" == val ) {
|
||||
if ( "match_parent" == val || "match-parent" == val || "mp" == val ) {
|
||||
setLayoutHeightPolicy( SizePolicy::MatchParent );
|
||||
} else if ( "wrap_content" == val ) {
|
||||
} else if ( "wrap_content" == val || "wrap-content" == val || "wc" == val ) {
|
||||
setLayoutHeightPolicy( SizePolicy::WrapContent );
|
||||
} else if ( "fixed" == val ) {
|
||||
setLayoutHeightPolicy( SizePolicy::Fixed );
|
||||
|
||||
@@ -109,8 +109,6 @@ UIWindow::~UIWindow() {
|
||||
|
||||
sendCommonEvent( Event::OnWindowClose );
|
||||
|
||||
onClose();
|
||||
|
||||
eeSAFE_DELETE( mFrameBuffer );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user