From a51c058696d5ec735994790770fa8ca1d4dbcb7d Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Wed, 17 Dec 2014 16:24:01 +0300 Subject: [PATCH] File Dialog - continue development; StringGridWidget - support custom drawn cells adapter --- res/mdpi/folder.png | Bin 0 -> 652 bytes res/mdpi/text-plain.png | Bin 0 -> 540 bytes src/dlangui/core/files.d | 59 +++++++++++++++++++++ src/dlangui/dialogs/filedlg.d | 96 ++++++++++++++++++++++++++++++---- src/dlangui/widgets/grid.d | 23 ++++++++ 5 files changed, 168 insertions(+), 10 deletions(-) create mode 100644 res/mdpi/folder.png create mode 100644 res/mdpi/text-plain.png diff --git a/res/mdpi/folder.png b/res/mdpi/folder.png new file mode 100644 index 0000000000000000000000000000000000000000..13c1962412823b050818788b4142d61e43a65428 GIT binary patch literal 652 zcmV;70(1R|P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01ejw01ejxLMWSf00007bV*G`2ipY* z5i2$wS3qO{00In2L_t(I%Z-xHOI1-2$3HXoc%Ql~sGvo;EF+;Gt}+*RVT=GN5NBQt+jYI_yer~lm zH+GB*=f^PfdSrmn2nm*?yj^QZ(&N!rfEPq}l9N4#up`(MuBJVQQrPg~^ z15O)#%&pE7Hrm<4EVqdwcSOLv46=vn?kh=o1r!8uClYDreplFY@(e{j0toJkAh=7{ mzB`Ci0;CitVmMB3|LiaPSNus#?|G&G0000N&G8<8|5R)2wiKvEa}hEY4}7{M67VkNUs zjHA)aj2|XLr`+Gc0r2yu-GnwQWt2DnX%bY+VRwz-8&cR@Sdc6)^*Bu2ID{|ayHeB1b4a>5` z9j7o1gPUCwq*5uUs>*JPqVRk4Z*S4-_4o}MjRtRHI2^hsu*jX91-TxLM#$xI_;q=S zY&MI0K5x^V5cv2^Ae~M_y}QGoejnX#muHX1aNM1pmDoem!aCmn}TK z_;@^qBuTbT^}B= 0) + return true; + return false; + } + + protected DrawableRef rowIcon(int row) { + string iconId = toUTF8(list.cellText(0, row)); + DrawableRef res; + if (iconId.length) + res = drawableCache.get(iconId); + return res; + } + + /// return cell size + override Point measureCell(int col, int row) { + DrawableRef icon = rowIcon(row); + if (icon.isNull) + return Point(0, 0); + return Point(icon.width + 2, icon.height + 2); + } + + /// draw data cell content + override void drawCell(DrawBuf buf, Rect rc, int col, int row) { + DrawableRef img = rowIcon(row); + if (!img.isNull) { + Point sz; + sz.x = img.width; + sz.y = img.height; + applyAlign(rc, sz, Align.HCenter, Align.VCenter); + uint st = state; + img.drawTo(buf, rc, st); + } + } + protected Widget createRootsList() { ListWidget list = new ListWidget("ROOTS_LIST"); WidgetListAdapter adapter = new WidgetListAdapter(); @@ -76,7 +147,7 @@ class FileDialog : Dialog { btn.styleId = "TRANSPARENT_BUTTON_BACKGROUND"; btn.focusable = false; btn.onClickListener = delegate(Widget source) { - rootEntrySelected(root); + openDirectory(root.path); return true; }; adapter.widgets.add(btn); @@ -110,10 +181,11 @@ class FileDialog : Dialog { rightPanel.addChild(path); list = new StringGridWidget("files"); list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); - list.resize(3, 3); - list.setColTitle(0, "Name"d); - list.setColTitle(1, "Size"d); - list.setColTitle(2, "Modified"d); + list.resize(4, 3); + list.setColTitle(0, " "d); + list.setColTitle(1, "Name"d); + list.setColTitle(2, "Size"d); + list.setColTitle(3, "Modified"d); list.showRowHeaders = false; list.rowSelect = true; rightPanel.addChild(list); @@ -128,7 +200,11 @@ class FileDialog : Dialog { addChild(content); addChild(createButtonsPanel([ACTION_OPEN, ACTION_CANCEL], 0, 0)); - string[] path = splitPath("/home/lve/src"); - Log.d("path: ", path); + //string[] path = splitPath("/home/lve/src"); + //Log.d("path: ", path); + + list.customCellAdapter = this; + + openDirectory(currentDir); } } diff --git a/src/dlangui/widgets/grid.d b/src/dlangui/widgets/grid.d index 56956f5d..150b250a 100644 --- a/src/dlangui/widgets/grid.d +++ b/src/dlangui/widgets/grid.d @@ -202,8 +202,25 @@ enum GridActions : int { SelectDocumentEnd, } +interface CustomGridCellAdapter { + /// return true for custom drawn cell + bool isCustomCell(int col, int row); + /// return cell size + Point measureCell(int col, int row); + /// draw data cell content + void drawCell(DrawBuf buf, Rect rc, int col, int row); +} + /// Abstract grid widget class GridWidgetBase : ScrollWidgetBase { + protected CustomGridCellAdapter _customCellAdapter; + + /// Get adapter to override drawing of some particular cells + @property CustomGridCellAdapter customCellAdapter() { return _customCellAdapter; } + /// Set adapter to override drawing of some particular cells + @property GridWidgetBase customCellAdapter(CustomGridCellAdapter adapter) { _customCellAdapter = adapter; return this; } + + /// column count (including header columns and fixed columns) protected int _cols; /// row count (including header rows and fixed rows) @@ -1140,6 +1157,9 @@ class StringGridWidget : StringGridWidgetBase { } protected override Point measureCell(int x, int y) { + if (_customCellAdapter && _customCellAdapter.isCustomCell(x, y)) { + return _customCellAdapter.measureCell(x, y); + } //Log.d("measureCell ", x, ", ", y); FontRef fnt = font; dstring txt; @@ -1158,6 +1178,9 @@ class StringGridWidget : StringGridWidgetBase { /// draw cell content protected override void drawCell(DrawBuf buf, Rect rc, int col, int row) { + if (_customCellAdapter && _customCellAdapter.isCustomCell(col, row)) { + return _customCellAdapter.drawCell(buf, rc, col, row); + } rc.shrink(2, 1); FontRef fnt = font; dstring txt = cellText(col, row);