Skip to content

Commit

Permalink
update style
Browse files Browse the repository at this point in the history
  • Loading branch information
hicdre committed Nov 4, 2014
1 parent 4b4611c commit c20e676
Show file tree
Hide file tree
Showing 20 changed files with 1,346 additions and 190 deletions.
4 changes: 4 additions & 0 deletions Demo/Demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,

//ui::Widget* widget = ui::WidgetView::CreateWidget(new DemoWidget);

ui::StyleTokenReader reader("background: url(\"something.png\");");
int tt = reader.get(NULL);
ui::StyleToken* t = reader.token_;

ui::Window* window = new ui::Window;
window->LoadFile(L"test.xml");
window->AttachWidget(ui::Widget::Create());
Expand Down
9 changes: 9 additions & 0 deletions DuiFramework/DuiFramwork.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="base\length.cpp" />
<ClCompile Include="base\padding.cpp" />
<ClCompile Include="base\point.cpp" />
<ClCompile Include="base\range.cpp" />
Expand Down Expand Up @@ -135,11 +136,14 @@
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="style\style_reader.cpp" />
<ClCompile Include="style\style_token_reader.cpp" />
<ClCompile Include="third_party\stb_image.cpp" />
<ClCompile Include="third_party\tinyxml2.cpp" />
<ClCompile Include="utils\app_init_helper.cpp" />
<ClCompile Include="utils\image_file.cpp" />
<ClCompile Include="utils\image_store.cpp" />
<ClCompile Include="utils\lex_parser.cpp" />
<ClCompile Include="utils\utils.cpp" />
<ClCompile Include="view\view_background.cpp" />
<ClCompile Include="view\view_border.cpp" />
Expand All @@ -151,6 +155,7 @@
<ClInclude Include="base\base_defines.h" />
<ClInclude Include="base\basictypes.h" />
<ClInclude Include="base\color.h" />
<ClInclude Include="base\length.h" />
<ClInclude Include="base\padding.h" />
<ClInclude Include="base\point.h" />
<ClInclude Include="base\range.h" />
Expand Down Expand Up @@ -204,12 +209,16 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="stdafx.h" />
<ClInclude Include="style\style_reader.h" />
<ClInclude Include="style\style_tokens.h" />
<ClInclude Include="style\style_token_reader.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="third_party\stb_image.h" />
<ClInclude Include="third_party\tinyxml2.h" />
<ClInclude Include="utils\app_init_helper.h" />
<ClInclude Include="utils\image_file.h" />
<ClInclude Include="utils\image_store.h" />
<ClInclude Include="utils\lex_parser.h" />
<ClInclude Include="utils\utils.h" />
<ClInclude Include="view\view_background.h" />
<ClInclude Include="view\view_border.h" />
Expand Down
30 changes: 30 additions & 0 deletions DuiFramework/DuiFramwork.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<Filter Include="dom">
<UniqueIdentifier>{966e277f-09e0-4027-922a-b8db1577697e}</UniqueIdentifier>
</Filter>
<Filter Include="style">
<UniqueIdentifier>{aa7fb73c-905b-45ea-b9e1-a46578b5eaa4}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
Expand Down Expand Up @@ -159,6 +162,18 @@
<ClCompile Include="control\window_builder.cpp">
<Filter>control</Filter>
</ClCompile>
<ClCompile Include="utils\lex_parser.cpp">
<Filter>utils</Filter>
</ClCompile>
<ClCompile Include="base\length.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="style\style_reader.cpp">
<Filter>style</Filter>
</ClCompile>
<ClCompile Include="style\style_token_reader.cpp">
<Filter>style</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
Expand Down Expand Up @@ -303,5 +318,20 @@
<ClInclude Include="control\window_builder.h">
<Filter>control</Filter>
</ClInclude>
<ClInclude Include="utils\lex_parser.h">
<Filter>utils</Filter>
</ClInclude>
<ClInclude Include="base\length.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="style\style_reader.h">
<Filter>style</Filter>
</ClInclude>
<ClInclude Include="style\style_token_reader.h">
<Filter>style</Filter>
</ClInclude>
<ClInclude Include="style\style_tokens.h">
<Filter>style</Filter>
</ClInclude>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions DuiFramework/base/basictypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
#include "base/matrix.h"
#include "base/range.h"
#include "base/value.h"
#include "base/length.h"

109 changes: 109 additions & 0 deletions DuiFramework/base/length.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "stdafx.h"
#include "length.h"

