From 9f01f1464556f6403eef597e948e6bfb730d546f Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Wed, 11 Feb 2015 13:33:03 +0300 Subject: [PATCH] allow specifying window size on creation --- dlanguilib.visualdproj | 2 +- examples/example1/src/example1.d | 2 +- src/dlangui/platforms/common/platform.d | 2 +- src/dlangui/platforms/sdl/sdlapp.d | 16 +++++++++----- src/dlangui/platforms/windows/winapp.d | 16 +++++++++----- src/dlangui/widgets/editors.d | 28 +++++++++---------------- 6 files changed, 35 insertions(+), 31 deletions(-) diff --git a/dlanguilib.visualdproj b/dlanguilib.visualdproj index 63ecfed8..34a97e5c 100644 --- a/dlanguilib.visualdproj +++ b/dlanguilib.visualdproj @@ -66,7 +66,7 @@ 0 DebugFocus 0 - EmbedStandardResources Unicode USE_FREETYPE + EmbedStandardResources Unicode USE_FREETYPE USE_SDL 0 0 1 diff --git a/examples/example1/src/example1.d b/examples/example1/src/example1.d index 28aa18bc..0306c44a 100644 --- a/examples/example1/src/example1.d +++ b/examples/example1/src/example1.d @@ -251,7 +251,7 @@ extern (C) int UIAppMain(string[] args) { //} // create window - Window window = Platform.instance.createWindow("My Window", null); + Window window = Platform.instance.createWindow("My Window", null, WindowFlag.Resizable, 700, 500); static if (true) { VerticalLayout contentLayout = new VerticalLayout(); diff --git a/src/dlangui/platforms/common/platform.d b/src/dlangui/platforms/common/platform.d index 46e5b89c..4eb18253 100644 --- a/src/dlangui/platforms/common/platform.d +++ b/src/dlangui/platforms/common/platform.d @@ -1073,7 +1073,7 @@ class Platform { * * Window w/o Resizable nor Fullscreen will be created with size based on measurement of its content widget */ - abstract Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable); + abstract Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable, uint width = 0, uint height = 0); /** * close window * diff --git a/src/dlangui/platforms/sdl/sdlapp.d b/src/dlangui/platforms/sdl/sdlapp.d index 848bc5b1..fea4ad39 100644 --- a/src/dlangui/platforms/sdl/sdlapp.d +++ b/src/dlangui/platforms/sdl/sdlapp.d @@ -60,10 +60,12 @@ class SDLWindow : Window { SDLPlatform _platform; SDL_Window * _win; SDL_Renderer* _renderer; - this(SDLPlatform platform, dstring caption, Window parent, uint flags) { + this(SDLPlatform platform, dstring caption, Window parent, uint flags, uint width = 0, uint height = 0) { _platform = platform; _caption = caption; debug Log.d("Creating SDL window"); + _dx = width; + _dy = height; create(flags); } @@ -100,6 +102,10 @@ class SDLWindow : Window { protected uint _flags; bool create(uint flags) { + if (!_dx) + _dx = 600; + if (!_dy) + _dy = 400; _flags = flags; uint windowFlags = SDL_WINDOW_HIDDEN; if (flags & WindowFlag.Resizable) @@ -116,7 +122,7 @@ class SDLWindow : Window { _glSupport = new GLSupport(); } _win = SDL_CreateWindow(toUTF8(_caption).toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - 800, 600, + _dx, _dy, windowFlags); version(USE_OPENGL) { if (!_win) { @@ -126,7 +132,7 @@ class SDLWindow : Window { // recreate w/o OpenGL windowFlags &= ~SDL_WINDOW_OPENGL; _win = SDL_CreateWindow(toUTF8(_caption).toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - 800, 600, + _dx, _dy, windowFlags); } } @@ -851,9 +857,9 @@ class SDLPlatform : Platform { } - override Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable) { + override Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable, uint width = 0, uint height = 0) { setDefaultLanguageAndThemeIfNecessary(); - SDLWindow res = new SDLWindow(this, windowCaption, parent, flags); + SDLWindow res = new SDLWindow(this, windowCaption, parent, flags, width, height); _windowMap[res.windowId] = res; return res; } diff --git a/src/dlangui/platforms/windows/winapp.d b/src/dlangui/platforms/windows/winapp.d index bc6a5fbf..8a39eea4 100644 --- a/src/dlangui/platforms/windows/winapp.d +++ b/src/dlangui/platforms/windows/winapp.d @@ -167,9 +167,15 @@ class Win32Window : Window { Win32ColorDrawBuf _drawbuf; bool useOpengl; uint _flags; - this(Win32Platform platform, dstring windowCaption, Window parent, uint flags) { + this(Win32Platform platform, dstring windowCaption, Window parent, uint flags, uint width = 0, uint height = 0) { Win32Window w32parent = cast(Win32Window)parent; HWND parenthwnd = w32parent ? w32parent._hwnd : null; + _dx = width; + _dy = height; + if (!_dx) + _dx = 600; + if (!_dy) + _dy = 400; _platform = platform; version (USE_OPENGL) { _gl = new GLSupport(); @@ -188,8 +194,8 @@ class Win32Window : Window { ws, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position - CW_USEDEFAULT, // initial x size - CW_USEDEFAULT, // initial y size + _dx, // initial x size + _dy, // initial y size parenthwnd, // parent window handle null, // window menu handle _hInstance, // program instance handle @@ -762,9 +768,9 @@ class Win32Platform : Platform { return _windowMap[cast(ulong)hwnd]; return null; } - override Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable) { + override Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable, uint width = 0, uint height = 0) { setDefaultLanguageAndThemeIfNecessary(); - return new Win32Window(this, windowCaption, parent, flags); + return new Win32Window(this, windowCaption, parent, flags, width, height); } /// calls request layout for all windows diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 7f1e3545..ea56e7fc 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -200,7 +200,7 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction // TODO: move to styles protected uint _selectionColorFocused = 0xB060A0FF; protected uint _selectionColorNormal = 0xD060A0FF; - protected uint _leftPaneBackgroundColor = 0xE0E0E0; + protected uint _leftPaneBackgroundColor = 0xF4F4F4; protected uint _leftPaneBackgroundColor2 = 0xFFFFFF; protected uint _leftPaneBackgroundColor3 = 0xC0C0C0; protected uint _leftPaneLineNumberColor = 0x4060D0; @@ -246,11 +246,11 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction } protected void drawLeftPaneFolding(DrawBuf buf, Rect rc, int line) { - buf.fillRect(rc, 0xF0F0F0); + buf.fillRect(rc, 0xFFFFFF); } protected void drawLeftPaneIcons(DrawBuf buf, Rect rc, int line) { - buf.fillRect(rc, 0xC0C0C0); + buf.fillRect(rc, 0xE0E0E0); } protected void drawLeftPaneModificationMarks(DrawBuf buf, Rect rc, int line) { @@ -281,24 +281,24 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction protected void drawLeftPane(DrawBuf buf, Rect rc, int line) { // override for custom drawn left pane buf.fillRect(rc, _leftPaneBackgroundColor); - buf.fillRect(Rect(rc.right - 2, rc.top, rc.right - 1, rc.bottom), _leftPaneBackgroundColor2); - buf.fillRect(Rect(rc.right - 1, rc.top, rc.right - 0, rc.bottom), _leftPaneBackgroundColor3); + //buf.fillRect(Rect(rc.right - 2, rc.top, rc.right - 1, rc.bottom), _leftPaneBackgroundColor2); + //buf.fillRect(Rect(rc.right - 1, rc.top, rc.right - 0, rc.bottom), _leftPaneBackgroundColor3); rc.right -= 3; if (_foldingWidth) { Rect rc2 = rc; rc.right = rc2.left = rc2.right - _foldingWidth; drawLeftPaneFolding(buf, rc2, line); } - if (_lineNumbersWidth) { - Rect rc2 = rc; - rc.right = rc2.left = rc2.right - _lineNumbersWidth; - drawLeftPaneLineNumbers(buf, rc2, line); - } if (_modificationMarksWidth) { Rect rc2 = rc; rc.right = rc2.left = rc2.right - _modificationMarksWidth; drawLeftPaneModificationMarks(buf, rc2, line); } + if (_lineNumbersWidth) { + Rect rc2 = rc; + rc.right = rc2.left = rc2.right - _lineNumbersWidth; + drawLeftPaneLineNumbers(buf, rc2, line); + } if (_iconsWidth) { Rect rc2 = rc; rc.right = rc2.left = rc2.right - _iconsWidth; @@ -440,14 +440,6 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction if (!_popupMenu.onBeforeOpeningSubmenu(_popupMenu)) return; _popupMenu.updateActionState(this); - //for (int i = 0; i < _popupMenu.subitemCount; i++) { - // MenuItem item = _popupMenu.subitem(i); - // if (item.action && isActionEnabled(item.action)) { - // item.enabled = true; - // } else { - // item.enabled = false; - // } - //} PopupMenu popupMenu = new PopupMenu(_popupMenu); popupMenu.onMenuItemActionListener = this; PopupWidget popup = window.showPopup(popupMenu, this, PopupAlign.Point | PopupAlign.Right, x, y);