How to vertically align bitmaps with text baseline?

I still haven't figured out a solution to this problem. Here's

> a demo that demonstrates the problem:

It's surely not a Sizer issue. Try with 'gyj_gyj' instead of
'FooBar' ;:slight_smile:

Jean-Michel Fauth, Switzerland

> I still haven't figured out a solution to this problem. Here's
> a demo that demonstrates the problem:

It's surely not a Sizer issue.

IMO it is. Using the baselines of text objects as alignment
references is one of the most fundamental concepts in layout.
It seems to be missing.

Try with 'gyj_gyj' instead of 'FooBar' ;:slight_smile:

Just did. The text is in the same place it was before. Does
it change for you? The baseline of the text still isn't aligned
with the bottom of the adjacent objects.

路路路

On 2005-09-08, jmf <jfauth@bluewin.ch> wrote:

--
Grant Edwards grante Yow! Are we live or
                                  at on tape?
                               visi.com

I hate to say it, but you're kinda SOL...

Sizers aren't designed for type setting, however, this workaround comes close, but depending on font, it's not a sure fire resolution.

Adding the wx.BOTTOM flag and a padding parameter you can fudge it.

路路路

---

import wx

class ColWin(wx.Window):
     def __init__(self, parent, id, BackColour, pos=(-1,-1), size=(-1,-1)):
         wx.Window.__init__(self, parent, id, pos, size, wx.SIMPLE_BORDER)
         self.SetBackgroundColour(BackColour)

class MyFrame(wx.Frame):
     def __init__(self, parent, title):
         wx.Frame.__init__(self, parent, -1, title)
         panel = wx.Panel(self)
         vsizer = wx.BoxSizer(wx.VERTICAL)
         hsizer = wx.BoxSizer(wx.HORIZONTAL)
         green = ColWin(panel,-1,wx.GREEN,size=(100,130))
         t = wx.StaticText(panel,-1,'FooBar')
         #t.SetFont(wx.Font(24,wx.DEFAULT,wx.NORMAL,wx.BOLD))
         blue = ColWin(panel,-1,wx.BLUE,size=(40,40))
         hsizer.AddMany([
             (green,0, wx.ALIGN_BOTTOM|wx.BOTTOM, 4),
             ((20,-1),1),
             (t, 0, wx.ALIGN_BOTTOM),
             ((20,-1),1),
             (blue, 0, wx.ALIGN_BOTTOM|wx.BOTTOM, 4),
             ])
         vsizer.Add(hsizer,1,flag=wx.ALL+wx.EXPAND,border=10)
         panel.SetSizerAndFit(vsizer)
         panel.Layout()
         vsizer.Fit(self)

class MyApp(wx.App):
     def OnInit(self):
         frame = MyFrame(None, "Still Baffled by Sizers")
         frame.Show(True)
         self.SetTopWindow(frame)
         return True

app = MyApp(False)
app.MainLoop()

Grant Edwards wrote:

On 2005-09-08, jmf <jfauth@bluewin.ch> wrote:

I still haven't figured out a solution to this problem. Here's
a demo that demonstrates the problem:

It's surely not a Sizer issue.

IMO it is. Using the baselines of text objects as alignment
references is one of the most fundamental concepts in layout.
It seems to be missing.

Try with 'gyj_gyj' instead of 'FooBar' ;:slight_smile:

Just did. The text is in the same place it was before. Does
it change for you? The baseline of the text still isn't aligned
with the bottom of the adjacent objects.

I haven't really been following this thread closely, so forgive me if this
has already been suggested.

For the situation you're talking about, consider the following: Forget
sizers. Forget layout constraints. Use good old brute-force positioning of
elements with the "pos=" parameter. Then it's just a matter of determining
the size of your graphic and doing some easy calculation to determine the
appropriate position of the other elements.

Then you need to decide if you want to write an EVT_SIZE handler, or if you
just want to leave your screen layout static and ignore resize events.

