mirror of https://github.com/buggins/dlangui.git
parent
568b87cc5f
commit
9ccbbb307c
|
@ -189,7 +189,12 @@ immutable int SIZE_IN_PERCENTS_FLAG = 0x0800_0000;
|
|||
|
||||
/// convert custom size to pixels (sz can be either pixels, or points if SIZE_IN_POINTS_FLAG bit set)
|
||||
int toPixels(int sz) {
|
||||
return sz > 0 ? ((sz & SIZE_IN_POINTS_FLAG) ? pointsToPixels(sz ^ SIZE_IN_POINTS_FLAG) : sz) : sz;
|
||||
if (sz > 0 && (sz & SIZE_IN_POINTS_FLAG) != 0) {
|
||||
import dlangui.core.logger;
|
||||
Log.d("size in points");
|
||||
return pointsToPixels(sz ^ SIZE_IN_POINTS_FLAG);
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
/// convert custom size Point to pixels (sz can be either pixels, or points if SIZE_IN_POINTS_FLAG bit set)
|
||||
|
|
|
@ -273,21 +273,34 @@ class FrameDrawable : Drawable {
|
|||
|
||||
enum DimensionUnits {
|
||||
pixels,
|
||||
points
|
||||
points,
|
||||
percents
|
||||
}
|
||||
|
||||
/// decode size string, e.g. 1px or 2 or 3pt
|
||||
static uint decodeDimension(string s) {
|
||||
uint value = 0;
|
||||
DimensionUnits units = DimensionUnits.pixels;
|
||||
bool dotFound = false;
|
||||
uint afterPointValue = 0;
|
||||
uint afterPointDivider = 1;
|
||||
foreach(c; s) {
|
||||
int digit = -1;
|
||||
if (c >='0' && c <= '9')
|
||||
digit = c - '0';
|
||||
if (digit >= 0)
|
||||
value = value * 10 + digit;
|
||||
else if (c == 't') // just test by containing 't' - for NNNpt
|
||||
if (digit >= 0) {
|
||||
if (dotFound) {
|
||||
afterPointValue = afterPointValue * 10 + digit;
|
||||
afterPointDivider *= 10;
|
||||
} else {
|
||||
value = value * 10 + digit;
|
||||
}
|
||||
} else if (c == 't') // just test by containing 't' - for NNNpt
|
||||
units = DimensionUnits.points; // "pt"
|
||||
else if (c == '%')
|
||||
units = DimensionUnits.percents;
|
||||
else if (c == '.')
|
||||
dotFound = true;
|
||||
}
|
||||
// TODO: convert points to pixels
|
||||
switch(units) {
|
||||
|
@ -295,6 +308,10 @@ static uint decodeDimension(string s) {
|
|||
// need to convert points to pixels
|
||||
value |= SIZE_IN_POINTS_FLAG;
|
||||
break;
|
||||
case DimensionUnits.percents:
|
||||
// need to convert percents
|
||||
value = ((value * 100) + (afterPointValue * 100 / afterPointDivider)) | SIZE_IN_PERCENTS_FLAG;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import dlangui.widgets.styles;
|
|||
|
||||
Recent changes:
|
||||
Dimensions like fontSize, padding, margins, min/max width and height can be specified in points, e.g. minWidth = "3pt" margins="1pt,2pt,1pt,2pt"
|
||||
% for font size, based on parent font size, e.g. fontSize="120.5%" means parentStyle.fontSize * 120.5 / 100.0;
|
||||
|
||||
Copyright: Vadim Lopatin, 2014
|
||||
License: Boost License 1.0
|
||||
|
@ -443,9 +444,11 @@ class Style {
|
|||
|
||||
/// font size
|
||||
@property int fontSize() const {
|
||||
if (_fontSize != FONT_SIZE_UNSPECIFIED)
|
||||
if (_fontSize != FONT_SIZE_UNSPECIFIED) {
|
||||
if (_fontSize & SIZE_IN_PERCENTS_FLAG)
|
||||
return parentStyle.fontSize * (_fontSize ^ SIZE_IN_PERCENTS_FLAG) / 10000;
|
||||
return toPixels(_fontSize);
|
||||
else
|
||||
} else
|
||||
return parentStyle.fontSize;
|
||||
}
|
||||
|
||||
|
@ -1237,7 +1240,7 @@ bool loadStyleAttributes(Style style, Element elem, bool allowStates) {
|
|||
if ("fontFamily" in elem.tag.attr)
|
||||
style.fontFamily = decodeFontFamily(elem.tag.attr["fontFamily"]);
|
||||
if ("fontSize" in elem.tag.attr)
|
||||
style.fontSize = cast(ushort)decodeDimension(elem.tag.attr["fontSize"]);
|
||||
style.fontSize = cast(int)decodeDimension(elem.tag.attr["fontSize"]);
|
||||
if ("layoutWidth" in elem.tag.attr)
|
||||
style.layoutWidth = decodeLayoutDimension(elem.tag.attr["layoutWidth"]);
|
||||
if ("layoutHeight" in elem.tag.attr)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<theme id="theme_default"
|
||||
fontSize="11pt"
|
||||
fontSize="9pt"
|
||||
fontFace="Verdana,Arial,DejaVu Sans"
|
||||
fontFamily="SansSerif"
|
||||
>
|
||||
|
@ -421,7 +421,7 @@
|
|||
|
||||
<style id="SETTINGS_PAGE_TITLE"
|
||||
margins="4,4,4,14"
|
||||
fontSize="11pt"
|
||||
fontSize="120%"
|
||||
layoutWeight="0"
|
||||
layoutWidth="FILL_PARENT"
|
||||
/>
|
||||
|
|
Loading…
Reference in New Issue