mirror of https://github.com/adamdruppe/arsd.git
make it scale better on windows toolbars #385
This commit is contained in:
parent
26526a1acc
commit
7958a5eb93
82
minigui.d
82
minigui.d
|
@ -7760,10 +7760,20 @@ class ScrollMessageWidget : Widget {
|
||||||
void scrollIntoView(Rectangle rect) {
|
void scrollIntoView(Rectangle rect) {
|
||||||
Rectangle viewRectangle = Rectangle(position, Size(hsb.viewableArea_, vsb.viewableArea_));
|
Rectangle viewRectangle = Rectangle(position, Size(hsb.viewableArea_, vsb.viewableArea_));
|
||||||
|
|
||||||
// writeln(viewRectangle, " ", rect, " ", viewRectangle.contains(rect.lowerRight));
|
// import std.stdio;writeln(viewRectangle, "\n", rect, " ", viewRectangle.contains(rect.lowerRight - Point(1, 1)));
|
||||||
|
|
||||||
if(!viewRectangle.contains(rect.lowerRight))
|
// the lower right is exclusive normally
|
||||||
setPosition(rect.upperLeft.tupleof);
|
auto test = rect.lowerRight;
|
||||||
|
if(test.x > 0) test.x--;
|
||||||
|
if(test.y > 0) test.y--;
|
||||||
|
|
||||||
|
if(!viewRectangle.contains(test) || !viewRectangle.contains(rect.upperLeft)) {
|
||||||
|
// try to scroll only one dimension at a time if we can
|
||||||
|
if(!viewRectangle.contains(Point(test.x, position.y)) || !viewRectangle.contains(Point(rect.upperLeft.x, position.y)))
|
||||||
|
setPosition(rect.upperLeft.x, position.y);
|
||||||
|
if(!viewRectangle.contains(Point(position.x, test.y)) || !viewRectangle.contains(Point(position.x, rect.upperLeft.y)))
|
||||||
|
setPosition(position.x, rect.upperLeft.y);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9915,7 +9925,7 @@ private class ClientAreaWidget : Widget {
|
||||||
*/
|
*/
|
||||||
class ToolBar : Widget {
|
class ToolBar : Widget {
|
||||||
version(win32_widgets) {
|
version(win32_widgets) {
|
||||||
private const int idealHeight;
|
private int idealHeight;
|
||||||
override int minHeight() { return idealHeight; }
|
override int minHeight() { return idealHeight; }
|
||||||
override int maxHeight() { return idealHeight; }
|
override int maxHeight() { return idealHeight; }
|
||||||
} else version(custom_widgets) {
|
} else version(custom_widgets) {
|
||||||
|
@ -9924,13 +9934,37 @@ class ToolBar : Widget {
|
||||||
} else static assert(false);
|
} else static assert(false);
|
||||||
override int heightStretchiness() { return 0; }
|
override int heightStretchiness() { return 0; }
|
||||||
|
|
||||||
version(win32_widgets)
|
version(win32_widgets) {
|
||||||
HIMAGELIST imageList;
|
HIMAGELIST imageListSmall;
|
||||||
|
HIMAGELIST imageListLarge;
|
||||||
|
}
|
||||||
|
|
||||||
this(Widget parent) {
|
this(Widget parent) {
|
||||||
this(null, parent);
|
this(null, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version(win32_widgets)
|
||||||
|
void changeIconSize(bool useLarge) {
|
||||||
|
SendMessageW(hwnd, TB_SETIMAGELIST, cast(WPARAM) 0, cast(LPARAM) (useLarge ? imageListLarge : imageListSmall));
|
||||||
|
|
||||||
|
/+
|
||||||
|
SIZE size;
|
||||||
|
import core.sys.windows.commctrl;
|
||||||
|
SendMessageW(hwnd, TB_GETMAXSIZE, 0, cast(LPARAM) &size);
|
||||||
|
idealHeight = size.cy + 4; // the plus 4 is a hack
|
||||||
|
+/
|
||||||
|
|
||||||
|
idealHeight = useLarge ? 34 : 26;
|
||||||
|
|
||||||
|
if(parent) {
|
||||||
|
parent.recomputeChildLayout();
|
||||||
|
parent.redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
SendMessageW(hwnd, TB_SETBUTTONSIZE, 0, (idealHeight-4) << 16 | (idealHeight-4));
|
||||||
|
SendMessageW(hwnd, TB_AUTOSIZE, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
this(Action[] actions, Widget parent) {
|
this(Action[] actions, Widget parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
|
@ -9945,16 +9979,25 @@ class ToolBar : Widget {
|
||||||
|
|
||||||
SendMessageW(hwnd, TB_SETEXTENDEDSTYLE, 0, 8/*TBSTYLE_EX_MIXEDBUTTONS*/);
|
SendMessageW(hwnd, TB_SETEXTENDEDSTYLE, 0, 8/*TBSTYLE_EX_MIXEDBUTTONS*/);
|
||||||
|
|
||||||
imageList = ImageList_Create(
|
imageListSmall = ImageList_Create(
|
||||||
// width, height
|
// width, height
|
||||||
16, 16,
|
16, 16,
|
||||||
ILC_COLOR16 | ILC_MASK,
|
ILC_COLOR16 | ILC_MASK,
|
||||||
16 /*numberOfButtons*/, 0);
|
16 /*numberOfButtons*/, 0);
|
||||||
|
|
||||||
SendMessageW(hwnd, TB_SETIMAGELIST, cast(WPARAM) 0, cast(LPARAM) imageList);
|
imageListLarge = ImageList_Create(
|
||||||
|
// width, height
|
||||||
|
24, 24,
|
||||||
|
ILC_COLOR16 | ILC_MASK,
|
||||||
|
16 /*numberOfButtons*/, 0);
|
||||||
|
|
||||||
|
SendMessageW(hwnd, TB_SETIMAGELIST, cast(WPARAM) 0, cast(LPARAM) imageListSmall);
|
||||||
SendMessageW(hwnd, TB_LOADIMAGES, cast(WPARAM) IDB_STD_SMALL_COLOR, cast(LPARAM) HINST_COMMCTRL);
|
SendMessageW(hwnd, TB_LOADIMAGES, cast(WPARAM) IDB_STD_SMALL_COLOR, cast(LPARAM) HINST_COMMCTRL);
|
||||||
|
|
||||||
|
SendMessageW(hwnd, TB_SETIMAGELIST, cast(WPARAM) 0, cast(LPARAM) imageListLarge);
|
||||||
|
SendMessageW(hwnd, TB_LOADIMAGES, cast(WPARAM) IDB_STD_LARGE_COLOR, cast(LPARAM) HINST_COMMCTRL);
|
||||||
|
|
||||||
SendMessageW(hwnd, TB_SETMAXTEXTROWS, 0, 0);
|
SendMessageW(hwnd, TB_SETMAXTEXTROWS, 0, 0);
|
||||||
SendMessageW(hwnd, TB_AUTOSIZE, 0, 0);
|
|
||||||
|
|
||||||
TBBUTTON[] buttons;
|
TBBUTTON[] buttons;
|
||||||
|
|
||||||
|
@ -9973,17 +10016,14 @@ class ToolBar : Widget {
|
||||||
SendMessageW(hwnd, TB_BUTTONSTRUCTSIZE, cast(WPARAM)TBBUTTON.sizeof, 0);
|
SendMessageW(hwnd, TB_BUTTONSTRUCTSIZE, cast(WPARAM)TBBUTTON.sizeof, 0);
|
||||||
SendMessageW(hwnd, TB_ADDBUTTONSW, cast(WPARAM) buttons.length, cast(LPARAM)buttons.ptr);
|
SendMessageW(hwnd, TB_ADDBUTTONSW, cast(WPARAM) buttons.length, cast(LPARAM)buttons.ptr);
|
||||||
|
|
||||||
SIZE size;
|
|
||||||
import core.sys.windows.commctrl;
|
|
||||||
SendMessageW(hwnd, TB_GETMAXSIZE, 0, cast(LPARAM) &size);
|
|
||||||
idealHeight = size.cy + 4; // the plus 4 is a hack
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
RECT rect;
|
RECT rect;
|
||||||
GetWindowRect(hwnd, &rect);
|
GetWindowRect(hwnd, &rect);
|
||||||
idealHeight = rect.bottom - rect.top + 10; // the +10 is a hack since the size right now doesn't look right on a real Windows XP box
|
idealHeight = rect.bottom - rect.top + 10; // the +10 is a hack since the size right now doesn't look right on a real Windows XP box
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
dpiChanged(); // to load the things calling changeIconSize the first time
|
||||||
|
|
||||||
assert(idealHeight);
|
assert(idealHeight);
|
||||||
} else version(custom_widgets) {
|
} else version(custom_widgets) {
|
||||||
foreach(action; actions)
|
foreach(action; actions)
|
||||||
|
@ -9994,6 +10034,16 @@ class ToolBar : Widget {
|
||||||
override void recomputeChildLayout() {
|
override void recomputeChildLayout() {
|
||||||
.recomputeChildLayout!"width"(this);
|
.recomputeChildLayout!"width"(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
version(win32_widgets)
|
||||||
|
override protected void dpiChanged() {
|
||||||
|
auto sz = scaleWithDpi(16);
|
||||||
|
if(sz >= 20)
|
||||||
|
changeIconSize(true);
|
||||||
|
else
|
||||||
|
changeIconSize(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum toolbarIconSize = 24;
|
enum toolbarIconSize = 24;
|
||||||
|
@ -12406,7 +12456,9 @@ abstract class EditableTextWidget : EditableTextWidgetParent {
|
||||||
textLayout.selection.replaceContent(s);
|
textLayout.selection.replaceContent(s);
|
||||||
|
|
||||||
tdh.adjustScrollbarSizes();
|
tdh.adjustScrollbarSizes();
|
||||||
//scrollForCaret();
|
// these don't seem to help
|
||||||
|
// tdh.smw.setPosition(0, 0);
|
||||||
|
// tdh.scrollForCaret();
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue