Update to v077r03 release.

byuu says:

Fixed up the geometry calculation code. There is now minimumGeometry()
[returns minimum size needed to display a layout, treats MaximumSize as
MinimumSize], and minimumLayoutGeometry() [like minimumGeometry(), but
it will return MaximumSize if a single container item has that
attribute. Used mostly internally for layout sizing.]

It looks great on Windows, but it looks visually off on Qt. Not exactly
sure what's up there. When I make a test application, everything looks
great. Going to have to clone a bsnes window that's having a problem (eg
bsnes main debugger checkbox window), and see what's up.
This commit is contained in:
Tim Allen 2011-03-23 19:04:37 +11:00
parent 396003e7f6
commit 2bf3dbf375
29 changed files with 162 additions and 96 deletions

View File

@ -1,5 +1,5 @@
void HorizontalLayout::append(VerticalLayout &layout, unsigned spacing) {
children.append({ &layout, 0, 0, 0, spacing });
children.append({ &layout, 0, MinimumSize, MinimumSize, spacing });
}
void HorizontalLayout::append(Widget &widget, unsigned width, unsigned height, unsigned spacing) {
@ -7,26 +7,81 @@ void HorizontalLayout::append(Widget &widget, unsigned width, unsigned height, u
}
Geometry HorizontalLayout::minimumGeometry() {
unsigned width = 0, height = 0;
foreach(child, children) {
width += child.spacing;
if(child.width == MinimumSize || child.width == MaximumSize) {
if(child.layout) width += child.layout->minimumGeometry().width;
if(child.widget) width += child.widget->minimumGeometry().width;
continue;
}
width += child.width;
}
foreach(child, children) {
if(child.height == MinimumSize || child.height == MaximumSize) {
if(child.layout) height = max(height, child.layout->minimumGeometry().height);
if(child.widget) height = max(height, child.widget->minimumGeometry().height);
continue;
}
height = max(height, child.height);
}
return { 0, 0, margin * 2 + width, margin * 2 + height };
}
Geometry HorizontalLayout::minimumLayoutGeometry() {
unsigned width = 0, height = 0;
bool maximumWidth = false;
bool maximumHeight = false;
unsigned width = margin * 2;
unsigned height = margin * 2;
foreach(child, children) {
if(child.width == MaximumSize) maximumWidth = true;
if(child.height == MaximumSize) maximumHeight = true;
if(child.width != MaximumSize) width += child.width;
if(child.height != MaximumSize) height = max(height, child.height);
if(child.width == MaximumSize) {
maximumWidth = true;
break;
}
return { 0, 0, maximumWidth ? MaximumSize : width, maximumHeight ? MaximumSize : height };
if(child.width == MinimumSize) {
if(child.layout) width += child.layout->minimumGeometry().width;
if(child.widget) width += child.widget->minimumGeometry().width;
continue;
}
width += child.width;
}
foreach(child, children) {
if(child.height == MaximumSize) {
maximumHeight = true;
break;
}
if(child.height == MinimumSize) {
if(child.layout) height = max(height, child.layout->minimumGeometry().height);
if(child.widget) height = max(height, child.widget->minimumGeometry().height);
continue;
}
height = max(height, child.height);
}
return { 0, 0, maximumWidth ? MaximumSize : margin * 2 + width, maximumHeight ? MaximumSize : margin * 2 + height };
}
void HorizontalLayout::setGeometry(const Geometry &containerGeometry) {
setMinimumGeometry();
setLayoutGeometry();
auto children = this->children;
foreach(child, children) {
if(child.layout) {
child.width = child.layout->minimumLayoutGeometry().width;
child.height = child.layout->minimumLayoutGeometry().height;
}
if(child.widget) {
if(child.width == MinimumSize) child.width = child.widget->minimumGeometry().width;
if(child.height == MinimumSize) child.height = child.widget->minimumGeometry().height;
}
}
Geometry geometry = containerGeometry;
geometry.x += margin;
@ -34,9 +89,6 @@ void HorizontalLayout::setGeometry(const Geometry &containerGeometry) {
geometry.width -= margin * 2;
geometry.height -= margin * 2;
Geometry layoutGeometry = geometry;
auto children = this->children;
unsigned minimumWidth = 0, maximumWidthCounter = 0;
foreach(child, children) {
if(child.width == MaximumSize) maximumWidthCounter++;
@ -64,30 +116,10 @@ void HorizontalLayout::setGeometry(const Geometry &containerGeometry) {
}
}
void HorizontalLayout::setLayoutGeometry() {
foreach(child, children) {
if(child.layout) {
child.width = child.layout->minimumGeometry().width;
child.height = child.layout->minimumGeometry().height;
}
}
}
void HorizontalLayout::setMargin(unsigned margin) {
this->margin = margin;
}
void HorizontalLayout::setMinimumGeometry() {
foreach(child, children) {
if(child.layout) child.layout->setMinimumGeometry();
if(child.widget) {
Geometry minimumGeometry = child.widget->minimumGeometry();
if(child.width == MinimumSize) child.width = minimumGeometry.width;
if(child.height == MinimumSize) child.height = minimumGeometry.height;
}
}
}
void HorizontalLayout::setParent(Window &parent) {
foreach(child, children) {
if(child.layout) child.layout->setParent(parent);

View File

@ -3,11 +3,10 @@ struct VerticalLayout;
struct HorizontalLayout : public Layout {
void append(VerticalLayout &layout, unsigned spacing = 0);
void append(Widget &widget, unsigned width, unsigned height, unsigned spacing = 0);
Geometry minimumLayoutGeometry();
Geometry minimumGeometry();
void setGeometry(const Geometry &geometry);
void setLayoutGeometry();
void setMargin(unsigned margin);
void setMinimumGeometry();
void setParent(Window &parent);
void setVisible(bool visible);
HorizontalLayout();

View File

@ -1,5 +1,5 @@
void VerticalLayout::append(HorizontalLayout &layout, unsigned spacing) {
children.append({ &layout, 0, 0, 0, spacing });
children.append({ &layout, 0, MinimumSize, MinimumSize, spacing });
}
void VerticalLayout::append(Widget &widget, unsigned width, unsigned height, unsigned spacing) {
@ -7,26 +7,81 @@ void VerticalLayout::append(Widget &widget, unsigned width, unsigned height, uns
}
Geometry VerticalLayout::minimumGeometry() {
unsigned width = 0, height = 0;
foreach(child, children) {
if(child.width == MinimumSize || child.width == MaximumSize) {
if(child.layout) width = max(width, child.layout->minimumGeometry().width);
if(child.widget) width = max(width, child.widget->minimumGeometry().width);
continue;
}
width = max(width, child.width);
}
foreach(child, children) {
height += child.spacing;
if(child.height == MinimumSize || child.height == MaximumSize) {
if(child.layout) height += child.layout->minimumGeometry().height;
if(child.widget) height += child.widget->minimumGeometry().height;
continue;
}
height += child.height;
}
return { 0, 0, margin * 2 + width, margin * 2 + height };
}
Geometry VerticalLayout::minimumLayoutGeometry() {
unsigned width = 0, height = 0;
bool maximumWidth = false;
bool maximumHeight = false;
unsigned width = margin * 2;
unsigned height = margin * 2;
foreach(child, children) {
if(child.width == MaximumSize) maximumWidth = true;
if(child.height == MaximumSize) maximumHeight = true;
if(child.width != MaximumSize) width = max(width, child.width);
if(child.height != MaximumSize) height += child.height;
if(child.width == MaximumSize) {
maximumWidth = true;
break;
}
return { 0, 0, maximumWidth ? MaximumSize : width, maximumHeight ? MaximumSize : height };
if(child.width == MinimumSize) {
if(child.layout) width = max(width, child.layout->minimumGeometry().width);
if(child.widget) width = max(width, child.widget->minimumGeometry().width);
continue;
}
width = max(width, child.width);
}
foreach(child, children) {
if(child.height == MaximumSize) {
maximumHeight = true;
break;
}
if(child.height == MinimumSize) {
if(child.layout) height += child.layout->minimumGeometry().height;
if(child.widget) height += child.widget->minimumGeometry().height;
continue;
}
height += child.height;
}
return { 0, 0, maximumWidth ? MaximumSize : margin * 2 + width, maximumHeight ? MaximumSize : margin * 2 + height };
}
void VerticalLayout::setGeometry(const Geometry &containerGeometry) {
setMinimumGeometry();
setLayoutGeometry();
auto children = this->children;
foreach(child, children) {
if(child.layout) {
child.width = child.layout->minimumLayoutGeometry().width;
child.height = child.layout->minimumLayoutGeometry().height;
}
if(child.widget) {
if(child.width == MinimumSize) child.width = child.widget->minimumGeometry().width;
if(child.height == MinimumSize) child.height = child.widget->minimumGeometry().height;
}
}
Geometry geometry = containerGeometry;
geometry.x += margin;
@ -34,9 +89,6 @@ void VerticalLayout::setGeometry(const Geometry &containerGeometry) {
geometry.width -= margin * 2;
geometry.height -= margin * 2;
Geometry layoutGeometry = geometry;
auto children = this->children;
unsigned minimumHeight = 0, maximumHeightCounter = 0;
foreach(child, children) {
if(child.height == MaximumSize) maximumHeightCounter++;
@ -64,30 +116,10 @@ void VerticalLayout::setGeometry(const Geometry &containerGeometry) {
}
}
void VerticalLayout::setLayoutGeometry() {
foreach(child, children) {
if(child.layout) {
child.width = child.layout->minimumGeometry().width;
child.height = child.layout->minimumGeometry().height;
}
}
}
void VerticalLayout::setMargin(unsigned margin) {
this->margin = margin;
}
void VerticalLayout::setMinimumGeometry() {
foreach(child, children) {
if(child.layout) child.layout->setMinimumGeometry();
if(child.widget) {
Geometry minimumGeometry = child.widget->minimumGeometry();
if(child.width == MinimumSize) child.width = minimumGeometry.width;
if(child.height == MinimumSize) child.height = minimumGeometry.height;
}
}
}
void VerticalLayout::setParent(Window &parent) {
foreach(child, children) {
if(child.layout) child.layout->setParent(parent);

View File

@ -4,10 +4,9 @@ struct VerticalLayout : public Layout {
void append(HorizontalLayout &layout, unsigned spacing = 0);
void append(Widget &widget, unsigned width, unsigned height, unsigned spacing = 0);
Geometry minimumGeometry();
Geometry minimumLayoutGeometry();
void setGeometry(const Geometry &geometry);
void setLayoutGeometry();
void setMargin(unsigned margin);
void setMinimumGeometry();
void setParent(Window &parent);
void setVisible(bool visible);
VerticalLayout();

View File

@ -5,7 +5,7 @@ static void HorizontalSlider_change(HorizontalSlider *self) {
}
Geometry pHorizontalSlider::minimumGeometry() {
return { 0, 0, 100, 20 };
return { 0, 0, 0, 20 };
}
unsigned pHorizontalSlider::position() {

View File

@ -1,5 +1,5 @@
Geometry pProgressBar::minimumGeometry() {
return { 0, 0, 100, 25 };
return { 0, 0, 0, 25 };
}
void pProgressBar::setPosition(unsigned position) {

View File

@ -5,7 +5,7 @@ static void VerticalSlider_change(VerticalSlider *self) {
}
Geometry pVerticalSlider::minimumGeometry() {
return { 0, 0, 20, 100 };
return { 0, 0, 20, 0 };
}
unsigned pVerticalSlider::position() {

View File

@ -12,7 +12,7 @@ Font& pWidget::font() {
}
Geometry pWidget::minimumGeometry() {
return { 0, 0, 100, 25 };
return { 0, 0, 0, 0 };
}
bool pWidget::enabled() {

View File

@ -1,7 +1,7 @@
/****************************************************************************
** Meta object code from reading C++ file 'qt.moc.hpp'
**
** Created: Mon Mar 21 22:59:16 2011
** Created: Wed Mar 23 03:03:27 2011
** by: The Qt Meta Object Compiler version 62 (Qt 4.7.0)
**
** WARNING! All changes made in this file will be lost!

View File

@ -1,5 +1,5 @@
Geometry pHorizontalSlider::minimumGeometry() {
return { 0, 0, 100, 20 };
return { 0, 0, 0, 20 };
}
unsigned pHorizontalSlider::position() {

View File

@ -1,5 +1,5 @@
Geometry pProgressBar::minimumGeometry() {
return { 0, 0, 100, 25 };
return { 0, 0, 0, 25 };
}
void pProgressBar::setPosition(unsigned position) {

View File

@ -1,5 +1,5 @@
Geometry pVerticalSlider::minimumGeometry() {
return { 0, 0, 20, 100 };
return { 0, 0, 20, 0 };
}
unsigned pVerticalSlider::position() {

View File

@ -4,7 +4,7 @@ Font& pWidget::font() {
}
Geometry pWidget::minimumGeometry() {
return { 0, 0, 100, 25 };
return { 0, 0, 0, 0 };
}
void pWidget::setEnabled(bool enabled) {

View File

@ -15,6 +15,10 @@ Geometry pFont::geometry(const string &text) {
return { 0, 0, rc.right, rc.bottom };
}
unsigned pFont::height() {
return geometry(" ").height;
}
void pFont::setBold(bool bold) {
if(hfont) { DeleteObject(hfont); hfont = 0; }
hfont = Font_createFont(font.state.family, font.state.size, font.state.bold, font.state.italic, font.state.underline);

View File

@ -1,7 +1,7 @@
Geometry pButton::minimumGeometry() {
Font &font = this->font();
Geometry geometry = font.geometry(button.state.text);
return { 0, 0, geometry.width + 20, geometry.height + 12 };
return { 0, 0, geometry.width + 20, font.p.height() + 12 };
}
void pButton::setText(const string &text) {

View File

@ -5,7 +5,7 @@ bool pCheckBox::checked() {
Geometry pCheckBox::minimumGeometry() {
Font &font = this->font();
Geometry geometry = font.geometry(checkBox.state.text);
return { 0, 0, geometry.width + 20, geometry.height + 4 };
return { 0, 0, geometry.width + 20, font.p.height() + 4 };
}
void pCheckBox::setChecked(bool checked) {

View File

@ -7,8 +7,7 @@ Geometry pComboBox::minimumGeometry() {
Font &font = this->font();
unsigned maximumWidth = 0;
foreach(text, comboBox.state.text) maximumWidth = max(maximumWidth, font.geometry(text).width);
Geometry geometry = font.geometry(" ");
return { 0, 0, maximumWidth + 24, geometry.height + 10 };
return { 0, 0, maximumWidth + 24, font.p.height() + 10 };
}
void pComboBox::reset() {

View File

@ -1,5 +1,5 @@
Geometry pHorizontalSlider::minimumGeometry() {
return { 0, 0, 100, 25 };
return { 0, 0, 0, 25 };
}
unsigned pHorizontalSlider::position() {

View File

@ -1,7 +1,7 @@
Geometry pLabel::minimumGeometry() {
Font &font = this->font();
Geometry geometry = font.geometry(label.state.text);
return { 0, 0, geometry.width, geometry.height };
return { 0, 0, geometry.width, font.p.height() };
}
void pLabel::setText(const string &text) {

View File

@ -1,7 +1,7 @@
Geometry pLineEdit::minimumGeometry() {
Font &font = this->font();
Geometry geometry = font.geometry(lineEdit.state.text);
return { 0, 0, geometry.width + 12, geometry.height + 8 };
return { 0, 0, geometry.width + 12, font.p.height() + 8 };
}
void pLineEdit::setEditable(bool editable) {

View File

@ -1,5 +1,5 @@
Geometry pProgressBar::minimumGeometry() {
return { 0, 0, 100, 25 };
return { 0, 0, 0, 25 };
}
void pProgressBar::setPosition(unsigned position) {

View File

@ -5,7 +5,7 @@ bool pRadioBox::checked() {
Geometry pRadioBox::minimumGeometry() {
Font &font = this->font();
Geometry geometry = font.geometry(radioBox.state.text);
return { 0, 0, geometry.width + 20, geometry.height + 4 };
return { 0, 0, geometry.width + 20, font.p.height() + 4 };
}
void pRadioBox::setChecked() {

View File

@ -1,5 +1,5 @@
Geometry pVerticalSlider::minimumGeometry() {
return { 0, 0, 25, 100 };
return { 0, 0, 25, 0 };
}
unsigned pVerticalSlider::position() {

View File

@ -8,7 +8,7 @@ Font& pWidget::font() {
}
Geometry pWidget::minimumGeometry() {
return { 0, 0, 100, 25 };
return { 0, 0, 0, 0 };
}
void pWidget::setEnabled(bool enabled) {

View File

@ -38,6 +38,7 @@ struct pFont : public pObject {
HFONT hfont;
Geometry geometry(const string &text);
unsigned height();
void setBold(bool bold);
void setFamily(const string &family);
void setItalic(bool italic);

View File

@ -1,7 +1,7 @@
namespace SNES {
namespace Info {
static const char Name[] = "bsnes";
static const char Version[] = "077.02";
static const char Version[] = "077.03";
static const unsigned SerializerVersion = 19;
}
}

View File

@ -24,7 +24,7 @@ void Console::create() {
controlLayout.append(clearConsole, 120, 0 );
layout.append(controlLayout );
setGeometry({ 0, 0, layout.minimumGeometry().width + 580, 350 });
setGeometry({ 0, 0, layout.minimumGeometry().width + 585, 350 });
append(layout);
onClose = []() {

View File

@ -36,7 +36,7 @@ void Debugger::create() {
layout.append(showBreakpointEditor, ~0, 0);
layout.append(showMemoryEditor, ~0, 0);
setGeometry({ 0, 0, 256, layout.minimumGeometry().height });
setGeometry({ 0, 0, layout.minimumGeometry().width, layout.minimumGeometry().height });
append(layout);
//windows shown by default

View File

@ -29,7 +29,7 @@ void BreakpointEditor::create() {
layout.append(breakpointLayout[n], 5);
}
setGeometry({ 0, 0, 310, layout.minimumGeometry().height });
setGeometry({ 0, 0, layout.minimumGeometry().width, layout.minimumGeometry().height });
append(layout);
onClose = []() {