FileDialog improvements; grid and file dialog fixes for Console mode

This commit is contained in:
Vadim Lopatin 2016-10-21 16:02:58 +03:00
parent a60b65a338
commit dfe7073222
6 changed files with 92 additions and 22 deletions

View File

@ -105,7 +105,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
protected EditLine _edFilename;
protected ComboBox _cbFilters;
protected StringGridWidget _fileList;
protected VerticalLayout leftPanel;
protected Widget leftPanel;
protected VerticalLayout rightPanel;
protected Action _action;
@ -282,7 +282,11 @@ class FileDialog : Dialog, CustomGridCellAdapter {
(size < 1024*1024 ? "%.1f".format(size/1024) ~ " KB" :
(size < 1024*1024*1024 ? "%.1f".format(size/(1024*1024)) ~ " MB" :
"%.1f".format(size/(1024*1024*1024)) ~ " GB"));
date = _entries[i].timeLastModified.toSimpleString();
import std.datetime;
SysTime ts = _entries[i].timeLastModified;
//string timeString = "%04d.%02d.%02d %02d:%02d:%02d".format(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
string timeString = "%04d.%02d.%02d %02d:%02d".format(ts.year, ts.month, ts.day, ts.hour, ts.minute);
date = timeString;
}
_fileList.setCellText(2, i, toUTF32(sz));
_fileList.setCellText(3, i, toUTF32(date));
@ -290,8 +294,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
if(_fileList.height > 0)
_fileList.scrollTo(0, 0);
_fileList.autoFitColumnWidths();
_fileList.fillColumnWidth(1);
autofitGrid();
if (selectionIndex >= 0)
_fileList.selectCell(1, selectionIndex + 1, true);
else if (_entries.length > 0)
@ -299,6 +302,12 @@ class FileDialog : Dialog, CustomGridCellAdapter {
return true;
}
void autofitGrid() {
_fileList.autoFitColumnWidths();
_fileList.setColWidth(1, 0);
_fileList.fillColumnWidth(1);
}
override bool onKeyEvent(KeyEvent event) {
if (event.action == KeyAction.KeyDown) {
if (event.keyCode == KeyCode.BACK && event.flags == 0) {
@ -311,7 +320,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
/// return true for custom drawn cell
override bool isCustomCell(int col, int row) {
if (col == 0 && row >= 0)
if ((col == 0 || col == 1) && row >= 0)
return true;
return false;
}
@ -326,14 +335,40 @@ class FileDialog : Dialog, CustomGridCellAdapter {
/// return cell size
override Point measureCell(int col, int row) {
if (col == 1) {
FontRef fnt = _fileList.font;
dstring txt = _fileList.cellText(col, row);
Point sz = fnt.textSize(txt);
if (sz.y < fnt.height)
sz.y = fnt.height;
return sz;
}
DrawableRef icon = rowIcon(row);
if (icon.isNull)
return Point(0, 0);
return Point(icon.width + 2, icon.height + 2);
return Point(icon.width + 2.pointsToPixels, icon.height + 2.pointsToPixels);
}
/// draw data cell content
override void drawCell(DrawBuf buf, Rect rc, int col, int row) {
if (col == 1) {
if (BACKEND_GUI)
rc.shrink(2, 1);
else
rc.right--;
FontRef fnt = _fileList.font;
dstring txt = _fileList.cellText(col, row);
Point sz = fnt.textSize(txt);
Align ha = Align.Left;
//if (sz.y < rc.height)
// applyAlign(rc, sz, ha, Align.VCenter);
int offset = BACKEND_CONSOLE ? 0 : 1;
uint cl = _fileList.textColor;
if (_entries[row].isDir)
cl = style.customColor("file_dialog_dir_name_color", cl);
fnt.drawText(buf, rc.left + offset, rc.top + offset, txt, cl);
return;
}
DrawableRef img = rowIcon(row);
if (!img.isNull) {
Point sz;
@ -347,7 +382,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
protected ListWidget createRootsList() {
ListWidget res = new ListWidget("ROOTS_LIST");
res.styleId = STYLE_EDIT_BOX;
res.styleId = STYLE_LIST_BOX;
WidgetListAdapter adapter = new WidgetListAdapter();
foreach(ref RootEntry root; _roots) {
ImageTextButton btn = new ImageTextButton(null, root.icon, root.label);
@ -479,9 +514,13 @@ class FileDialog : Dialog, CustomGridCellAdapter {
content.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); //.minWidth(400).minHeight(300);
leftPanel = new VerticalLayout("places");
leftPanel.addChild(createRootsList());
leftPanel.layoutHeight(FILL_PARENT).minWidth(BACKEND_CONSOLE ? 7 : 40);
//leftPanel = new VerticalLayout("places");
//leftPanel.addChild(createRootsList());
//leftPanel.layoutHeight(FILL_PARENT).minWidth(BACKEND_CONSOLE ? 7 : 40);
leftPanel = createRootsList();
leftPanel.minWidth(BACKEND_CONSOLE ? 7 : 40.pointsToPixels);
rightPanel = new VerticalLayout("main");
rightPanel.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT);
@ -574,8 +613,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
/// Set widget rectangle to specified value and layout widget contents. (Step 2 of two phase layout).
override void layout(Rect rc) {
super.layout(rc);
_fileList.autoFitColumnWidths();
_fileList.fillColumnWidth(1);
autofitGrid();
}
@ -618,7 +656,7 @@ class FilePathPanelItem : HorizontalLayout {
_text.click = &onTextClick;
//_text.backgroundColor = 0xC0FFFF;
_text.state = State.Parent;
_button = new ImageButton(null, "scrollbar_btn_right");
_button = new ImageButton(null, ATTR_SCROLLBAR_BUTTON_RIGHT);
_button.styleId = STYLE_BUTTON_TRANSPARENT;
_button.focusable = false;
_button.click = &onButtonClick;
@ -627,7 +665,7 @@ class FilePathPanelItem : HorizontalLayout {
trackHover(true);
addChild(_text);
addChild(_button);
margins(Rect(2,0,2,0));
margins(Rect(2.pointsToPixels + 1, 0, 2.pointsToPixels + 1, 0));
}
private bool onTextClick(Widget src) {
if (onPathSelectionListener.assigned)
@ -704,10 +742,10 @@ class FilePathPanelButtons : WidgetGroupDefaultDrawing {
if (parentHeight != SIZE_UNSPECIFIED)
pheight -= m.top + m.bottom + p.top + p.bottom;
int reservedForEmptySpace = parentWidth / 20;
if (reservedForEmptySpace > 40)
reservedForEmptySpace = 40;
if (reservedForEmptySpace < 4)
reservedForEmptySpace = 4;
if (reservedForEmptySpace > 40.pointsToPixels)
reservedForEmptySpace = 40.pointsToPixels;
if (reservedForEmptySpace < 4.pointsToPixels)
reservedForEmptySpace = 4.pointsToPixels;
Point sz;
sz.x += reservedForEmptySpace;

View File

@ -1371,8 +1371,8 @@ class GridWidgetBase : ScrollWidgetBase, GridModelAdapter, MenuItemActionHandler
if (m < 10)
m = 10; // TODO: use min size
} else {
if (m < 3)
m = 3; // TODO: use min size
if (m < 1)
m = 1; // TODO: use min size
}
return m;
}
@ -1403,12 +1403,14 @@ class GridWidgetBase : ScrollWidgetBase, GridModelAdapter, MenuItemActionHandler
totalw += _colWidths[i];
if (w > totalw)
_colWidths[colIndex + _headerCols] += w - totalw;
updateCumulativeSizes();
invalidate();
}
void autoFitColumnWidths() {
for (int i = 0; i < _cols; i++)
autoFitColumnWidth(i);
updateCumulativeSizes();
invalidate();
}
@ -1622,7 +1624,9 @@ class StringGridWidget : StringGridWidgetBase {
ha = Align.HCenter;
applyAlign(rc, sz, ha, Align.VCenter);
int offset = BACKEND_CONSOLE ? 0 : 1;
fnt.drawText(buf, rc.left + offset, rc.top + offset, txt, textColor);
uint cl = textColor;
cl = style.customColor("grid_cell_text_color_header", cl);
fnt.drawText(buf, rc.left + offset, rc.top + offset, txt, cl);
}
/// draw cell background

View File

@ -111,6 +111,8 @@ immutable string STYLE_LIST_ITEM = "LIST_ITEM";
immutable string STYLE_EDIT_LINE = "EDIT_LINE";
/// standard style id for EditBox
immutable string STYLE_EDIT_BOX = "EDIT_BOX";
/// standard style id for lists
immutable string STYLE_LIST_BOX = "LIST_BOX";
/// standard style id for StringGrid
immutable string STYLE_STRING_GRID = "STRING_GRID";
/// standard style id for background similar to transparent button

View File

@ -31,8 +31,10 @@
<color id="grid_cell_background_fixed" value="#FFFFFFFF"/>
<color id="grid_cell_border_color" value="#C0C0C0C0"/>
<color id="grid_cell_border_color_header" value="#C0202020"/>
<color id="grid_cell_text_color_header" value="#FFFFFF"/>
<color id="grid_cell_background_header" value="#808080"/>
<color id="grid_cell_background_header_selected" value="#008000"/>
<color id="file_dialog_dir_name_color" value="#FFFF00"/>
<drawable id="arrow_right_down_black" value="{'▼ ' #008000}"/>
<drawable id="arrow_right_hollow" value="{'► ' #008000}"/>
@ -330,7 +332,6 @@
<state state_focused="true" backgroundImageId="{'┌─┐' '│ │' '└─┘' 0xFFFF00 bc 0xFFFFFFFF ninepatch 1 1 1 1 padding 1 1 1 1}"/>
</style>
<style id="EDIT_BOX"
fontFace="Menlo,Consolas,DejaVuSansMono,Lucida Sans Typewriter,Courier New,Lucida Console"
backgroundImageId="{'┌─┐' '│ │' '└─┘' 0x808080 bc 0xFFFFFFFF ninepatch 1 1 1 1 padding 1 1 0 0}"
padding="1,1,0,0"
margins="0,0,0,0"
@ -343,6 +344,19 @@
<state state_focused="true" backgroundImageId="{'┌─┐' '│ │' '└─┘' 0xFFFF00 bc 0xFFFFFFFF ninepatch 1 1 1 1 padding 1 1 0 0}"/>
<state state_enabled="true" backgroundImageId="{'┌─┐' '│ │' '└─┘' 0x808080 bc 0xFFFFFFFF ninepatch 1 1 1 1 padding 1 1 0 0}"/>
</style>
<style id="LIST_BOX"
backgroundImageId="{'┌─┐' '│ │' '└─┘' 0x808080 bc 0xFFFFFFFF ninepatch 1 1 1 1 padding 1 1 0 0}"
padding="1,1,1,1"
margins="0,0,0,0"
minWidth="8"
minHeight="3"
layoutWidth="FILL_PARENT"
layoutHeight="FILL_PARENT"
>
<state state_focused="true" state_window_focused="true" backgroundImageId="{'┌─┐' '│ │' '└─┘' 0xFFFF00 bc 0xFFFFFFFF ninepatch 1 1 1 1 padding 1 1 0 0}"/>
<state state_focused="true" backgroundImageId="{'┌─┐' '│ │' '└─┘' 0xFFFF00 bc 0xFFFFFFFF ninepatch 1 1 1 1 padding 1 1 0 0}"/>
<state state_enabled="true" backgroundImageId="{'┌─┐' '│ │' '└─┘' 0x808080 bc 0xFFFFFFFF ninepatch 1 1 1 1 padding 1 1 0 0}"/>
</style>
<style id="EDIT_BOX_NO_FRAME"
fontFace="Menlo,Consolas,DejaVuSansMono,Lucida Sans Typewriter,Courier New,Lucida Console"
backgroundColor="#000000"

View File

@ -26,6 +26,7 @@
<color id="grid_cell_border_color_header" value="#80000000"/>
<color id="grid_cell_background_header" value="#C0808080"/>
<color id="grid_cell_background_header_selected" value="#40B0B060"/>
<color id="file_dialog_dir_name_color" value="#FFFF00"/>
<style id="BUTTON"
backgroundImageId="btn_background_dark"
@ -208,6 +209,9 @@
<style id="EDIT_BOX"
backgroundImageId="editbox_background_dark"
/>
<style id="LIST_BOX"
backgroundImageId="editbox_background_dark"
/>
<style id="EDIT_BOX_NO_FRAME"
backgroundColor="#292929"
/>

View File

@ -28,6 +28,7 @@
<color id="grid_cell_border_color_header" value="#C0202020"/>
<color id="grid_cell_background_header" value="#C0909090"/>
<color id="grid_cell_background_header_selected" value="#80FFC040"/>
<color id="file_dialog_dir_name_color" value="#808000"/>
<style id="BUTTON"
backgroundImageId="btn_background"
@ -309,6 +310,13 @@
layoutWidth="FILL_PARENT"
layoutHeight="FILL_PARENT"
/>
<style id="LIST_BOX"
backgroundImageId="editbox_background"
padding="2,2,2,2"
margins="2,2,2,2"
layoutWidth="FILL_PARENT"
layoutHeight="FILL_PARENT"
/>
<style id="EDIT_BOX_NO_FRAME"
fontFace="Menlo,Consolas,DejaVuSansMono,Lucida Sans Typewriter,Courier New,Lucida Console"
backgroundColor="#FFFFFF"