mirror of https://github.com/adamdruppe/arsd.git
nice minigui bug fixes
This commit is contained in:
parent
d214635885
commit
fbf2ae0f07
91
minigui.d
91
minigui.d
|
@ -1,13 +1,17 @@
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb775498%28v=vs.85%29.aspx
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb775498%28v=vs.85%29.aspx
|
||||||
|
|
||||||
|
// FIXME: unify Windows style line endings
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
|
|
||||||
|
class Form
|
||||||
|
|
||||||
|
disabled widgets and menu items
|
||||||
|
|
||||||
TrackBar controls
|
TrackBar controls
|
||||||
|
|
||||||
event cleanup
|
event cleanup
|
||||||
ScreenPainter dtor stuff. clipping api.
|
|
||||||
Windows radio button sizing and theme text selection
|
|
||||||
tooltips.
|
tooltips.
|
||||||
api improvements
|
api improvements
|
||||||
|
|
||||||
|
@ -639,7 +643,7 @@ class Action {
|
||||||
MENUS
|
MENUS
|
||||||
|
|
||||||
auto bar = new MenuBar(window);
|
auto bar = new MenuBar(window);
|
||||||
window.menu = bar;
|
window.menuBar = bar;
|
||||||
|
|
||||||
auto fileMenu = bar.addItem(new Menu("&File"));
|
auto fileMenu = bar.addItem(new Menu("&File"));
|
||||||
fileMenu.addItem(new MenuItem("&Exit"));
|
fileMenu.addItem(new MenuItem("&Exit"));
|
||||||
|
@ -732,6 +736,7 @@ void recomputeChildLayout(string relevantMeasure)(Widget parent) {
|
||||||
mixin("parent.padding"~secondThingy~"()");
|
mixin("parent.padding"~secondThingy~"()");
|
||||||
|
|
||||||
int stretchinessSum;
|
int stretchinessSum;
|
||||||
|
int stretchyChildSum;
|
||||||
int lastMargin = 0;
|
int lastMargin = 0;
|
||||||
|
|
||||||
// set initial size
|
// set initial size
|
||||||
|
@ -772,17 +777,29 @@ void recomputeChildLayout(string relevantMeasure)(Widget parent) {
|
||||||
auto margin = mixin("child.margin" ~ secondThingy ~ "()");
|
auto margin = mixin("child.margin" ~ secondThingy ~ "()");
|
||||||
lastMargin = margin;
|
lastMargin = margin;
|
||||||
spaceRemaining -= thisMargin + margin;
|
spaceRemaining -= thisMargin + margin;
|
||||||
stretchinessSum += mixin("child." ~ relevantMeasure ~ "Stretchiness()");
|
auto s = mixin("child." ~ relevantMeasure ~ "Stretchiness()");
|
||||||
|
stretchinessSum += s;
|
||||||
|
if(s > 0)
|
||||||
|
stretchyChildSum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// stretch to fill space
|
// stretch to fill space
|
||||||
while(spaceRemaining > 0 && stretchinessSum) {
|
while(spaceRemaining > 0 && stretchinessSum && stretchyChildSum) {
|
||||||
//import std.stdio; writeln("str ", stretchinessSum);
|
//import std.stdio; writeln("str ", stretchinessSum);
|
||||||
auto spacePerChild = spaceRemaining / stretchinessSum;
|
auto spacePerChild = spaceRemaining / stretchinessSum;
|
||||||
if(spacePerChild <= 0)
|
bool spreadEvenly;
|
||||||
break;
|
bool giveToBiggest;
|
||||||
|
if(spacePerChild <= 0) {
|
||||||
|
spacePerChild = spaceRemaining / stretchyChildSum;
|
||||||
|
spreadEvenly = true;
|
||||||
|
}
|
||||||
|
if(spacePerChild <= 0) {
|
||||||
|
giveToBiggest = true;
|
||||||
|
}
|
||||||
int previousSpaceRemaining = spaceRemaining;
|
int previousSpaceRemaining = spaceRemaining;
|
||||||
stretchinessSum = 0;
|
stretchinessSum = 0;
|
||||||
|
Widget mostStretchy;
|
||||||
|
int mostStretchyS;
|
||||||
foreach(child; parent.children) {
|
foreach(child; parent.children) {
|
||||||
if(cast(StaticPosition) child)
|
if(cast(StaticPosition) child)
|
||||||
continue;
|
continue;
|
||||||
|
@ -799,7 +816,10 @@ void recomputeChildLayout(string relevantMeasure)(Widget parent) {
|
||||||
spaceRemaining += adj;
|
spaceRemaining += adj;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto spaceAdjustment = spacePerChild * mixin("child." ~ relevantMeasure ~ "Stretchiness()");
|
auto s = mixin("child." ~ relevantMeasure ~ "Stretchiness()");
|
||||||
|
if(s <= 0)
|
||||||
|
continue;
|
||||||
|
auto spaceAdjustment = spacePerChild * (spreadEvenly ? 1 : s);
|
||||||
mixin("child." ~ relevantMeasure) += spaceAdjustment;
|
mixin("child." ~ relevantMeasure) += spaceAdjustment;
|
||||||
spaceRemaining -= spaceAdjustment;
|
spaceRemaining -= spaceAdjustment;
|
||||||
if(mixin("child." ~ relevantMeasure) > maximum) {
|
if(mixin("child." ~ relevantMeasure) > maximum) {
|
||||||
|
@ -808,6 +828,28 @@ void recomputeChildLayout(string relevantMeasure)(Widget parent) {
|
||||||
spaceRemaining += diff;
|
spaceRemaining += diff;
|
||||||
} else if(mixin("child." ~ relevantMeasure) < maximum) {
|
} else if(mixin("child." ~ relevantMeasure) < maximum) {
|
||||||
stretchinessSum += mixin("child." ~ relevantMeasure ~ "Stretchiness()");
|
stretchinessSum += mixin("child." ~ relevantMeasure ~ "Stretchiness()");
|
||||||
|
if(mostStretchy is null || s >= mostStretchyS) {
|
||||||
|
mostStretchy = child;
|
||||||
|
mostStretchyS = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(giveToBiggest && mostStretchy !is null) {
|
||||||
|
auto child = mostStretchy;
|
||||||
|
int spaceAdjustment = spaceRemaining;
|
||||||
|
|
||||||
|
static if(calcingV)
|
||||||
|
auto maximum = child.maxHeight();
|
||||||
|
else
|
||||||
|
auto maximum = child.maxWidth();
|
||||||
|
|
||||||
|
mixin("child." ~ relevantMeasure) += spaceAdjustment;
|
||||||
|
spaceRemaining -= spaceAdjustment;
|
||||||
|
if(mixin("child." ~ relevantMeasure) > maximum) {
|
||||||
|
auto diff = mixin("child." ~ relevantMeasure) - maximum;
|
||||||
|
mixin("child." ~ relevantMeasure) -= diff;
|
||||||
|
spaceRemaining += diff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3662,14 +3704,20 @@ class MainWindow : Window {
|
||||||
---
|
---
|
||||||
|
|
||||||
+/
|
+/
|
||||||
void setMenuAndToolbarFromAnnotatedCode(T)(ref T t) {
|
void setMenuAndToolbarFromAnnotatedCode(T)(ref T t) if(!is(T == class) && !is(T == interface)) {
|
||||||
|
setMenuAndToolbarFromAnnotatedCode_internal(t);
|
||||||
|
}
|
||||||
|
void setMenuAndToolbarFromAnnotatedCode(T)(T t) if(is(T == class) || is(T == interface)) {
|
||||||
|
setMenuAndToolbarFromAnnotatedCode_internal(t);
|
||||||
|
}
|
||||||
|
void setMenuAndToolbarFromAnnotatedCode_internal(T)(ref T t) {
|
||||||
Action[] toolbarActions;
|
Action[] toolbarActions;
|
||||||
auto menuBar = new MenuBar();
|
auto menuBar = new MenuBar();
|
||||||
Menu[string] mcs;
|
Menu[string] mcs;
|
||||||
|
|
||||||
void delegate() triggering;
|
void delegate() triggering;
|
||||||
|
|
||||||
foreach(memberName; __traits(allMembers, T)) {
|
foreach(memberName; __traits(derivedMembers, T)) {
|
||||||
static if(__traits(compiles, triggering = &__traits(getMember, t, memberName))) {
|
static if(__traits(compiles, triggering = &__traits(getMember, t, memberName))) {
|
||||||
.menu menu;
|
.menu menu;
|
||||||
.toolbar toolbar;
|
.toolbar toolbar;
|
||||||
|
@ -3724,7 +3772,7 @@ class MainWindow : Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.menu = menuBar;
|
this.menuBar = menuBar;
|
||||||
|
|
||||||
if(toolbarActions.length) {
|
if(toolbarActions.length) {
|
||||||
auto tb = new ToolBar(toolbarActions);
|
auto tb = new ToolBar(toolbarActions);
|
||||||
|
@ -3762,16 +3810,16 @@ class MainWindow : Window {
|
||||||
version(win32_widgets)
|
version(win32_widgets)
|
||||||
super.addChild(t, 0);
|
super.addChild(t, 0);
|
||||||
else version(custom_widgets)
|
else version(custom_widgets)
|
||||||
super.addChild(t, menu ? 1 : 0);
|
super.addChild(t, menuBar ? 1 : 0);
|
||||||
else static assert(0);
|
else static assert(0);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuBar _menu;
|
MenuBar _menu;
|
||||||
///
|
///
|
||||||
MenuBar menu() { return _menu; }
|
MenuBar menuBar() { return _menu; }
|
||||||
///
|
///
|
||||||
MenuBar menu(MenuBar m) {
|
MenuBar menuBar(MenuBar m) {
|
||||||
if(_menu !is null) {
|
if(_menu !is null) {
|
||||||
// make sure it is sanely removed
|
// make sure it is sanely removed
|
||||||
// FIXME
|
// FIXME
|
||||||
|
@ -3818,9 +3866,6 @@ class ClientAreaWidget : Widget {
|
||||||
this(Widget parent = null) {
|
this(Widget parent = null) {
|
||||||
super(parent);
|
super(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
override int paddingLeft() { return 2; }
|
|
||||||
override int paddingRight() { return 2; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3961,9 +4006,11 @@ class ToolButton : Button {
|
||||||
case GenericIcons.Open:
|
case GenericIcons.Open:
|
||||||
painter.fillColor = Color.white;
|
painter.fillColor = Color.white;
|
||||||
painter.drawPolygon(
|
painter.drawPolygon(
|
||||||
Point(2, 4) * multiplier / divisor, Point(2, 12) * multiplier / divisor, Point(13, 12) * multiplier / divisor, Point(13, 3) * multiplier / divisor,
|
Point(3, 4) * multiplier / divisor, Point(3, 12) * multiplier / divisor, Point(14, 12) * multiplier / divisor, Point(14, 3) * multiplier / divisor,
|
||||||
Point(9, 3) * multiplier / divisor, Point(9, 4) * multiplier / divisor, Point(2, 4) * multiplier / divisor);
|
Point(10, 3) * multiplier / divisor, Point(10, 4) * multiplier / divisor, Point(3, 4) * multiplier / divisor);
|
||||||
painter.drawLine(Point(2, 6) * multiplier / divisor, Point(13, 7) * multiplier / divisor);
|
painter.drawPolygon(
|
||||||
|
Point(1, 6) * multiplier / divisor, Point(12, 6) * multiplier / divisor,
|
||||||
|
Point(14, 12) * multiplier / divisor, Point(3, 12) * multiplier / divisor);
|
||||||
//painter.drawLine(Point(9, 6) * multiplier / divisor, Point(13, 7) * multiplier / divisor);
|
//painter.drawLine(Point(9, 6) * multiplier / divisor, Point(13, 7) * multiplier / divisor);
|
||||||
break;
|
break;
|
||||||
case GenericIcons.Copy:
|
case GenericIcons.Copy:
|
||||||
|
@ -4145,7 +4192,8 @@ class StatusBar : Widget {
|
||||||
@property void content(string s) {
|
@property void content(string s) {
|
||||||
version(win32_widgets) {
|
version(win32_widgets) {
|
||||||
_content = s;
|
_content = s;
|
||||||
SendMessageA(owner.hwnd, SB_SETTEXT, idx, cast(LPARAM) toStringzInternal(s));
|
WCharzBuffer bfr = WCharzBuffer(s);
|
||||||
|
SendMessageW(owner.hwnd, SB_SETTEXT, idx, cast(LPARAM) bfr.ptr);
|
||||||
} else version(custom_widgets) {
|
} else version(custom_widgets) {
|
||||||
if(_content != s) {
|
if(_content != s) {
|
||||||
_content = s;
|
_content = s;
|
||||||
|
@ -5915,7 +5963,6 @@ enum {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum WM_USER = 1024;
|
enum WM_USER = 1024;
|
||||||
enum SB_SETTEXT = WM_USER + 1; // SET TEXT A. It is +11 for W
|
|
||||||
}
|
}
|
||||||
|
|
||||||
version(win32_widgets)
|
version(win32_widgets)
|
||||||
|
|
Loading…
Reference in New Issue