I am using ZeroBrane Studio (2.01; MobDebug 0.805) on Windows 10. I need to insert a white square panel on top of the "panel". This panel should be a square. The panel should scale with the window size.
I want to get this:
MWE:
package.cpath = package.cpath..";./?.dll;./?.so;../lib/?.so;../lib/vc_dll/?.dll;../lib/bcc_dll/?.dll;../lib/mingw_dll/?.dll;"
require("wx")
frame = wx.wxFrame(wx.NULL, wx.wxID_ANY, "wxLua sizer test frame", wx.wxDefaultPosition, wx.wxSize(450, 450), wx.wxDEFAULT_FRAME_STYLE)
panel = wx.wxPanel(frame, wx.wxID_ANY)
button1 = wx.wxButton(frame, wx.wxID_ANY, "Button1")
button2 = wx.wxButton(frame, wx.wxID_ANY, "Button2")
topsizer = wx.wxBoxSizer(wx.wxVERTICAL)
bottomsizer = wx.wxBoxSizer(wx.wxHORIZONTAL)
topsizer:Add(panel, 1, wx.wxGROW + wx.wxALL, 6)
topsizer:Add(bottomsizer, 0, wx.wxEXPAND + wx.wxALL, 0);
bottomsizer:Add(button1, 1, wx.wxEXPAND + wx.wxALL, 6)
bottomsizer:Add(button2, 1, wx.wxEXPAND + wx.wxALL, 6)
function onButton1Click(event)
wx.wxMessageBox("Button1 clicked!", "Information", wx.wxOK + wx.wxICON_INFORMATION)
end
button1:Connect(wx.wxEVT_COMMAND_BUTTON_CLICKED, onButton1Click)
function onButton2Click(event)
wx.wxMessageBox("Button2 clicked!", "Information", wx.wxOK + wx.wxICON_INFORMATION)
end
button2:Connect(wx.wxEVT_COMMAND_BUTTON_CLICKED, onButton2Click)
frame:SetAutoLayout(true)
frame:SetSizer(topsizer)
wx.wxGetApp():SetTopWindow(frame)
frame:Show(true)
wx.wxGetApp():MainLoop()
I tried using Sizer.
It's not clear if your white square should be a window or should be just displayed on the panel. In the latter case, you need to connect to wxEVT_PAINT
and draw a centered rectangle in your handler.
If you want to have a window, you can create one and add it to a grid sizer or use nested box sizers. The exact way to do it depends if you want to have fixed borders around your square or something more complicated.
Not really related to your question, but:
SetAutoLayout(true)
, this is the default.wxGROW
and wxEXPAND
in the same code, they're synonyms and mean exactly the same thing.