Skip to content

Commit

Permalink
[wxstrgen] Refactors UI layout.
Browse files Browse the repository at this point in the history
Fixes initial size issues.
Uses Bind instead of static event table.
Adds FetchContent fallback for wxWidgets not found.
  • Loading branch information
UoLAidan committed Feb 23, 2021
1 parent d1ef341 commit a8e6cbe
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 212 deletions.
27 changes: 26 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,32 @@ if(USE_ICU)
endif()

if(BUILD_GUI_TOOLS)
find_package(wxWidgets REQUIRED core base xrc xml adv)
find_package(wxWidgets 3.0.4 COMPONENTS core base xrc xml adv)

if(NOT wxWidgets_FOUND)
# We are going to use the FetchContent module to grab crashpad and its dependencies.
include(FetchContent)

FetchContent_Declare(
wxwidgets_git
GIT_REPOSITORY https://github.com/wxWidgets/wxWidgets.git
GIT_TAG v3.1.4
GIT_PROGRESS TRUE
GIT_SHALLOW TRUE
)

# Do we want static linking or not?
set(wxBUILD_SHARED OFF CACHE BOOL "Build wx libraries as shared libs")

# We don't use FetchContent_MakeAvailable here because we don't want all wxwidgets_git targets including, just our dependency.
FetchContent_GetProperties(wxwidgets_git)
if(NOT wxwidgets_git_POPULATED)
FetchContent_Populate(wxwidgets_git)
add_subdirectory(${wxwidgets_git_SOURCE_DIR} ${wxwidgets_git_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
set(wxWidgets_LIBRARIES wxcore wxbase wxxrc wxxml wxadv)
set(wxWidgets_wxrc_EXECUTABLE wxrc)
endif()
endif()

# Set version info for the base config module
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ target_link_libraries(ini2str PUBLIC common)
add_executable(strgen ini2str/strgen.cpp)
target_link_libraries(strgen ini2str)

if(wxWidgets_FOUND)
if(wxWidgets_FOUND OR wxwidgets_git_POPULATED)
if(NOT wxWidgets_wxrc_EXECUTABLE)
message(FATAL_ERROR "wxrc resource compiler was not found, please set wxWidgets_wxrc_EXECUTABLE manually.")
endif()
Expand Down
20 changes: 8 additions & 12 deletions src/ini2str/wxstrgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,20 @@
class StrGenFrame: public MainFrame
{
public:
StrGenFrame(wxWindow *parent = NULL) : MainFrame(parent) {}
StrGenFrame(wxWindow *parent = nullptr);

void OnCreateIni(wxCommandEvent &event);
void OnCreateStr(wxCommandEvent &event);
void OnExitToolOrMenuCommand(wxCommandEvent &event);

wxDECLARE_EVENT_TABLE();
};

// clang-format off
wxBEGIN_EVENT_TABLE(StrGenFrame, wxFrame)
EVT_MENU(wxID_EXIT, StrGenFrame::OnExitToolOrMenuCommand)
EVT_BUTTON(XRCID("m_buttonToIni"), StrGenFrame::OnCreateIni)
EVT_BUTTON(XRCID("m_buttonToStr"), StrGenFrame::OnCreateStr)
wxEND_EVENT_TABLE()
// clang-format on


StrGenFrame::StrGenFrame(wxWindow *parent) :
MainFrame(parent)
{
Bind(wxEVT_COMMAND_MENU_SELECTED, &StrGenFrame::OnExitToolOrMenuCommand, this, wxID_EXIT);
Bind(wxEVT_BUTTON, &StrGenFrame::OnCreateIni, this, XRCID("m_buttonToIni"));
Bind(wxEVT_BUTTON, &StrGenFrame::OnCreateStr, this, XRCID("m_buttonToStr"));
}

void StrGenFrame::OnCreateIni(wxCommandEvent &event)
{
Expand Down
281 changes: 83 additions & 198 deletions src/ini2str/wxstrgenui.xrc
Original file line number Diff line number Diff line change
@@ -1,219 +1,104 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
<object class="wxFrame" name="MainFrame">
<style>wxCAPTION|wxCLOSE_BOX|wxFRAME_SHAPED|wxMINIMIZE_BOX|wxRESIZE_BORDER|wxSYSTEM_MENU|wxTAB_TRAVERSAL</style>
<size>-1,180</size>
<style>wxCAPTION|wxCLOSE_BOX|wxFRAME_SHAPED|wxMINIMIZE_BOX|wxSYSTEM_MENU|wxTAB_TRAVERSAL</style>
<bg>#f0f0f0</bg>
<title>String Table Generator</title>
<centered>1</centered>
<aui_managed>0</aui_managed>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="wxFlexGridSizer">
<rows>3</rows>
<cols>3</cols>
<minsize>-1,150</minsize>
<vgap>0</vgap>
<hgap>0</hgap>
<growablecols></growablecols>
<growablerows></growablerows>
<object class="sizeritem">
<option>1</option>
<flag>wxEXPAND</flag>
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL</flag>
<border>5</border>
<object class="wxStaticText" name="m_iniLabel">
<style>wxALIGN_RIGHT</style>
<label>INI File:</label>
<wrap>-1</wrap>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER|wxALL</flag>
<border>5</border>
<object class="wxFilePickerCtrl" name="m_filePickerINI">
<value></value>
<message>Select a file</message>
<wildcard>*.*</wildcard>
<style>wxFLP_DEFAULT_STYLE|wxFLP_SAVE</style>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL|wxEXPAND</flag>
<border>5</border>
<object class="wxButton" name="m_buttonToStr">
<label>Create String File</label>
<default>0</default>
<markup>0</markup>
<bitmap />
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL</flag>
<border>5</border>
<object class="wxStaticText" name="m_strLabel">
<style>wxALIGN_RIGHT</style>
<label>String File:</label>
<wrap>-1</wrap>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER|wxALL</flag>
<border>5</border>
<object class="wxFilePickerCtrl" name="m_filePickerString">
<value></value>
<message>Select a file</message>
<wildcard>*.*</wildcard>
<style>wxFLP_DEFAULT_STYLE|wxFLP_SAVE</style>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL|wxEXPAND</flag>
<border>5</border>
<object class="wxButton" name="m_buttonToIni">
<label>Create INI File</label>
<default>0</default>
<markup>0</markup>
<bitmap />
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="spacer">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<size>0,0</size>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxStaticText" name="m_iniLabel">
<label>INI File:</label>
<wrap>-1</wrap>
</object>
</object>
<object class="spacer">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<size>0,0</size>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxStaticText" name="m_strLabel">
<label>String File:</label>
<wrap>-1</wrap>
</object>
</object>
<object class="spacer">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<size>0,0</size>
</object>
</object>
</object>
<object class="sizeritem">
<option>2</option>
<flag>wxEXPAND</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="spacer">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<size>0,0</size>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL|wxEXPAND</flag>
<border>5</border>
<object class="wxFilePickerCtrl" name="m_filePickerINI">
<value></value>
<message>Select a file</message>
<wildcard>*.*</wildcard>
<style>wxFLP_DEFAULT_STYLE|wxFLP_SAVE</style>
</object>
</object>
<object class="spacer">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<size>0,0</size>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL|wxEXPAND</flag>
<border>5</border>
<object class="wxFilePickerCtrl" name="m_filePickerString">
<value></value>
<message>Select a file</message>
<wildcard>*.*</wildcard>
<style>wxFLP_DEFAULT_STYLE|wxFLP_SAVE</style>
</object>
</object>
<object class="spacer">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<size>0,0</size>
</object>
</object>
</object>
<object class="sizeritem">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="spacer">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<size>0,0</size>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL|wxEXPAND</flag>
<border>5</border>
<object class="wxButton" name="m_buttonToIni">
<label>Create INI File</label>
<default>0</default>
<markup>0</markup>
<bitmap />
</object>
</object>
<object class="spacer">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<size>0,0</size>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL|wxEXPAND</flag>
<border>5</border>
<object class="wxButton" name="m_buttonToStr">
<label>Create String File</label>
<default>0</default>
<markup>0</markup>
<bitmap />
</object>
</object>
<object class="spacer">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<size>0,0</size>
</object>
</object>
</object>
<object class="wxStaticText" name="m_staticText4">
<style>wxALIGN_RIGHT</style>
<label>Language:</label>
<wrap>-1</wrap>
</object>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxEXPAND</flag>
<flag>wxALIGN_CENTER_VERTICAL|wxALL</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxEXPAND</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="spacer">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<size>0,0</size>
</object>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxStaticText" name="m_staticText4">
<label>Language:</label>
<wrap>-1</wrap>
</object>
</object>
<object class="spacer">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<size>0,0</size>
</object>
</object>
</object>
<object class="sizeritem">
<option>1</option>
<flag>wxEXPAND</flag>
<border>5</border>
<object class="wxBoxSizer">
<orient>wxVERTICAL</orient>
<object class="sizeritem">
<option>0</option>
<flag>wxALL</flag>
<border>5</border>
<object class="wxTextCtrl" name="m_textCtrl1">
<value>eng</value>
<maxlength>3</maxlength>
</object>
</object>
</object>
</object>
<object class="wxTextCtrl" name="m_textCtrl1">
<value>eng</value>
<maxlength>3</maxlength>
</object>
</object>
</object>
<object class="wxStatusBar" name="m_statusBar">
<style>wxSTB_SIZEGRIP</style>
<fields>1</fields>
</object>
</object>
Expand Down

0 comments on commit a8e6cbe

Please sign in to comment.