working on sample UI

This commit is contained in:
Caelan Sayler
2024-11-08 20:05:25 +00:00
committed by Caelan
parent 3b3eea72dc
commit bb3758a851
2 changed files with 129 additions and 26 deletions

View File

@@ -18,19 +18,35 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(wxWidgets)
set(SRCS main.cpp)
if(APPLE)
# create bundle on apple compiles
add_executable(main MACOSX_BUNDLE ${SRCS})
# Set a custom plist file for the app bundle - needed for Mac OS Retina display
set_target_properties(main PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
# include the Velopack library (headers + precompiled lib)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../src/lib-cpp/include")
if(CMAKE_BUILD_TYPE STREQUAL "Release")
message(STATUS "Building in Release mode")
set(VELOPACK_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/release/velopack_libc.dll.lib")
set(VELOPACK_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/release/velopack_libc.dll")
else()
message(STATUS "Building in Debug mode")
set(VELOPACK_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/velopack_libc.dll.lib")
set(VELOPACK_DLL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/velopack_libc.dll")
endif()
# add sources and executable
set(SRCS main.cpp)
if(WIN32)
# the WIN32 is needed for Windows in order for it to look for WinMain
# instead of the main function. This is ignored on other systems,
# so it works on all platforms
add_executable(main WIN32 ${SRCS} main.exe.manifest)
else()
add_executable(main ${SRCS})
endif()
target_link_libraries(main PRIVATE wxcore wxnet)
target_compile_definitions(main PRIVATE RELEASES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/releases")
target_link_libraries(main PRIVATE wxcore wxnet "${VELOPACK_LIB_PATH}")
# copy velopack dll to output directory
add_custom_command(TARGET main POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${VELOPACK_DLL_PATH}"
"$<TARGET_FILE_DIR:main>"
)

View File

@@ -1,28 +1,115 @@
#include <wx/wx.h>
#include <optional>
#include <string>
#include "Velopack.h"
class MyApp : public wxApp
using namespace Velopack;
std::optional<UpdateManager> updateManager;
std::optional<UpdateInfo> updateInfo;
std::string logBuffer;
std::optional<UpdateManager> get_or_create_update_manager()
{
public:
virtual bool OnInit();
};
try
{
updateManager = UpdateManager(RELEASES_DIR);
}
catch (std::exception& ex)
{
std::string message = std::string("\n") + ex.what();
logBuffer.append(message);
}
return updateManager;
}
std::string get_status()
{
return "";
}
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
MyFrame() : wxFrame(nullptr, wxID_ANY, "VelopackCppWidgetsSample", wxDefaultPosition, wxSize(600, 600))
{
// Set background color to white
SetBackgroundColour(*wxWHITE);
// Main vertical sizer
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
// Auto-wrapping text
topText = new wxStaticText(this, wxID_ANY,
"This is a sample text that will automatically wrap based on the width of the window. "
"Resize the window to see the text wrap around.");
topText->Wrap(380); // Set wrap width close to the window width
mainSizer->Add(topText, 0, wxALL | wxEXPAND, 10);
// Create a horizontal sizer for the buttons
wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL);
wxButton* button1 = new wxButton(this, wxID_ANY, "Check for Updates");
wxButton* button2 = new wxButton(this, wxID_ANY, "Button 2");
wxButton* button3 = new wxButton(this, wxID_ANY, "Button 3");
// Add buttons to the button sizer
buttonSizer->Add(button1, 0, wxALL, 5);
buttonSizer->Add(button2, 0, wxALL, 5);
buttonSizer->Add(button3, 0, wxALL, 5);
// Add the button sizer to the main sizer
mainSizer->Add(buttonSizer, 0, wxALIGN_CENTER);
// Add a large, scrollable text area
textArea = new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxSize(600, 400),
wxTE_MULTILINE | wxTE_RICH2 | wxTE_READONLY | wxTE_AUTO_URL);
mainSizer->Add(textArea, 1, wxALL | wxEXPAND, 10);
// Set the sizer for the frame
SetSizer(mainSizer);
mainSizer->Fit(this);
// Set up a timer for periodic updates
timer = new wxTimer(this);
Bind(wxEVT_TIMER, &MyFrame::OnTimer, this);
timer->Start(1000); // Trigger updates every second
}
~MyFrame()
{
timer->Stop();
delete timer;
}
private:
wxStaticText* topText;
wxTextCtrl* textArea;
wxTimer* timer;
int updateCount = 0;
void OnTimer(wxTimerEvent&)
{
// Update the static text
topText->SetLabel(wxString::Format("Updated Text - %d", updateCount));
topText->Wrap(380); // Re-wrap after changing text
// Update the scrollable text area
textArea->AppendText(wxString::Format("Log Entry %d\n", updateCount));
updateCount++;
}
};
class MyApp : public wxApp
{
public:
virtual bool OnInit()
{
get_or_create_update_manager();
MyFrame* frame = new MyFrame();
frame->Show(true);
return true;
}
};
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
MyFrame* frame = new MyFrame("Hello Everyone!", wxDefaultPosition, wxDefaultSize);
frame->Show(true);
return true;
}
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(NULL, wxID_ANY, title, pos, size)
{
new wxStaticText(this, wxID_ANY, "Good Morning!"); // no need to delete - the parent will do it automatically
}