diff --git a/src/dlangui/core/types.d b/src/dlangui/core/types.d index d8197b5f..b49dd066 100644 --- a/src/dlangui/core/types.d +++ b/src/dlangui/core/types.d @@ -173,6 +173,35 @@ struct Rect { } } +// Layout size constants +/// layout option, to occupy all available place +immutable int FILL_PARENT = 0x4000_0000; +/// layout option, for size based on content +immutable int WRAP_CONTENT = 0x2000_0000; +/// use as widget.layout() param to avoid applying of parent size +immutable int SIZE_UNSPECIFIED = 0x6000_0000; + +/// use in styles to specify size in points (1/72 inch) +immutable int SIZE_IN_POINTS_FLAG = 0x1000_0000; +/// (RESERVED) use in styles to specify size in percents * 100 (e.g. 0 == 0%, 10000 == 100%, 100 = 1%) +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; +} + +/// convert custom size Point to pixels (sz can be either pixels, or points if SIZE_IN_POINTS_FLAG bit set) +Point toPixels(const Point sz) { + return Point(toPixels(sz.x), toPixels(sz.y)); +} + +/// convert custom size Rect to pixels (sz can be either pixels, or points if SIZE_IN_POINTS_FLAG bit set) +Rect toPixels(const Rect sz) { + return Rect(toPixels(sz.left), toPixels(sz.top), toPixels(sz.right), toPixels(sz.bottom)); +} + /// screen dots per inch private __gshared int PRIVATE_SCREEN_DPI = 96; diff --git a/src/dlangui/graphics/resources.d b/src/dlangui/graphics/resources.d index 17abd4f6..e461b08d 100644 --- a/src/dlangui/graphics/resources.d +++ b/src/dlangui/graphics/resources.d @@ -292,8 +292,8 @@ static uint decodeDimension(string s) { // TODO: convert points to pixels switch(units) { case DimensionUnits.points: - // convert points to pixels - value = pointsToPixels(value); + // need to convert points to pixels + value |= SIZE_IN_POINTS_FLAG; break; default: break; @@ -301,6 +301,7 @@ static uint decodeDimension(string s) { return value; } + /// decode solid color / gradient / frame drawable from string like #AARRGGBB, e.g. #5599AA /// /// SolidFillDrawable: #AARRGGBB - e.g. #8090A0 or #80ffffff diff --git a/src/dlangui/platforms/sdl/sdlapp.d b/src/dlangui/platforms/sdl/sdlapp.d index cd7c08a4..7e2b473c 100644 --- a/src/dlangui/platforms/sdl/sdlapp.d +++ b/src/dlangui/platforms/sdl/sdlapp.d @@ -928,8 +928,16 @@ class SDLPlatform : Platform { override Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable, uint width = 0, uint height = 0) { setDefaultLanguageAndThemeIfNecessary(); + int oldDPI = SCREEN_DPI; SDLWindow res = new SDLWindow(this, windowCaption, parent, flags, width, height); _windowMap[res.windowId] = res; + version(Windows) { + width = pointsToPixels(width); + height = pointsToPixels(height); + res.doResize(width, height); + } + if (oldDPI != SCREEN_DPI) + onThemeChanged(); return res; } diff --git a/src/dlangui/platforms/windows/winapp.d b/src/dlangui/platforms/windows/winapp.d index 43b1f217..4cd1c62a 100644 --- a/src/dlangui/platforms/windows/winapp.d +++ b/src/dlangui/platforms/windows/winapp.d @@ -778,6 +778,8 @@ class Win32Platform : Platform { return null; } override Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable, uint width = 0, uint height = 0) { + width = pointsToPixels(width); + height = pointsToPixels(height); setDefaultLanguageAndThemeIfNecessary(); return new Win32Window(this, windowCaption, parent, flags, width, height); } diff --git a/src/dlangui/widgets/styles.d b/src/dlangui/widgets/styles.d index 9ce7f172..c1670b70 100644 --- a/src/dlangui/widgets/styles.d +++ b/src/dlangui/widgets/styles.d @@ -11,9 +11,11 @@ Synopsis: ---- 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" + Copyright: Vadim Lopatin, 2014 License: Boost License 1.0 Authors: Vadim Lopatin, coolreader.org@gmail.com @@ -180,13 +182,6 @@ immutable string STYLE_COLOR_WINDOW_BACKGROUND = "window_background"; immutable string STYLE_COLOR_DIALOG_BACKGROUND = "dialog_background"; -// Layout size constants -/// layout option, to occupy all available place -immutable int FILL_PARENT = int.max - 1; -/// layout option, for size based on content -immutable int WRAP_CONTENT = int.max - 2; -/// use as widget.layout() param to avoid applying of parent size -immutable int SIZE_UNSPECIFIED = int.max; // Other style constants @@ -262,8 +257,8 @@ class Style { protected ubyte _align = Align.TopLeft; protected ubyte _fontStyle = FONT_STYLE_UNSPECIFIED; protected FontFamily _fontFamily = FontFamily.Unspecified; - protected ushort _fontSize = FONT_SIZE_UNSPECIFIED; protected ushort _fontWeight = FONT_WEIGHT_UNSPECIFIED; + protected int _fontSize = FONT_SIZE_UNSPECIFIED; protected uint _backgroundColor = COLOR_UNSPECIFIED; protected uint _textColor = COLOR_UNSPECIFIED; protected uint _textFlags = 0; @@ -447,9 +442,9 @@ class Style { } /// font size - @property ushort fontSize() const { + @property int fontSize() const { if (_fontSize != FONT_SIZE_UNSPECIFIED) - return _fontSize; + return toPixels(_fontSize); else return parentStyle.fontSize; } @@ -458,17 +453,17 @@ class Style { // layout parameters: margins / padding /// padding - @property ref const(Rect) padding() const { + @property const(Rect) padding() const { if (_stateMask || _padding.left == SIZE_UNSPECIFIED) - return parentStyle._padding; - return _padding; + return toPixels(parentStyle._padding); + return toPixels(_padding); } /// margins - @property ref const(Rect) margins() const { + @property const(Rect) margins() const { if (_stateMask || _margins.left == SIZE_UNSPECIFIED) - return parentStyle._margins; - return _margins; + return toPixels(parentStyle._margins); + return toPixels(_margins); } /// alpha (0=opaque .. 255=transparent) @@ -528,28 +523,28 @@ class Style { /// minimal width constraint, 0 if limit is not set @property uint minWidth() const { if (_minWidth != SIZE_UNSPECIFIED) - return _minWidth; + return toPixels(_minWidth); else return parentStyle.minWidth; } /// max width constraint, returns SIZE_UNSPECIFIED if limit is not set @property uint maxWidth() const { if (_maxWidth != SIZE_UNSPECIFIED) - return _maxWidth; + return toPixels(_maxWidth); else return parentStyle.maxWidth; } /// minimal height constraint, 0 if limit is not set @property uint minHeight() const { if (_minHeight != SIZE_UNSPECIFIED) - return _minHeight; + return toPixels(_minHeight); else return parentStyle.minHeight; } /// max height constraint, SIZE_UNSPECIFIED if limit is not set @property uint maxHeight() const { if (_maxHeight != SIZE_UNSPECIFIED) - return _maxHeight; + return toPixels(_maxHeight); else return parentStyle.maxHeight; } @@ -660,7 +655,7 @@ class Style { return this; } - @property Style fontSize(ushort size) { + @property Style fontSize(int size) { _fontSize = size; _font.clear(); return this; @@ -832,7 +827,7 @@ class Theme : Style { _textColor = 0x000000; // black _maxLines = 1; _align = Align.TopLeft; - _fontSize = 14; // TODO: from settings or screen properties / DPI + _fontSize = 9 | SIZE_IN_POINTS_FLAG; // TODO: from settings or screen properties / DPI _fontStyle = FONT_STYLE_NORMAL; _fontWeight = 400; //_fontFace = "Arial"; // TODO: from settings diff --git a/src/dlangui/widgets/widget.d b/src/dlangui/widgets/widget.d index 3c848f1c..717e1cde 100644 --- a/src/dlangui/widgets/widget.d +++ b/src/dlangui/widgets/widget.d @@ -460,9 +460,9 @@ class Widget { return this; } /// returns font size in pixels - @property ushort fontSize() const { return stateStyle.fontSize; } + @property int fontSize() const { return stateStyle.fontSize; } /// set font size for widget - override one from style - @property Widget fontSize(ushort size) { + @property Widget fontSize(int size) { ownStyle.fontSize = size; requestLayout(); return this; diff --git a/views/res/theme_dark.xml b/views/res/theme_dark.xml index bb977764..aef2d7cb 100644 --- a/views/res/theme_dark.xml +++ b/views/res/theme_dark.xml @@ -1,7 +1,5 @@ @@ -28,24 +26,17 @@ - - - @@ -388,57 +243,14 @@ align="Center" /> - -