Skip to content

Commit fca573f

Browse files
committed
Implement margin auto
1 parent e8be369 commit fca573f

File tree

13 files changed

+239
-129
lines changed

13 files changed

+239
-129
lines changed

dw/fltkui.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,10 @@ void FltkComplexButtonResource::widgetCallback (Fl_Widget *widget,
752752
res->click_x = Fl::event_x() - widget->x();
753753
res->click_y = Fl::event_y() - widget->y();
754754
if (res->style) {
755-
res->click_x -= res->style->boxOffsetX();
756-
res->click_y -= res->style->boxOffsetY();
757-
w -= res->style->boxDiffWidth();
758-
h -= res->style->boxDiffHeight();
755+
res->click_x -= res->getEmbed()->marginBoxOffsetX();
756+
res->click_y -= res->getEmbed()->marginBoxOffsetY();
757+
w -= res->getEmbed()->marginBoxDiffWidth();
758+
h -= res->getEmbed()->marginBoxDiffHeight();
759759
}
760760
if (res->click_x >= 0 && res->click_y >= 0 &&
761761
res->click_x < w && res->click_y < h) {
@@ -768,8 +768,8 @@ void FltkComplexButtonResource::widgetCallback (Fl_Widget *widget,
768768
dw::core::EventButton event;
769769

770770
res->click_x = res->click_y = 0;
771-
event.xCanvas = widget->x() + res->style->boxOffsetX();
772-
event.yCanvas = widget->y() + res->style->boxOffsetY();
771+
event.xCanvas = widget->x() + res->getEmbed()->marginBoxOffsetX();
772+
event.yCanvas = widget->y() + res->getEmbed()->marginBoxOffsetY();
773773
// ButtonState doesn't have mouse button values on a release.
774774
event.state = (core::ButtonState) 0;
775775
event.button = 1;

dw/ooffloatsmgr.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ int OOFFloatsMgr::calcFloatX (Float *vloat)
441441
// Left floats are always aligned on the left side of the generator
442442
// (content, not allocation) ...
443443
x = generator->getGeneratorX (oofmIndex)
444-
+ generator->getStyle()->boxOffsetX();
444+
+ generator->marginBoxOffsetX();
445445

446446
// ... but when the float exceeds the line break width of the container,
447447
// it is corrected (but not left of the container). This way, we save
@@ -479,7 +479,7 @@ int OOFFloatsMgr::calcFloatX (Float *vloat)
479479
vloat->generator->getMaxGeneratorWidth ());
480480

481481
x = max (generator->getGeneratorX (oofmIndex) + effGeneratorWidth
482-
- vloat->size.width - generator->getStyle()->boxRestWidth(),
482+
- vloat->size.width - generator->marginBoxRestWidth(),
483483
// Do not exceed container allocation:
484484
0);
485485
break;
@@ -1064,7 +1064,7 @@ void OOFFloatsMgr::getFloatsExtremes (Extremes *cbExtr, Side side,
10641064
// For the maximal width, borders must be considered.
10651065
*maxWidth = max (*maxWidth,
10661066
extr.maxWidth
1067-
+ vloat->generator->getStyle()->boxDiffWidth(),
1067+
+ vloat->generator->marginBoxDiffWidth(),
10681068
+ max (container->getGeneratorWidth ()
10691069
- vloat->generator->getGeneratorWidth (),
10701070
0));
@@ -1147,7 +1147,7 @@ int OOFFloatsMgr::getBorder (Side side, int y, int h, OOFAwareWidget *lastGB,
11471147
switch (side) {
11481148
case LEFT:
11491149
d = vloat->generator->getGeneratorX (oofmIndex)
1150-
+ vloat->generator->getStyle()->boxOffsetX ();
1150+
+ vloat->generator->marginBoxOffsetX ();
11511151
break;
11521152

11531153
case RIGHT:
@@ -1158,7 +1158,7 @@ int OOFFloatsMgr::getBorder (Side side, int y, int h, OOFAwareWidget *lastGB,
11581158
d = container->getMaxGeneratorWidth ()
11591159
- (vloat->generator->getGeneratorX (oofmIndex)
11601160
+ vloat->generator->getMaxGeneratorWidth ())
1161-
+ vloat->generator->getStyle()->boxRestWidth ();
1161+
+ vloat->generator->marginBoxRestWidth ();
11621162
break;
11631163

11641164
default:

dw/oofposrelmgr.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ int OOFPosRelMgr::getChildPosX (Child *child, int refWidth)
177177
child->widget->getStyle()->right,
178178
child->x,
179179
refWidth
180-
- child->widget->getStyle()->boxDiffWidth ());
180+
- child->widget->marginBoxDiffWidth ());
181181

182182
DBG_OBJ_LEAVE_VAL ("%d + %d = %d", gx, dim, gx + dim);
183183
return gx + dim;
@@ -194,7 +194,7 @@ int OOFPosRelMgr::getChildPosY (Child *child, int refHeight)
194194
child->widget->getStyle()->bottom,
195195
child->y,
196196
refHeight
197-
- child->widget->getStyle()->boxDiffHeight ());
197+
- child->widget->marginBoxDiffHeight ());
198198

199199
DBG_OBJ_LEAVE_VAL ("%d + %d = %d", gy, dim, gy + dim);
200200
return gy + dim;

dw/style.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void StyleAttrs::initValues ()
8181
position = POSITION_STATIC;
8282
top = bottom = left = right = LENGTH_AUTO;
8383
textIndent = 0;
84-
margin.setVal (0);
84+
margin.setVal (createAbsLength(0));
8585
borderWidth.setVal (0);
8686
padding.setVal (0);
8787
borderCollapse = BORDER_MODEL_SEPARATE;
@@ -123,7 +123,7 @@ void StyleAttrs::resetValues ()
123123
height = LENGTH_AUTO;
124124
minWidth = maxWidth = minHeight = maxHeight = LENGTH_AUTO;
125125

126-
margin.setVal (0);
126+
margin.setVal (createAbsLength(0));
127127
borderWidth.setVal (0);
128128
padding.setVal (0);
129129
setBorderColor (NULL);
@@ -1167,16 +1167,17 @@ static void drawBorderRight(View *view, Style *style,
11671167
*/
11681168
void drawBorder (View *view, Layout *layout, Rectangle *area,
11691169
int x, int y, int width, int height,
1170+
int marginLeft, int marginRight,
11701171
Style *style, bool inverse)
11711172
{
11721173
/** \todo a lot! */
11731174
int xb1, yb1, xb2, yb2;
11741175

11751176
// top left and bottom right point of outer border boundary
1176-
xb1 = x + style->margin.left;
1177-
yb1 = y + style->margin.top;
1178-
xb2 = x + (width > 0 ? width - 1 : 0) - style->margin.right;
1179-
yb2 = y + (height > 0 ? height - 1 : 0) - style->margin.bottom;
1177+
xb1 = x + marginLeft;
1178+
yb1 = y + style->marginTop();
1179+
xb2 = x + (width > 0 ? width - 1 : 0) - marginRight;
1180+
yb2 = y + (height > 0 ? height - 1 : 0) - style->marginBottom();
11801181

11811182
/*
11821183
// top left and bottom right point of inner border boundary

dw/style.hh

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -589,16 +589,38 @@ public:
589589
borderStyle.top = borderStyle.right = borderStyle.bottom
590590
= borderStyle.left = val; }
591591

592-
inline int boxOffsetX ()
593-
{ return margin.left + borderWidth.left + padding.left; }
594-
inline int boxRestWidth ()
595-
{ return margin.right + borderWidth.right + padding.right; }
596-
inline int boxDiffWidth () { return boxOffsetX () + boxRestWidth (); }
597-
inline int boxOffsetY ()
598-
{ return margin.top + borderWidth.top + padding.top; }
599-
inline int boxRestHeight ()
600-
{ return margin.bottom + borderWidth.bottom + padding.bottom; }
601-
inline int boxDiffHeight () { return boxOffsetY () + boxRestHeight (); }
592+
inline int marginLeft()
593+
{
594+
if (style::isAbsLength (margin.left)) {
595+
return style::absLengthVal (margin.left);
596+
} else {
597+
return 0;
598+
}
599+
}
600+
inline int marginRight()
601+
{
602+
if (style::isAbsLength (margin.right)) {
603+
return style::absLengthVal (margin.right);
604+
} else {
605+
return 0;
606+
}
607+
}
608+
inline int marginTop()
609+
{
610+
if (style::isAbsLength (margin.top)) {
611+
return style::absLengthVal (margin.top);
612+
} else {
613+
return 0;
614+
}
615+
}
616+
inline int marginBottom()
617+
{
618+
if (style::isAbsLength (margin.bottom)) {
619+
return style::absLengthVal (margin.bottom);
620+
} else {
621+
return 0;
622+
}
623+
}
602624

603625
inline bool hasBackground ()
604626
{ return backgroundColor != NULL || backgroundImage != NULL; }
@@ -901,6 +923,7 @@ public:
901923

902924
void drawBorder (View *view, Layout *layout, Rectangle *area,
903925
int x, int y, int width, int height,
926+
int marginLeft, int marginRight,
904927
Style *style, bool inverse);
905928
void drawBackground (View *view, Layout *layout, Rectangle *area,
906929
int x, int y, int width, int height,

dw/textblock.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ void Textblock::sizeRequestImpl (core::Requisition *requisition, int numPos,
359359
// margin of the first line box:
360360
requisition->ascent = calcVerticalBorder (getStyle()->padding.top,
361361
getStyle()->borderWidth.top,
362-
getStyle()->margin.top
362+
getStyle()->marginTop()
363363
+ extraSpace.top,
364364
firstLine->borderAscent,
365365
firstLine->marginAscent);
@@ -373,7 +373,7 @@ void Textblock::sizeRequestImpl (core::Requisition *requisition, int numPos,
373373
// for this case is not necessary.)
374374
calcVerticalBorder (getStyle()->padding.bottom,
375375
getStyle()->borderWidth.bottom,
376-
getStyle()->margin.bottom + extraSpace.bottom,
376+
getStyle()->marginBottom() + extraSpace.bottom,
377377
lastLine->borderDescent, lastLine->marginDescent);
378378
} else {
379379
requisition->width = leftInnerPadding + boxDiffWidth ();
@@ -777,12 +777,12 @@ int Textblock::getAvailWidthOfChild (Widget *child, bool forceValue)
777777
/* Clamp to min-width and max-width if given, taking into
778778
* account leftInnerPadding. */
779779
int maxWidth = child->calcWidth (child->getStyle()->maxWidth,
780-
-1, this, -1, false);
780+
-1, this, -1, false).total;
781781
if (maxWidth != -1 && width > maxWidth - leftInnerPadding)
782782
width = maxWidth - leftInnerPadding;
783783

784784
int minWidth = child->calcWidth (child->getStyle()->minWidth,
785-
-1, this, -1, false);
785+
-1, this, -1, false).total;
786786
if (minWidth != -1 && width < minWidth - leftInnerPadding)
787787
width = minWidth - leftInnerPadding;
788788
}
@@ -1583,7 +1583,7 @@ int Textblock::findLineIndexWhenNotAllocated (int y)
15831583
return
15841584
findLineIndex (y, calcVerticalBorder (getStyle()->padding.top,
15851585
getStyle()->borderWidth.top,
1586-
getStyle()->margin.top
1586+
getStyle()->marginTop()
15871587
+ extraSpace.top,
15881588
lines->getRef(0)->borderAscent,
15891589
lines->getRef(0)->marginAscent));
@@ -2337,14 +2337,14 @@ bool Textblock::calcSizeOfWidgetInFlow (int wordIndex, Widget *widget,
23372337
int rightBorder = boxRestWidth ();
23382338

23392339
int lastMargin, yLine = yOffsetOfLineToBeCreated (&lastMargin);
2340-
int yRel = yLine - min (lastMargin, widget->getStyle()->margin.top);
2340+
int yRel = yLine - min (lastMargin, widget->getStyle()->marginTop());
23412341

23422342
DBG_OBJ_MSGF ("resize", 1,
23432343
"leftBorder = %d + %d + (%d == 0 ? %d : 0) = %d, "
23442344
"rightBorder = %d, yRel = %d - min (%d, %d) = %d",
23452345
boxOffsetX (), leftInnerPadding , lines->size (),
23462346
line1OffsetEff, leftBorder, rightBorder, yLine, lastMargin,
2347-
widget->getStyle()->margin.top, yRel);
2347+
widget->getStyle()->marginTop(), yRel);
23482348

23492349
core::SizeParams childParams;
23502350
DBG_OBJ_ASSOC_CHILD (&childParams);
@@ -3328,14 +3328,14 @@ int Textblock::yOffsetOfLineToBeCreated (int *lastMargin)
33283328
if (lines->size () == 0) {
33293329
result = calcVerticalBorder (getStyle()->padding.top,
33303330
getStyle()->borderWidth.top + extraSpace.top,
3331-
getStyle()->margin.top, 0, 0);
3331+
getStyle()->marginTop(), 0, 0);
33323332
if (lastMargin)
3333-
*lastMargin = getStyle()->margin.top;
3333+
*lastMargin = getStyle()->marginTop();
33343334
} else {
33353335
Line *firstLine = lines->getRef (0), *lastLine = lines->getLastRef ();
33363336
result = calcVerticalBorder (getStyle()->padding.top,
33373337
getStyle()->borderWidth.top,
3338-
getStyle()->margin.top + extraSpace.top,
3338+
getStyle()->marginTop() + extraSpace.top,
33393339
firstLine->borderAscent,
33403340
firstLine->marginAscent)
33413341
- firstLine->borderAscent + lastLine->top + lastLine->totalHeight (0);
@@ -3365,7 +3365,7 @@ int Textblock::yOffsetOfLineCreated (Line *line)
33653365
Line *firstLine = lines->getRef (0);
33663366
result = calcVerticalBorder (getStyle()->padding.top,
33673367
getStyle()->borderWidth.top,
3368-
getStyle()->margin.top + extraSpace.top,
3368+
getStyle()->marginTop() + extraSpace.top,
33693369
firstLine->borderAscent,
33703370
firstLine->marginAscent)
33713371
- firstLine->borderAscent + line->top;

dw/textblock_iterator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void Textblock::TextblockIterator::getAllocation (int start, int end,
229229
Word *w = textblock->words->getRef (i);
230230
int borderAscent =
231231
w->content.type == core::Content::WIDGET_IN_FLOW ?
232-
w->size.ascent - w->content.widget->getStyle()->margin.top :
232+
w->size.ascent - w->content.widget->getStyle()->marginTop() :
233233
w->size.ascent;
234234
lineBorderAscent = misc::max (lineBorderAscent, borderAscent);
235235
}

dw/textblock_linebreaking.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ Textblock::Line *Textblock::addLine (int firstWord, int lastWord,
400400
// just before. The correction in sizeAllocateImpl() is irrelevant
401401
// in this regard. Also, right floats are not regarded here, but in
402402
// OutOfFlowMgr::getSize(),
403-
lineWidth += (line->leftOffset - getStyle()->boxOffsetX ());
403+
lineWidth += (line->leftOffset - marginBoxOffsetX ());
404404

405405
if (lines->size () == 1) {
406406
// first line
@@ -1589,9 +1589,9 @@ void Textblock::accumulateWordForLine (int lineIndex, int wordIndex)
15891589
marginAscent = word->size.ascent;
15901590
marginDescent = word->size.descent;
15911591
borderAscent =
1592-
marginAscent - word->content.widget->getStyle()->margin.top;
1592+
marginAscent - word->content.widget->getStyle()->marginTop();
15931593
borderDescent =
1594-
marginDescent - word->content.widget->getStyle()->margin.bottom;
1594+
marginDescent - word->content.widget->getStyle()->marginBottom();
15951595

15961596
word->content.widget->parentRef = makeParentRefInFlow (lineIndex);
15971597
DBG_OBJ_SET_NUM_O (word->content.widget, "parentRef",

0 commit comments

Comments
 (0)