namespace ui
{
Length::Length()
: type_(Auto)
, int_value_(0)
, is_float_(false)
{

}

Length::Length(LengthType type)
: type_(type)
, int_value_(0)
, is_float_(false)
{

}

Length::Length(int v, LengthType t)
: type_(t)
, int_value_(v)
, is_float_(false)
{

}

Length::Length(float v, LengthType t)
: type_(t)
, float_value_(v)
, is_float_(true)
{

}

bool Length::IsAuto() const
{
return type_ == Auto;
}

bool Length::IsPercent() const
{
return type_ == Percent;
}

bool Length::IsFixed() const
{
return type_ == Fixed;
}

float Length::percent() const
{
assert(IsPercent());
return float_value_;
}

int Length::intValue() const
{
return is_float_ ? static_cast<int>(float_value_) : int_value_;
}

float Length::value() const
{
return is_float_ ? float_value_ : static_cast<float>(int_value_);
}

void Length::setValue(LengthType t, int value)
{
type_ = t;
float_value_ = value;
is_float_ = false;
}

void Length::setValue(LengthType t, float value)
{
type_ = t;
float_value_ = value;
is_float_ = true;
}

void Length::setValue(float value)
{
*this = Length(value, Fixed);
}

ui::LengthType Length::type() const
{
return type_;
}

// ui::Length Length::FromString(const std::string& str)
// {
// const char* p = str.c_str();
// char* end = NULL;
// float f = strtof(p, &end);
//
// while (*end && isspace(*end))
// end++;
//
// if (*end == 0)
// return Length(f, Fixed);
// else if (*end == '%')
// return Length((float)(f / 100.0), Percent);
// else
// return Length();
// }
}
46 changes: 46 additions & 0 deletions DuiFramework/base/length.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

namespace ui
{
enum LengthType {
Auto, Percent, Fixed,
Intrinsic, MinIntrinsic,
MinContent, MaxContent, FillAvailable, FitContent,
Calculated,
ExtendToZoom, DeviceWidth, DeviceHeight,
MaxSizeNone
};

class Length
{
public:
Length();
Length(LengthType type);
Length(int v, LengthType t);
Length(float v, LengthType t);

LengthType type() const;
bool IsAuto() const;
bool IsPercent() const;
bool IsFixed() const;

float percent() const;
int intValue() const;
float value() const;

void setValue(float value);

void setValue(LengthType t, float value);

void setValue(LengthType t, int value);

//static Length FromString(const std::string& str);
private:
LengthType type_;
union {
int int_value_;
float float_value_;
};
bool is_float_;
};
}
2 changes: 1 addition & 1 deletion DuiFramework/base/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace ui
Matrix Invert() const;

XFORM ToXFORM() const;
private:
public:
float a, b, c, d;
float tx, ty;
};
Expand Down
12 changes: 6 additions & 6 deletions DuiFramework/control/window_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ namespace ui
const char* val = xml_element->Attribute("width");
if (val)
{
box->setWidth(Length::FromString(val));
//box->setWidth(Length::FromString(val));
}
}
{
const char* val = xml_element->Attribute("height");
if (val)
{
box->setHeight(Length::FromString(val));
//box->setHeight(Length::FromString(val));
}
}
{
Expand Down Expand Up @@ -159,28 +159,28 @@ namespace ui
const char* val = xml_element->Attribute("marginLeft", marginLeft);
if (val)
{
box->setMarginLeft(Length::FromString(val));
//box->setMarginLeft(Length::FromString(val));
}
}
{
const char* val = xml_element->Attribute("marginTop", marginTop);
if (val)
{
box->setMarginTop(Length::FromString(val));
//box->setMarginTop(Length::FromString(val));
}
}
{
const char* val = xml_element->Attribute("marginRight", marginRight);
if (val)
{
box->setMarginRight(Length::FromString(val));
//box->setMarginRight(Length::FromString(val));
}
}
{
const char* val = xml_element->Attribute("marginBottom", marginBottom);
if (val)
{
box->setMarginBottom(Length::FromString(val));
//box->setMarginBottom(Length::FromString(val));
}
}

Expand Down
2 changes: 2 additions & 0 deletions DuiFramework/duiframework.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
#include "view/view.h"


#include "style/style_token_reader.h"

//#include "layout/box_layout.h"
//#include "layout/frame_layout.h"
Loading

0 comments on commit c20e676

Please sign in to comment.