gui:可显示UI。

This commit is contained in:
taynpg 2025-04-03 10:23:46 +08:00
parent 48e9b36e6c
commit 2daea403b4
7 changed files with 68 additions and 12 deletions

View File

@ -1,7 +1,9 @@
#include "basepanel.h"
CBasePanel::CBasePanel(wxWindow* parent)
CBasePanel::CBasePanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
: wxPanel(parent, wxID_ANY, pos, size, style, name)
{
Init();
}
void CBasePanel::Init()
@ -18,4 +20,7 @@ void CBasePanel::Init()
szL1->Add(edIp_, 0, wxALL, 5);
szL1->Add(lbPort, 0, wxALL, 5);
szL1->Add(edPort_, 0, wxALL, 5);
topSizer->Add(szL1, 0, wxEXPAND | wxALL, 5);
this->SetSizer(topSizer);
}

View File

@ -6,7 +6,7 @@
class CBasePanel : public wxPanel
{
public:
CBasePanel(wxWindow* parent);
CBasePanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name);
private:
void Init();

View File

@ -1,4 +1,22 @@
#include "mainframe.h"
#include <memory>
IMPLEMENT_APP(CMainFrame);
DECLARE_APP(CMainFrame);
class CMainForm : public wxApp
{
public:
bool OnInit() override;
private:
CMainFrame* frmae_{};
};
IMPLEMENT_APP(CMainForm);
DECLARE_APP(CMainForm);
bool CMainForm::OnInit()
{
// 这里也是自动释放的,不需要智能指针或者手动释放。
frmae_ = new CMainFrame(_("GTransm"));
frmae_->Show(true);
return true;
}

View File

@ -1,6 +1,25 @@
#include "mainframe.h"
bool CMainFrame::OnInit()
CMainFrame::CMainFrame(const wxString& title) : wxFrame(nullptr, wxID_ANY, title)
{
return false;
}
InitFrame();
ManLayout();
}
void CMainFrame::InitFrame()
{
if (panela_ == nullptr) {
panela_ = new CMainPanel(this);
}
if (panelb_ == nullptr) {
panelb_ = new CMainPanel(this);
}
}
void CMainFrame::ManLayout()
{
auto* szTop = new wxBoxSizer(wxHORIZONTAL);
szTop->Add(panela_, 1, wxEXPAND);
szTop->Add(panelb_, 1, wxEXPAND);
SetSizer(szTop);
}

View File

@ -1,13 +1,21 @@
#ifndef MAINFRAME_H
#define MAINFRAME_H
#include "mainpanel.h"
#include <wx/wx.h>
#include "design/basepanel.h"
class CMainFrame : public wxApp
class CMainFrame : public wxFrame
{
public:
bool OnInit() override;
explicit CMainFrame(const wxString& title);
public:
void InitFrame();
void ManLayout();
private:
CMainPanel* panela_{};
CMainPanel* panelb_{};
};
#endif

View File

@ -1,5 +1,6 @@
#include "mainpanel.h"
CMainPanel::CMainPanel(wxWindow* parent) : CBasePanel(parent)
CMainPanel::CMainPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
: CBasePanel(parent, id, pos, size, style, name)
{
}

View File

@ -3,10 +3,15 @@
#include "design/basepanel.h"
constexpr int g_Width = 300;
constexpr int g_Heigh = 450;
constexpr int g_Border = 3;
class CMainPanel : public CBasePanel
{
public:
CMainPanel(wxWindow* parent);
CMainPanel(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxSize(g_Width, g_Heigh), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString);
};
#endif // MAINPANEL_H