wxSizer patches by Alexander Smishlajev <als@turnhere.com>
Adds some wxALIGN_* flags to increase ability to position item within its allotted space. Adds wxSHAPED flag that enforces proportional resizing on growable items. Adds a sample and updated documentation. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4461 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -69,7 +69,7 @@ def makeSimpleBox6(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 1, wxALIGN_TOP)
|
||||
box.Add(wxButton(win, 1010, "two"), 1, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "three"), 1, wxCENTER)
|
||||
box.Add(wxButton(win, 1010, "three"), 1, wxALIGN_CENTER)
|
||||
box.Add(wxButton(win, 1010, "four"), 1, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "five"), 1, wxALIGN_BOTTOM)
|
||||
|
||||
@@ -93,7 +93,7 @@ def makeSimpleBox8(win):
|
||||
box = wxBoxSizer(wxVERTICAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
|
||||
box.Add(0,0, 1)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxCENTER)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxALIGN_CENTER)
|
||||
box.Add(0,0, 1)
|
||||
box.Add(wxButton(win, 1010, "three"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "four"), 0, wxEXPAND)
|
||||
@@ -243,7 +243,7 @@ def makeGrid2(win):
|
||||
(wxButton(win, 1010, 'two'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'three'), 0, wxALIGN_LEFT | wxALIGN_BOTTOM),
|
||||
(wxButton(win, 1010, 'four'), 0, wxEXPAND),
|
||||
(wxButton(win, 1010, 'five'), 0, wxCENTER),
|
||||
(wxButton(win, 1010, 'five'), 0, wxALIGN_CENTER),
|
||||
(wxButton(win, 1010, 'six'), 0, wxEXPAND),
|
||||
(box, 0, wxEXPAND | wxALL, 10),
|
||||
(wxButton(win, 1010, 'eight'), 0, wxEXPAND),
|
||||
@@ -276,6 +276,76 @@ def makeGrid3(win):
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeGrid4(win):
|
||||
bpos = wxDefaultPosition
|
||||
bsize = wxSize(100, 50)
|
||||
gs = wxGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
|
||||
|
||||
gs.AddMany([ (wxButton(win, 1010, 'one', bpos, bsize),
|
||||
0, wxALIGN_TOP | wxALIGN_LEFT ),
|
||||
(wxButton(win, 1010, 'two', bpos, bsize),
|
||||
0, wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL ),
|
||||
(wxButton(win, 1010, 'three', bpos, bsize),
|
||||
0, wxALIGN_TOP | wxALIGN_RIGHT ),
|
||||
(wxButton(win, 1010, 'four', bpos, bsize),
|
||||
0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT ),
|
||||
(wxButton(win, 1010, 'five', bpos, bsize),
|
||||
0, wxALIGN_CENTER ),
|
||||
(wxButton(win, 1010, 'six', bpos, bsize),
|
||||
0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT ),
|
||||
(wxButton(win, 1010, 'seven', bpos, bsize),
|
||||
0, wxALIGN_BOTTOM | wxALIGN_LEFT ),
|
||||
(wxButton(win, 1010, 'eight', bpos, bsize),
|
||||
0, wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL ),
|
||||
(wxButton(win, 1010, 'nine', bpos, bsize),
|
||||
0, wxALIGN_BOTTOM | wxALIGN_RIGHT ),
|
||||
])
|
||||
|
||||
return gs
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeShapes(win):
|
||||
bpos = wxDefaultPosition
|
||||
bsize = wxSize(100, 50)
|
||||
gs = wxGridSizer(3, 3, 2, 2) # rows, cols, hgap, vgap
|
||||
|
||||
gs.AddMany([ (wxButton(win, 1010, 'one', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_TOP | wxALIGN_LEFT ),
|
||||
(wxButton(win, 1010, 'two', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_TOP | wxALIGN_CENTER_HORIZONTAL ),
|
||||
(wxButton(win, 1010, 'three', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_TOP | wxALIGN_RIGHT ),
|
||||
(wxButton(win, 1010, 'four', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT ),
|
||||
(wxButton(win, 1010, 'five', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_CENTER ),
|
||||
(wxButton(win, 1010, 'six', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT ),
|
||||
(wxButton(win, 1010, 'seven', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_BOTTOM | wxALIGN_LEFT ),
|
||||
(wxButton(win, 1010, 'eight', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_BOTTOM | wxALIGN_CENTER_HORIZONTAL ),
|
||||
(wxButton(win, 1010, 'nine', bpos, bsize),
|
||||
0, wxSHAPED | wxALIGN_BOTTOM | wxALIGN_RIGHT ),
|
||||
])
|
||||
|
||||
return gs
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
def makeSimpleBoxShaped(win):
|
||||
box = wxBoxSizer(wxHORIZONTAL)
|
||||
box.Add(wxButton(win, 1010, "one"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "two"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "three"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "four"), 0, wxEXPAND)
|
||||
box.Add(wxButton(win, 1010, "five"), 1, wxSHAPED)
|
||||
|
||||
return box
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
theTests = [
|
||||
("Simple horizontal boxes", makeSimpleBox1,
|
||||
"This is a HORIZONTAL box sizer with four non-stretchable buttons held "
|
||||
@@ -328,7 +398,7 @@ theTests = [
|
||||
("", None, ""),
|
||||
|
||||
("Simple border sizer", makeSimpleBorder1,
|
||||
"The wxBorderSizer leaves empty space around its contents. This one "
|
||||
"The wxBoxSizer can leave empty space around its contents. This one "
|
||||
"gives a border all the way around."
|
||||
),
|
||||
|
||||
@@ -380,6 +450,22 @@ theTests = [
|
||||
"\nThere is also a spacer in the middle cell instead of an actual window."
|
||||
),
|
||||
|
||||
("Grid with Alignment", makeGrid4,
|
||||
"New alignment flags allow for the positioning of items in any corner or centered "
|
||||
"position."
|
||||
),
|
||||
|
||||
("", None, ""),
|
||||
|
||||
("Proportional resize", makeSimpleBoxShaped,
|
||||
"Managed items can preserve their original aspect ratio. The last item has the "
|
||||
"wxSHAPED flag set and will resize proportional to its origingal size."
|
||||
),
|
||||
|
||||
("Proportional resize with Alignments", makeShapes,
|
||||
"This one shows various alignments as well as proportional resizing for all items."
|
||||
),
|
||||
|
||||
]
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
@@ -132,22 +132,18 @@ class wxGridSizer(wxPySizer):
|
||||
isz = item.CalcMin()
|
||||
flag = item.GetFlag()
|
||||
|
||||
if flag & wxEXPAND:
|
||||
if flag & wxEXPAND or flag & wxSHAPED:
|
||||
isz = wxSize(w, h)
|
||||
else:
|
||||
if flag & wxALIGN_CENTER_HORIZONTAL:
|
||||
ipt.x = x + (w - isz.width) / 2
|
||||
elif flag & wxALIGN_RIGHT:
|
||||
ipt.x = x + (w - isz.width)
|
||||
|
||||
elif flag & wxCENTER:
|
||||
ipt.x = x + (w - isz.width) / 2
|
||||
ipt.y = y + (h - isz.height) / 2
|
||||
|
||||
if flag & wxALIGN_LEFT:
|
||||
ipt.x = x
|
||||
elif flag & wxALIGN_RIGHT:
|
||||
ipt.x = x + (w - isz.width)
|
||||
|
||||
if flag & wxALIGN_TOP:
|
||||
ipt.y = y
|
||||
elif flag & wxALIGN_BOTTOM:
|
||||
ipt.y = y + (h - isz.height)
|
||||
if flag & wxALIGN_CENTER_VERTICAL:
|
||||
ipt.y = y + (h - isz.height) / 2
|
||||
elif flag & wxALIGN_BOTTOM:
|
||||
ipt.y = y + (h - isz.height)
|
||||
|
||||
item.SetDimension(ipt, isz)
|
||||
|
||||
|
@@ -232,11 +232,16 @@ enum {
|
||||
wxCOLOURED,
|
||||
wxFIXED_LENGTH,
|
||||
wxALIGN_LEFT,
|
||||
wxALIGN_CENTER,
|
||||
wxALIGN_CENTRE,
|
||||
wxALIGN_CENTER_HORIZONTAL,
|
||||
wxALIGN_CENTRE_HORIZONTAL,
|
||||
wxALIGN_RIGHT,
|
||||
wxALIGN_BOTTOM,
|
||||
wxALIGN_CENTER_VERTICAL,
|
||||
wxALIGN_CENTRE_VERTICAL,
|
||||
wxALIGN_TOP,
|
||||
wxALIGN_CENTER,
|
||||
wxALIGN_CENTRE,
|
||||
wxSHAPED,
|
||||
wxLB_NEEDED_SB,
|
||||
wxLB_ALWAYS_SB,
|
||||
wxLB_SORT,
|
||||
|
Reference in New Issue
Block a user