It's not necessarily pretty, but it'll work.

David

路路路

-----Original Message-----
From: Joe Brown [mailto:joebrown@rclooke.com]
Sent: Thursday, September 08, 2005 9:13 AM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Re: How to vertically align
bitmaps with text baseline?

I hate to say it, but you're kinda SOL...

Sizers aren't designed for type setting, however, this
workaround comes
close, but depending on font, it's not a sure fire resolution.

Adding the wx.BOTTOM flag and a padding parameter you can fudge it.
---

import wx

class ColWin(wx.Window):
     def __init__(self, parent, id, BackColour, pos=(-1,-1),
size=(-1,-1)):
         wx.Window.__init__(self, parent, id, pos, size,
wx.SIMPLE_BORDER)
         self.SetBackgroundColour(BackColour)

class MyFrame(wx.Frame):
     def __init__(self, parent, title):
         wx.Frame.__init__(self, parent, -1, title)
         panel = wx.Panel(self)
         vsizer = wx.BoxSizer(wx.VERTICAL)
         hsizer = wx.BoxSizer(wx.HORIZONTAL)
         green = ColWin(panel,-1,wx.GREEN,size=(100,130))
         t = wx.StaticText(panel,-1,'FooBar')
         #t.SetFont(wx.Font(24,wx.DEFAULT,wx.NORMAL,wx.BOLD))
         blue = ColWin(panel,-1,wx.BLUE,size=(40,40))
         hsizer.AddMany([
             (green,0, wx.ALIGN_BOTTOM|wx.BOTTOM, 4),
             ((20,-1),1),
             (t, 0, wx.ALIGN_BOTTOM),
             ((20,-1),1),
             (blue, 0, wx.ALIGN_BOTTOM|wx.BOTTOM, 4),
             ])
         vsizer.Add(hsizer,1,flag=wx.ALL+wx.EXPAND,border=10)
         panel.SetSizerAndFit(vsizer)
         panel.Layout()
         vsizer.Fit(self)

class MyApp(wx.App):
     def OnInit(self):
         frame = MyFrame(None, "Still Baffled by Sizers")
         frame.Show(True)
         self.SetTopWindow(frame)
         return True

app = MyApp(False)
app.MainLoop()

Grant Edwards wrote:
> On 2005-09-08, jmf <jfauth@bluewin.ch> wrote:
>
>
>>>I still haven't figured out a solution to this problem. Here's a
>>>demo that demonstrates the problem:
>>
>>It's surely not a Sizer issue.
>
>
> IMO it is. Using the baselines of text objects as alignment
> references is one of the most fundamental concepts in
layout. It seems
> to be missing.
>
>
>>Try with 'gyj_gyj' instead of 'FooBar' ;:slight_smile:
>
>
> Just did. The text is in the same place it was before. Does it
> change for you? The baseline of the text still isn't
aligned with the
> bottom of the adjacent objects.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org

I hate to say it, but you're kinda SOL...

That's sort of what I've figured out. :slight_smile:

It's not a big deal, but it's one of the things that shows a
certain lack of polish in a UI.

Sizers aren't designed for type setting, however, this
workaround comes close, but depending on font, it's not a sure
fire resolution.

Adding the wx.BOTTOM flag and a padding parameter you can
fudge it. ---

Nice work-around (why do I never remember to use AddMany??). If
there was a way to get the baseline offset of a font, it could
even be made more-or-less portable. But I don't think there is.

路路路

On 2005-09-08, Joe Brown <joebrown@rclooke.com> wrote:

         hsizer.AddMany([
             (green,0, wx.ALIGN_BOTTOM|wx.BOTTOM, 4),
             ((20,-1),1),
             (t, 0, wx.ALIGN_BOTTOM),
             ((20,-1),1),
             (blue, 0, wx.ALIGN_BOTTOM|wx.BOTTOM, 4),
             ])

--
Grant Edwards grante Yow! My NOSE is NUMB!
                                  at
                               visi.com