Some minor optimizations.

This commit is contained in:
Martín Lucas Golini
2020-04-26 20:39:42 -03:00
parent 45b4f0d208
commit e066eb510e
9 changed files with 129 additions and 85 deletions

View File

@@ -55,7 +55,7 @@ class EE_API StyleSheet {
void addMediaQueryList( MediaQueryList::ptr list );
void addStyleToNodeIndex( StyleSheetStyle* style );
bool addStyleToNodeIndex( StyleSheetStyle* style );
};
}}} // namespace EE::UI::CSS

View File

@@ -36,6 +36,8 @@ class EE_API StyleSheetParser {
StyleSheet& getStyleSheet();
const bool& isLoaded() const;
protected:
enum ReadState { ReadingSelector, ReadingProperty, ReadingComment };
@@ -43,6 +45,7 @@ class EE_API StyleSheetParser {
StyleSheet mStyleSheet;
std::vector<std::string> mComments;
MediaQueryList::ptr mMediaQueryList;
bool mLoaded;
bool parse( std::string& css, std::vector<std::string>& importedList );

View File

@@ -9,11 +9,15 @@ class EE_API UISlider : public UIWidget {
public:
static UISlider* New();
static UISlider* NewWithTag( const std::string& tag );
static UISlider* NewWithTag( const std::string& tag, const UIOrientation& orientation );
static UISlider* NewVertical( const std::string& tag );
static UISlider* NewVertical();
static UISlider* NewHorizontal( const std::string& tag );
static UISlider* NewHorizontal();
static UISlider* NewVerticalWithTag( const std::string& tag );
static UISlider* NewHorizontalWithTag( const std::string& tag );
UISlider( const std::string& tag,
const UIOrientation& orientation = UIOrientation::Horizontal );

View File

@@ -24,7 +24,7 @@ size_t StyleSheet::NodeHash( const std::string& tag, const std::string& id ) {
return seed;
}
void StyleSheet::addStyleToNodeIndex( StyleSheetStyle* style ) {
bool StyleSheet::addStyleToNodeIndex( StyleSheetStyle* style ) {
const std::string& id = style->getSelector().getSelectorId();
const std::string& tag = style->getSelector().getSelectorTagName();
if ( style->hasProperties() || style->hasVariables() ) {
@@ -33,15 +33,18 @@ void StyleSheet::addStyleToNodeIndex( StyleSheetStyle* style ) {
auto it = std::find( nodes.begin(), nodes.end(), style );
if ( it == nodes.end() ) {
nodes.push_back( style );
return true;
} else {
eePRINTL( "Ignored style %s", style->getSelector().getName().c_str() );
}
}
return false;
}
void StyleSheet::addStyle( std::shared_ptr<StyleSheetStyle> node ) {
mNodes.push_back( node );
addStyleToNodeIndex( node.get() );
if ( addStyleToNodeIndex( node.get() ) ) {
mNodes.push_back( node );
}
addMediaQueryList( node->getMediaQueryList() );
}

View File

@@ -19,7 +19,7 @@ using namespace EE::System;
namespace EE { namespace UI { namespace CSS {
StyleSheetParser::StyleSheetParser() {}
StyleSheetParser::StyleSheetParser() : mLoaded( false ) {}
bool StyleSheetParser::loadFromStream( IOStream& stream ) {
Clock elapsed;
@@ -28,6 +28,7 @@ bool StyleSheetParser::loadFromStream( IOStream& stream ) {
stream.read( &mCSS[0], stream.getSize() );
bool ok = parse( mCSS, importedList );
eePRINTL( "StyleSheet loaded in: %4.3f ms.", elapsed.getElapsedTime().asMilliseconds() );
mLoaded = ok;
return ok;
}
@@ -89,6 +90,10 @@ StyleSheet& StyleSheetParser::getStyleSheet() {
return mStyleSheet;
}
const bool& StyleSheetParser::isLoaded() const {
return mLoaded;
}
bool StyleSheetParser::parse( std::string& css, std::vector<std::string>& importedList ) {
ReadState rs = ReadingSelector;
std::size_t pos = 0;

View File

@@ -7,12 +7,80 @@
#include <eepp/scene/actions/fade.hpp>
#include <eepp/scene/scenemanager.hpp>
#include <eepp/scene/scenenode.hpp>
#include <eepp/ui/css/stylesheetparser.hpp>
#include <eepp/ui/tools/uicolorpicker.hpp>
#include <eepp/ui/uiscenenode.hpp>
#include <eepp/ui/uithememanager.hpp>
namespace EE { namespace UI { namespace Tools {
static CSS::StyleSheetParser sStyleSheetParser;
static UISceneNode* sLastSceneNode = NULL;
const char* COLOR_PICKER_STYLE = R"xml(
#color_picker {
margin: 4dp;
window-min-size: 320dp 478dp;
}
#color_picker > .header {
margin-bottom: 4dp;
}
#color_picker > .header > .current_color {
}
#color_picker > .header > .picker_icon {
icon: color-picker-white;
gravity: center;
}
#color_picker > .pickers > .color_picker_container > .color_picker {
background-color: white;
scale-type: expand;
}
#color_picker > .pickers > .color_picker_container > .vertical_line {
background-color: black;
border-width: 1dp;
border-color: white;
border-type: outside;
}
#color_picker > .pickers > .color_picker_container > .horizontal_line {
background-color: black;
border-width: 1dp;
border-color: white;
border-type: outside;
}
#color_picker > .pickers > .separator,
#color_picker > .header > .separator {
margin-left: 8dp;
margin-right: 8dp;
}
#color_picker > .pickers > .separator {
background-color: #FFFFFF88;
}
#color_picker > .pickers > .hue_picker_container > .hue_picker {
background-color: white;
scale-type: expand;
}
#color_picker > .pickers > .hue_picker_container > .hue_line {
background-color: black;
border-width: 1dp;
border-color: white;
border-type: outside;
}
#color_picker > .separator {
margin-top: 8dp;
margin-bottom: 4dp;
background-color: #FFFFFF88;
}
#color_picker > .slider_container,
#color_picker > .footer {
margin-top: 4dp;
}
#color_picker > .footer > PushButton {
padding-left: 8dp;
padding-right: 8dp;
icon: ok;
}
)xml";
UIColorPicker* UIColorPicker::NewModal( Node* nodeCreator,
const UIColorPicker::ColorPickedCb& colorPickedCb,
const Uint8& modalAlpha, const Uint32& winFlags,
@@ -105,69 +173,6 @@ UIColorPicker::UIColorPicker( UIWindow* attachTo, const UIColorPicker::ColorPick
}
std::string layout = R"xml(
<style>
#color_picker {
margin: 4dp;
window-min-size: 320dp 478dp;
}
#color_picker > .header {
margin-bottom: 4dp;
}
#color_picker > .header > .current_color {
}
#color_picker > .header > .picker_icon {
icon: color-picker-white;
gravity: center;
}
#color_picker > .pickers > .color_picker_container > .color_picker {
background-color: white;
scale-type: expand;
}
#color_picker > .pickers > .color_picker_container > .vertical_line {
background-color: black;
border-width: 1dp;
border-color: white;
border-type: outside;
}
#color_picker > .pickers > .color_picker_container > .horizontal_line {
background-color: black;
border-width: 1dp;
border-color: white;
border-type: outside;
}
#color_picker > .pickers > .separator,
#color_picker > .header > .separator {
margin-left: 8dp;
margin-right: 8dp;
}
#color_picker > .pickers > .separator {
background-color: #FFFFFF88;
}
#color_picker > .pickers > .hue_picker_container > .hue_picker {
background-color: white;
scale-type: expand;
}
#color_picker > .pickers > .hue_picker_container > .hue_line {
background-color: black;
border-width: 1dp;
border-color: white;
border-type: outside;
}
#color_picker > .separator {
margin-top: 8dp;
margin-bottom: 4dp;
background-color: #FFFFFF88;
}
#color_picker > .slider_container,
#color_picker > .footer {
margin-top: 4dp;
}
#color_picker > .footer > PushButton {
padding-left: 8dp;
padding-right: 8dp;
icon: ok;
}
</style>
<LinearLayout id="color_picker" class="container" orientation="vertical" layout_width="match_parent" layout_height="wrap_content">
<LinearLayout class="header" orientation="horizontal" layout_width="match_parent" layout_height="28dp">
<Widget id="current_color" class="current_color" layout_width="256dp" layout_height="match_parent" />
@@ -189,22 +194,22 @@ UIColorPicker::UIColorPicker( UIWindow* attachTo, const UIColorPicker::ColorPick
<Widget class="separator" layout_width="match_parent" layout_height="1dp" />
<LinearLayout id="red_container" class="slider_container" orientation="horizontal" layout_width="match_parent" layout_height="wrap_content">
<TextView layout_width="16dp" layout_height="wrap_content" text="R" layout_gravity="center" />
<Slider layout_width="0dp" layout_weight="1" layout_height="wrap_content" orientation="horizontal" layout_gravity="center" minValue="0" maxValue="255" />
<HSlider layout_width="0dp" layout_weight="1" layout_height="wrap_content" layout_gravity="center" minValue="0" maxValue="255" />
<SpinBox layout_width="48dp" layout_height="wrap_content" minValue="0" maxValue="255" />
</LinearLayout>
<LinearLayout id="green_container" class="slider_container" orientation="horizontal" layout_width="match_parent" layout_height="wrap_content">
<TextView layout_width="16dp" layout_height="wrap_content" text="G" layout_gravity="center" />
<Slider layout_width="0dp" layout_weight="1" layout_height="wrap_content" orientation="horizontal" layout_gravity="center" minValue="0" maxValue="255" />
<HSlider layout_width="0dp" layout_weight="1" layout_height="wrap_content" layout_gravity="center" minValue="0" maxValue="255" />
<SpinBox layout_width="48dp" layout_height="wrap_content" minValue="0" maxValue="255" />
</LinearLayout>
<LinearLayout id="blue_container" class="slider_container" orientation="horizontal" layout_width="match_parent" layout_height="wrap_content">
<TextView layout_width="16dp" layout_height="wrap_content" text="B" layout_gravity="center" />
<Slider layout_width="0dp" layout_weight="1" layout_height="wrap_content" orientation="horizontal" layout_gravity="center" minValue="0" maxValue="255" />
<HSlider layout_width="0dp" layout_weight="1" layout_height="wrap_content" layout_gravity="center" minValue="0" maxValue="255" />
<SpinBox layout_width="48dp" layout_height="wrap_content" minValue="0" maxValue="255" />
</LinearLayout>
<LinearLayout id="alpha_container" class="slider_container" orientation="horizontal" layout_width="match_parent" layout_height="wrap_content">
<TextView layout_width="16dp" layout_height="wrap_content" text="A" layout_gravity="center" />
<Slider layout_width="0dp" layout_weight="1" layout_height="wrap_content" orientation="horizontal" layout_gravity="center" minValue="0" maxValue="255" />
<HSlider layout_width="0dp" layout_weight="1" layout_height="wrap_content" layout_gravity="center" minValue="0" maxValue="255" />
<SpinBox layout_width="48dp" layout_height="wrap_content" minValue="0" maxValue="255" />
</LinearLayout>
<LinearLayout id="footer" class="footer" orientation="horizontal" layout_width="match_parent" layout_height="wrap_content">
@@ -218,8 +223,19 @@ UIColorPicker::UIColorPicker( UIWindow* attachTo, const UIColorPicker::ColorPick
if ( NULL != mUIContainer->getSceneNode() && mUIContainer->getSceneNode()->isUISceneNode() ) {
Clock clock;
mRoot = mUIContainer->getSceneNode()->asType<UISceneNode>()->loadLayoutFromString(
layout, mUIContainer );
UISceneNode* uiSceneNode = mUIContainer->getSceneNode()->asType<UISceneNode>();
if ( !sStyleSheetParser.isLoaded() ) {
sStyleSheetParser.loadFromString( std::string( COLOR_PICKER_STYLE ) );
}
if ( sLastSceneNode != uiSceneNode ) {
uiSceneNode->combineStyleSheet( sStyleSheetParser.getStyleSheet() );
sLastSceneNode = uiSceneNode;
}
mRoot = uiSceneNode->loadLayoutFromString( layout, mUIContainer );
eePRINTL( "UIColorPicker loadLayoutFromString time: %.2f",
clock.getElapsedTime().asMilliseconds() );
}

View File

@@ -41,7 +41,8 @@ UIScrollBar::UIScrollBar( const UIOrientation& orientation ) :
mBtnDown->setSize( 8, 8 );
mSlider = UISlider::NewWithTag( orientation == UIOrientation::Vertical ? "scrollbar::vslider"
: "scrollbar::hslider" );
: "scrollbar::hslider",
orientation );
mSlider->setLayoutSizeRules( LayoutSizeRule::Fixed, LayoutSizeRule::Fixed );
mSlider->setOrientation( orientation );
mSlider->setParent( this );

View File

@@ -6,18 +6,26 @@
namespace EE { namespace UI {
UISlider* UISlider::New() {
return NewWithTag( "slider" );
return NewWithTag( "slider", UIOrientation::Vertical );
}
UISlider* UISlider::NewWithTag( const std::string& tag ) {
UISlider* UISlider::NewWithTag( const std::string& tag, const UIOrientation& orientation ) {
return eeNew( UISlider, ( tag, orientation ) );
}
UISlider* UISlider::NewVertical() {
return NewVerticalWithTag( "slider" );
}
UISlider* UISlider::NewHorizontal() {
return NewHorizontalWithTag( "slider" );
}
UISlider* UISlider::NewVerticalWithTag( const std::string& tag ) {
return eeNew( UISlider, ( tag, UIOrientation::Vertical ) );
}
UISlider* UISlider::NewVertical( const std::string& tag ) {
return eeNew( UISlider, ( tag, UIOrientation::Vertical ) );
}
UISlider* UISlider::NewHorizontal( const std::string& tag ) {
UISlider* UISlider::NewHorizontalWithTag( const std::string& tag ) {
return eeNew( UISlider, ( tag, UIOrientation::Horizontal ) );
}

View File

@@ -83,6 +83,10 @@ void UIWidgetCreator::createBaseWidgetList() {
registeredWidget["inputpassword"] = UITextInputPassword::New;
registeredWidget["viewpagerhorizontal"] = UIViewPager::NewHorizontal;
registeredWidget["viewpagervertical"] = UIViewPager::NewHorizontal;
registeredWidget["vslider"] = UISlider::NewHorizontal;
registeredWidget["hslider"] = UISlider::NewHorizontal;
registeredWidget["vscrollbar"] = UIScrollBar::NewVertical;
registeredWidget["hscrollbar"] = UIScrollBar::NewHorizontal;
sBaseListCreated = true;
}