-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,346 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ | |
#include "base/matrix.h" | ||
#include "base/range.h" | ||
#include "base/value.h" | ||
#include "base/length.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.