summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 197f2a0)
raw | patch | inline | side by side (parent: 197f2a0)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Mon, 25 Sep 2017 18:21:18 +0000 (21:21 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Mon, 25 Sep 2017 18:21:45 +0000 (21:21 +0300) |
src/gx/gh_flexlay.pas | patch | blob | history | |
src/gx/gh_ui.pas | patch | blob | history |
diff --git a/src/gx/gh_flexlay.pas b/src/gx/gh_flexlay.pas
index 79c6a5c578b8fc3a858d34eb5cc966f8a4a691c7..9692f0d1353f0319fb407204f7feb37dcf8338de 100644 (file)
--- a/src/gx/gh_flexlay.pas
+++ b/src/gx/gh_flexlay.pas
function getExpand (): Boolean; inline;
procedure setExpand (v: Boolean); inline;
+ function alignLeft (): Boolean; inline;
+ function alignTop (): Boolean; inline;
+ function alignRight (): Boolean; inline;
+ function alignBottom (): Boolean; inline;
+ function alignCenter (): Boolean; inline;
+
public
property didWrap: Boolean read getDidWrap write setDidWrap;
property expand: Boolean read getExpand write setExpand;
// this also sets `tempFlex`
procedure calcMaxSizeInternal (cidx: LayControlIdx);
- procedure fixLine (me: PLayControl; i0, i1: LayControlIdx; cury: Integer; var spaceLeft: Single; var flexTotal: Integer; var flexBoxCount: Integer);
+ procedure fixLine (me: PLayControl; i0, i1: LayControlIdx; var cury: Integer; var spaceLeft: Single);
// do box layouting; call `layBox()` recursively if necessary
procedure layBox (boxidx: LayControlIdx);
@@ -247,6 +253,12 @@ procedure TFlexLayouterBase.TLayControl.setDidWrap (v: Boolean); inline; begin i
function TFlexLayouterBase.TLayControl.getExpand (): Boolean; inline; begin result := ((flags and FlagExpand) <> 0); end;
procedure TFlexLayouterBase.TLayControl.setExpand (v: Boolean); inline; begin if (v) then flags := flags or FlagExpand else flags := flags and (not FlagExpand); end;
+function TFlexLayouterBase.TLayControl.alignLeft (): Boolean; inline; begin result := (aligndir < 0); end;
+function TFlexLayouterBase.TLayControl.alignTop (): Boolean; inline; begin result := (aligndir < 0); end;
+function TFlexLayouterBase.TLayControl.alignRight (): Boolean; inline; begin result := (aligndir > 0); end;
+function TFlexLayouterBase.TLayControl.alignBottom (): Boolean; inline; begin result := (aligndir > 0); end;
+function TFlexLayouterBase.TLayControl.alignCenter (): Boolean; inline; begin result := (aligndir = 0); end;
+
// ////////////////////////////////////////////////////////////////////////// //
constructor TFlexLayouterBase.TChildrenEnumerator.Create (constref actls: TLayCtlArray; acur: Integer);
lc, c: PLayControl;
msz: TLaySize;
negw, negh: Boolean;
+ zerow: Boolean;
curwdt, curhgt, totalhgt: Integer;
doWrap: Boolean;
begin
lc := @ctlist[cidx];
msz := lc.ctl.getMaxSize;
- negw := (lc.startsize.w <= 0);
- negh := (lc.startsize.h <= 0);
+ negw := (lc.startsize.w < 0);
+ negh := (lc.startsize.h < 0);
+ zerow := (lc.startsize.w = 0);
lc.tempFlex := lc.ctl.getFlex;
// horizontal boxes
if (negw) then lc.tempFlex := 0; // size is negative: don't expand
curwdt := lc.margins.horiz;
- curhgt := lc.margins.vert;
- totalhgt := 0;
+ curhgt := 0;
+ totalhgt := lc.margins.vert;
for c in forChildren(cidx) do
begin
// new line?
doWrap := (not c.firstInLine) and (c.lineStart);
// need to wrap?
- if (not doWrap) and (lc.canWrap) and (c.canWrap) and (msz.w > 0) and (curwdt+c.startsize.w > lc.startsize.w) then doWrap := true;
+ if (not doWrap) and zerow and (lc.canWrap) and (c.canWrap) and (msz.w > 0) and (curwdt+c.startsize.w > lc.startsize.w) then doWrap := true;
if (doWrap) then
begin
totalhgt += curhgt;
curwdt += c.startsize.w;
if (curhgt < c.startsize.h) then curhgt := c.startsize.h;
end;
+ //writeln('00: ', cidx, ': totalhgt=', totalhgt);
totalhgt += curhgt;
+ //writeln('01: ', cidx, ': totalhgt=', totalhgt);
if (lc.startsize.w < curwdt) then lc.startsize.w := curwdt;
if (lc.startsize.h < totalhgt) then lc.startsize.h := totalhgt;
end
ctlist[f].startsize := ctlist[f].ctl.getDefSize;
mr := ctlist[f].ctl.getMargins;
ctlist[f].margins := mr;
- ctlist[f].startsize.w += mr.horiz;
- ctlist[f].startsize.h += mr.vert;
+ //ctlist[f].startsize.w += mr.horiz;
+ //ctlist[f].startsize.h += mr.vert;
end;
// setup sizes
calcMaxSizeInternal(0); // this also sets `tempFlex`
+ //writeln('=== calculated max size (0) ==='); dump();
// find max size for group, adjust 'startsize' controls to group max size
needRecalcMaxSize := false;
for gtype := 0 to 1 do
for f := 0 to High(ctlist) do ctlist[f].desiredsize := ctlist[f].startsize;
// set flags
firstTime := true;
- //writeln('=== calculated max size ===');
- //dump();
+ //writeln('=== calculated max size (final) ==='); dump();
end;
-procedure TFlexLayouterBase.fixLine (me: PLayControl; i0, i1: LayControlIdx; cury: Integer; var spaceLeft: Single; var flexTotal: Integer; var flexBoxCount: Integer);
+procedure TFlexLayouterBase.fixLine (me: PLayControl; i0, i1: LayControlIdx; var cury: Integer; var spaceLeft: Single);
var
+ flexTotal: Integer = 0; // total sum of flex fields
+ flexBoxCount: Integer = 0; // number of boxes
curx: Integer;
lc: PLayControl;
osz: TLaySize;
begin
curx := me.margins.left;
sti0 := i0;
- // calc minimal line height
+ // calc minimal line height, count flexboxes
lineh := 0;
while (i0 <> i1) do
begin
lc := @ctlist[i0];
lineh := nmax(lineh, lc.startsize.h);
+ if (lc.tempFlex > 0) then begin flexTotal += lc.tempFlex; flexBoxCount += 1; end;
i0 := lc.nextSibling;
end;
// distribute space, expand/align
end;
// expand or align
if (lc.expand) then lc.desiredsize.h := nmin(lc.maxsize.h, lineh) // expand
- else if (lc.aligndir > 0) then lc.desiredpos.y := cury+(lineh-lc.desiredsize.h) // bottom align
- else if (lc.aligndir = 0) then lc.desiredpos.y := cury+(lineh-lc.desiredsize.h) div 2; // center
+ else if (lc.alignBottom) then lc.desiredpos.y := cury+(lineh-lc.desiredsize.h) // bottom align
+ else if (lc.alignCenter) then lc.desiredpos.y := cury+(lineh-lc.desiredsize.h) div 2; // center
if (not osz.equals(lc.desiredsize)) then
begin
if (lc.inGroup) then groupElementChanged := true;
flexTotal := 0;
flexBoxCount := 0;
spaceLeft := me.desiredsize.w-me.margins.horiz;
+ cury += lineh;
end;
flexBoxCount: Integer; // number of boxes
spaceLeft: Single;
cury: Integer;
- maxwdt, maxhgt: Integer;
+ maxwdt: Integer;
lineStartIdx: LayControlIdx;
lc: PLayControl;
doWrap: Boolean;
begin
// horizontal boxes
cury := me.margins.top;
- maxhgt := 0;
- fixLine(me, -1, -1, cury, spaceLeft, flexTotal, flexBoxCount); //HACK!
+ fixLine(me, -1, -1, cury, spaceLeft); //HACK!
lineStartIdx := me.firstChild;
-
for lc in forChildren(boxidx) do
begin
// new line?
if (doWrap) then
begin
// new line, fix this one
- if (not lc.didWrap) then
- begin
- wrappingChanged := true;
- lc.didWrap := true;
- end;
- fixLine(me, lineStartIdx, lc.myidx, cury, spaceLeft, flexTotal, flexBoxCount);
- cury += maxhgt;
+ if (not lc.didWrap) then begin wrappingChanged := true; lc.didWrap := true; end;
+ fixLine(me, lineStartIdx, lc.myidx, cury, spaceLeft);
lineStartIdx := lc.myidx;
end
else
begin
- if (lc.didWrap) then
- begin
- wrappingChanged := true;
- lc.didWrap := false;
- end;
+ if (lc.didWrap) then begin wrappingChanged := true; lc.didWrap := false; end;
end;
spaceLeft -= lc.desiredsize.w;
- if (maxhgt < lc.desiredsize.h) then maxhgt := lc.desiredsize.h;
- if (lc.tempFlex > 0) then
- begin
- flexTotal += lc.tempFlex;
- flexBoxCount += 1;
- end;
+ //if (maxhgt < lc.desiredsize.h) then maxhgt := lc.desiredsize.h;
+ //if (lc.tempFlex > 0) then begin flexTotal += lc.tempFlex; flexBoxCount += 1; end;
end;
// fix last line
- fixLine(me, lineStartIdx, -1, cury, spaceLeft, flexTotal, flexBoxCount);
+ fixLine(me, lineStartIdx, -1, cury, spaceLeft);
end
else
begin
begin
spaceLeft -= lc.desiredsize.h;
if (maxwdt < lc.desiredsize.w) then maxwdt := lc.desiredsize.w;
- if (lc.tempFlex > 0) then
- begin
- flexTotal += lc.tempFlex;
- flexBoxCount += 1;
- end;
+ if (lc.tempFlex > 0) then begin flexTotal += lc.tempFlex; flexBoxCount += 1; end;
end;
// distribute space
end;
// expand or align
if (lc.expand) then lc.desiredsize.w := nmin(lc.maxsize.w, me.desiredsize.w-me.margins.vert) // expand
- else if (lc.aligndir > 0) then lc.desiredpos.x := me.desiredsize.w-me.margins.right-lc.desiredsize.w // right align
- else if (lc.aligndir = 0) then lc.desiredpos.x := (me.desiredsize.w-lc.desiredsize.w) div 2; // center
+ else if (lc.alignRight) then lc.desiredpos.x := me.desiredsize.w-me.margins.right-lc.desiredsize.w // right align
+ else if (lc.alignCenter) then lc.desiredpos.x := (me.desiredsize.w-lc.desiredsize.w) div 2; // center
if (not osz.equals(lc.desiredsize)) then
begin
if (lc.inGroup) then groupElementChanged := true;
diff --git a/src/gx/gh_ui.pas b/src/gx/gh_ui.pas
index a48a0f9df6acfd1fc320d7e8f45560e5d7d20f01..812fae7bda427e97be0ca26ab906b99376b0e464 100644 (file)
--- a/src/gx/gh_ui.pas
+++ b/src/gx/gh_ui.pas
lay.setup(ctl);
//lay.layout();
- writeln('============================');
- lay.dumpFlat();
+ //writeln('============================'); lay.dumpFlat();
- writeln('=== initial ===');
- lay.dump();
+ //writeln('=== initial ==='); lay.dump();
//lay.calcMaxSizeInternal(0);
{
}
lay.layout();
- writeln('=== final ===');
- lay.dump();
+ //writeln('=== final ==='); lay.dump();
finally
FreeAndNil(lay);
mDrawShadow := false;
actionCB := nil;
// layouter interface
- mDefSize := TLaySize.Create(64, 8); // default size
+ //mDefSize := TLaySize.Create(64, 8); // default size
+ mDefSize := TLaySize.Create(0, 0); // default size
mMaxSize := TLaySize.Create(-1, -1); // maximum size
mFlex := 0;
mHoriz := true;
if (strEquCI1251(prname, 'title')) or (strEquCI1251(prname, 'caption')) then
begin
mCaption := par.expectStrOrId(true);
- mDefSize := TLaySize.Create(Length(mCaption)*8+2+8*2, 8*2+2);
+ mDefSize := TLaySize.Create(Length(mCaption)*8+2, 8);
result := true;
exit;
end;