update
This commit is contained in:
parent
14706d425a
commit
c6de43f5c1
|
|
@ -6,13 +6,23 @@ set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
# Add For Windows, specify Unicode
|
# Add For Windows, specify Unicode
|
||||||
|
set(APP_TYPE "")
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
add_definitions(-DUNICODE -D_UNICODE)
|
add_definitions(-DUNICODE -D_UNICODE)
|
||||||
|
set(APP_TYPE WIN32)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(wxBUILD_SHARED OFF)
|
||||||
|
|
||||||
# Add wxWidgets as a subdirectory
|
# Add wxWidgets as a subdirectory
|
||||||
add_subdirectory(external/wxWidgets)
|
add_subdirectory(external/wxWidgets)
|
||||||
|
|
||||||
|
# get_cmake_property(_variableNames VARIABLES)
|
||||||
|
# list(SORT _variableNames)
|
||||||
|
# foreach(_variableName ${_variableNames})
|
||||||
|
# message(STATUS "${_variableName}=${${_variableName}}")
|
||||||
|
# endforeach()
|
||||||
|
|
||||||
# Define your source files
|
# Define your source files
|
||||||
set(SRC_DIR ${CMAKE_SOURCE_DIR}/src)
|
set(SRC_DIR ${CMAKE_SOURCE_DIR}/src)
|
||||||
file(GLOB SRC_FILES ${SRC_DIR}/*.cpp)
|
file(GLOB SRC_FILES ${SRC_DIR}/*.cpp)
|
||||||
|
|
@ -20,8 +30,6 @@ file(GLOB SRC_FILES ${SRC_DIR}/*.cpp)
|
||||||
# Include directories
|
# Include directories
|
||||||
include_directories(${CMAKE_SOURCE_DIR}/external/wxWidgets/include)
|
include_directories(${CMAKE_SOURCE_DIR}/external/wxWidgets/include)
|
||||||
|
|
||||||
add_definitions(-D__WXUNIVERSAL__)
|
|
||||||
|
|
||||||
# Link additional libraries
|
# Link additional libraries
|
||||||
set(WX_LIB
|
set(WX_LIB
|
||||||
wx::core
|
wx::core
|
||||||
|
|
@ -32,7 +40,7 @@ set(WX_LIB
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create the executable
|
# Create the executable
|
||||||
add_executable(${PROJECT_NAME} ${SRC_FILES})
|
add_executable(${PROJECT_NAME} ${APP_TYPE} ${SRC_FILES})
|
||||||
|
|
||||||
# Link wxWidgets libraries
|
# Link wxWidgets libraries
|
||||||
target_link_libraries(${PROJECT_NAME} ${WX_LIB})
|
target_link_libraries(${PROJECT_NAME} ${WX_LIB})
|
||||||
|
|
|
||||||
119
src/main.cpp
119
src/main.cpp
|
|
@ -1,56 +1,117 @@
|
||||||
#include <wx/wx.h>
|
#include <wx/wx.h>
|
||||||
|
#include <wx/aui/aui.h>
|
||||||
|
#include <wx/settings.h>
|
||||||
|
#include <wx/artprov.h>
|
||||||
|
|
||||||
class MyApp.compp : public wxApp
|
// Custom frame class
|
||||||
|
class MyFrame : public wxFrame
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyFrame(const wxString &title);
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxAuiManager m_mgr;
|
||||||
|
|
||||||
|
void OnExit(wxCommandEvent &event);
|
||||||
|
void OnAbout(wxCommandEvent &event);
|
||||||
|
// void OnToggleTheme(wxCommandEvent &event);
|
||||||
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
ID_Exit = wxID_EXIT,
|
||||||
|
ID_About = wxID_ABOUT,
|
||||||
|
ID_ToggleTheme = wxID_HIGHEST + 1
|
||||||
|
};
|
||||||
|
|
||||||
|
// Application class
|
||||||
|
class MyApp : public wxApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool OnInit();
|
virtual bool OnInit();
|
||||||
};
|
};
|
||||||
|
|
||||||
class MyFrame.comrame : public wxFrame.comame
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MyFrame.comrame(const wxString& title);
|
|
||||||
|
|
||||||
private:
|
|
||||||
void OnQuit(wxCommandEvent& event);
|
|
||||||
void OnAbout(wxCommandEvent& event);
|
|
||||||
};
|
|
||||||
|
|
||||||
wxIMPLEMENT_APP(MyApp);
|
wxIMPLEMENT_APP(MyApp);
|
||||||
|
|
||||||
bool MyApp.comnInit()
|
bool MyApp::OnInit()
|
||||||
{
|
{
|
||||||
MyFrame.comrame* frame = new MyFrame.comrame("Advanced wxWidgets Demo");
|
if (!wxApp::OnInit())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Create main frame
|
||||||
|
MyFrame *frame = new MyFrame("Modern wxWidgets App");
|
||||||
frame->Show(true);
|
frame->Show(true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
MyFrame.comrame::MyFrame.comnst wxString& title)
|
MyFrame::MyFrame(const wxString &title)
|
||||||
: wxFrame.comame(NULL, wxID_ANY, title)
|
: wxFrame(nullptr, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600)),
|
||||||
|
m_mgr(this)
|
||||||
{
|
{
|
||||||
wxMenu* menuFile = new wxMenu;
|
// Create menu bar
|
||||||
menuFile->Append(wxID_EXIT);
|
wxMenu *fileMenu = new wxMenu;
|
||||||
|
fileMenu->Append(ID_Exit, "E&xit\tAlt-X", "Quit this program");
|
||||||
|
|
||||||
wxMenu* menuHelp = new wxMenu;
|
wxMenu *helpMenu = new wxMenu;
|
||||||
menuHelp->Append(wxID_ABOUT);
|
helpMenu->Append(ID_About, "&About\tF1", "Show about dialog");
|
||||||
|
helpMenu->Append(ID_ToggleTheme, "&Toggle Theme\tCtrl-T", "Toggle Dark Mode");
|
||||||
|
|
||||||
wxMenuBar* menuBar = new wxMenuBar.com
|
wxMenuBar *menuBar = new wxMenuBar();
|
||||||
menuBar->Append(menuFile, "&File");
|
menuBar->Append(fileMenu, "&File");
|
||||||
menuBar->Append(menuHelp, "&Help");
|
menuBar->Append(helpMenu, "&Help");
|
||||||
|
|
||||||
SetMenuBar(menuBar);
|
SetMenuBar(menuBar);
|
||||||
|
|
||||||
Bind(wxEVT_MENU, &MyFrame.comrame::OnQuit, this, wxID_EXIT);
|
// Create a toolbar
|
||||||
Bind(wxEVT_MENU, &MyApp.comrame::OnAbout, this, wxID_ABOUT);
|
wxToolBar *toolbar = CreateToolBar();
|
||||||
|
toolbar->AddTool(wxID_ANY, "Exit", wxArtProvider::GetBitmap(wxART_QUIT));
|
||||||
|
toolbar->Realize();
|
||||||
|
|
||||||
|
// Create a text control in the center
|
||||||
|
wxTextCtrl *textCtrl = new wxTextCtrl(this, wxID_ANY, "Modern wxWidgets App",
|
||||||
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
wxTE_MULTILINE | wxNO_BORDER);
|
||||||
|
|
||||||
|
// Create a status bar
|
||||||
|
CreateStatusBar(2);
|
||||||
|
SetStatusText("Welcome to wxWidgets!");
|
||||||
|
|
||||||
|
// Manage layout with wxAuiManager (for modern look)
|
||||||
|
m_mgr.SetManagedWindow(this);
|
||||||
|
m_mgr.AddPane(textCtrl, wxAuiPaneInfo().Center().Caption("Editor"));
|
||||||
|
m_mgr.Update();
|
||||||
|
|
||||||
|
// Bind events
|
||||||
|
Bind(wxEVT_MENU, &MyFrame::OnExit, this, ID_Exit);
|
||||||
|
Bind(wxEVT_MENU, &MyFrame::OnAbout, this, ID_About);
|
||||||
|
// Bind(wxEVT_MENU, &MyFrame::OnToggleTheme, this, ID_ToggleTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyApp.comrame::OnQuit(wxCommandEvent& event)
|
void MyFrame::OnExit(wxCommandEvent &event)
|
||||||
{
|
{
|
||||||
Close(true);
|
Close(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyApp.comrame::OnAbout(wxCommandEvent& event)
|
void MyFrame::OnAbout(wxCommandEvent &event)
|
||||||
{
|
{
|
||||||
wxMessageBox("This is an advanced wxWidgets demo application.",
|
wxMessageBox("This is a modern wxWidgets app", "About wxWidgets App", wxOK | wxICON_INFORMATION, this);
|
||||||
"About", wxOK | wxICON_INFORMATION);
|
}
|
||||||
}
|
|
||||||
|
// void MyFrame::OnToggleTheme(wxCommandEvent &event)
|
||||||
|
// {
|
||||||
|
// wxSystemAppearance appearance = wxSystemSettings::GetAppearance();
|
||||||
|
// bool isDarkMode = appearance.IsDark();
|
||||||
|
|
||||||
|
// if (isDarkMode)
|
||||||
|
// {
|
||||||
|
// wxSystemSettings::SetAppearance(wxSystemAppearance::Light);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// wxSystemSettings::SetAppearance(wxSystemAppearance::Dark);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// wxMessageBox(isDarkMode ? "Switched to Light Mode" : "Switched to Dark Mode", "Theme Switch",
|
||||||
|
// wxOK | wxICON_INFORMATION, this);
|
||||||
|
// }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue