Opened 7 months ago

Closed 7 months ago

#18643 closed defect (fixed)

[GTK3] Changing StaticText content while hidden resizes it to 1x0 px

Reported by: pieleric Owned by:
Priority: normal Milestone:
Component: wxGTK Version: 3.0.3
Keywords: GTK3 StaticText Cc:
Blocked By: Blocking:
Patch: no

Description

If the content is changed while the StaticText is hidden, then it's automatically resized to 1x0px. Therefore showing the StaticText afterwards will not show anything.

Here is a wxPython code demonstrating it (you can copy-paste it in wxDemo/StaticText for easy testing):

class TestPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)

        StaticText(self, -1, "This is an example of static text", (20, 10))
        self.t = StaticText(self, -1, "using the wx.StaticText Control.", (20, 30))
        self.Bind(wx.EVT_CHAR, self.on_char)
        self.Layout()

    def on_char(self, evt):
        print("Text is shown: %s, with size %s" % (self.t.Shown, self.t.Size))
        if self.t.Shown:
            self.t.Show(False)
        else:
            self.t.Label += "AA"
            self.t.Show(True) # Moving this line up solves the issue
            #self.t.Wrap(-1) # This is another way to solve the issue
            #self.t.InvalidateBestSize() # Doesn't seem to help
        print("Text is shown: %s, with size %s" % (self.t.Shown, self.t.Size))

Pressing a key a couple of times shows this output:

Text is shown: True, with size (223, 17)
Text is shown: False, with size (223, 17)
Text is shown: False, with size (223, 17)
Text is shown: True, with size (1, 0)
Text is shown: True, with size (1, 1)
Text is shown: False, with size (1, 1)

This is probably related to issues #16088 and #17160 (ie, GTK3 doesn't bother computing the size of a control which is hidden). Maybe on GTK3, any change to a hidden control should be noted in a flag. Then the next time the control is shown while this flag is on, the size should be updated?

Change History (1)

comment:1 Changed 7 months ago by pcor

  • Resolution set to fixed
  • Status changed from new to closed

This was fixed on master by 85b37bea495f11d949669cd99afc4fde9b30d7e7, now backported to WX_3_0_BRANCH in 1a40ebc10744cbe8981cce962624692e7621437e

Note: See TracTickets for help on using tickets.