Skip to content

Commit 90f6593

Browse files
committed
Gfx::Legend percent unit fixed
1 parent bc2bb3d commit 90f6593

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/base/gfx/length.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Length::Length(const std::string &s)
1010
auto unit = parser.getUnit();
1111
if (unit == "%")
1212
{
13-
relative = parser.getValue();
13+
relative = parser.getValue() / 100.0;
1414
}
1515
else if (unit == "px" || unit.empty())
1616
{

src/base/gfx/length.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define GFX_LENGTH
33

44
#include <string>
5+
#include <stdexcept>
56

67
#include "base/text/valueunit.h"
78

@@ -19,16 +20,24 @@ class Length
1920
static Length Absolute(double value) { return Length(value, 0); }
2021
static Length Relative(double value) { return Length(0, value); }
2122

22-
Length(double abs, double rel) :
23+
Length(double abs, double rel = 0.0) :
2324
absolute(abs), relative(rel)
2425
{}
2526

2627
explicit Length(const std::string &s);
2728

29+
bool isAbsolute() const { return relative == 0.0; }
30+
bool isRelative() const { return absolute == 0.0; }
31+
2832
double get(double reference) const {
2933
return absolute + relative * reference;
3034
}
3135

36+
double get() const {
37+
if (isAbsolute()) return absolute;
38+
throw std::logic_error("internal error: relative length wo. reference");
39+
}
40+
3241
explicit operator std::string() const;
3342

3443
bool operator==(const Length &other) const {

0 commit comments

Comments
 (0)