Skip to content

Commit

Permalink
Release 1 (#21)
Browse files Browse the repository at this point in the history
* add: public API endpoints for getting component position and size
* improve: menu selection/toggling
* update: readme
* update: version
* improve: menu selection/toggling
* add: public API endpoints for showing row borders and getting multiple files/folders
* fix: conflicting typedef names
* add: public API endpoints LSG_GetText, LSG_SetMenuItemValue, LSG_SetSliderValue and LSG_SetVisible
* add: event triggers for click, double-click and right-click on panels
* improve: dynamic font size handling
* improve: menu labels
* improve: make sure menu is rendered last (above all other UI)
* add: public API endpoint for getting slider value
* add: public API endpoints LSG_RemoveMenuItem and LSG_SaveFile
* add: public API endpoints LSG_GetSelectedRow and LSG_SelectRow
* add: public API endpoints LSG_GetSortColumn, LSG_GetSortOrder, LSG_GetScrollHorizontal, LSG_GetScrollVertical, LSG_IsVisible, LSG_ScrollHorizontal and LSG:ScrollVertical
* add: pagination for lists and tables
* add: public API endpoints LSG_GetColorTheme, LSG_GetPage and LSG_SetPage
* fix: SetPage only calls list component, needs to be separate calls to list and table.
* improve: pagination label
* fix: LSG_GetTableRow does not include header
* add: public API endpoint to scroll to the bottom (#1)
* add: public API endpoint to get the last page (#2)
* add: public API endpoint to select a row by offset (#3)
* improve: increase max rows per page (#4)
* fix: scroll by offset after changing page (#6)
* Library gtk not mentioned in readme (#7)
* add: event notifications for component scrolling and keyboard interaction (#8)
* fix: reset page navigation when setting list/table content (#9)
* fix: make sure menu is properly closed when selecting an item (#10)
* improve: disable child components when disabling a parent (#11)
* improve: component highlight on hover (#15)
* improve: sub-menu navigation (#16)
* add: public API endpoint LSG_GetBackgroundColor (#17)
* add: public API endpoint to select a button (#18)
* fix: scroll direction is oppposite on macOS (#19)
* improve: support for cross-platform build (#20)
  • Loading branch information
adamajammary authored Sep 16, 2023
1 parent 55dfea9 commit 2be8d4d
Show file tree
Hide file tree
Showing 44 changed files with 4,037 additions and 1,615 deletions.
146 changes: 106 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
cmake_minimum_required(VERSION 3.12)

project (testsdl2gui)
project (libsdl2gui)
project (sdl2gui)

# libsdl2gui depends on the following third-party libraries:
# - sdl2, sdl2_image, sdl2_ttf, libxml2

set(EXT_LIB_DIR "${EXT_LIB_DIR}")
set(INC_DIR "${EXT_LIB_DIR}/include")
set(LIB_DIR "${EXT_LIB_DIR}/lib")
set(CPP_VERSION "20")

if (APPLE)
set(CMAKE_CXX_STANDARD "20")
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (ANDROID)
set(OS "_android")
elseif (IOS)
set(OS "_ios")

set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_MACOSX_BUNDLE OFF)

set(IOS_LIBS "iconv -framework AudioToolbox -framework AVFAudio -framework CoreBluetooth -framework CoreFoundation -framework CoreGraphics -framework CoreHaptics -framework CoreMotion -framework Foundation -framework GameController -framework ImageIO -framework Metal -framework MobileCoreServices -framework OpenGLES -framework QuartzCore -framework UIKit")
elseif (APPLE)
set(OS "_macosx")
elseif (UNIX)

set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x objective-c++")

set(MACOSX_LIBS "-framework AppKit")
elseif (LINUX)
set(OS "_linux")

set(GTK_INC /usr/include/gtk-3.0 /usr/include/pango-1.0 /usr/include/glib-2.0 /usr/lib/x86_64-linux-gnu/glib-2.0/include /usr/include/harfbuzz /usr/include/freetype2 /usr/include/libpng16 /usr/include/libmount /usr/include/blkid /usr/include/fribidi /usr/include/cairo /usr/include/pixman-1 /usr/include/gdk-pixbuf-2.0 /usr/include/x86_64-linux-gnu /usr/include/gio-unix-2.0 /usr/include/atk-1.0 /usr/include/at-spi2-atk/2.0 /usr/include/at-spi-2.0 /usr/include/dbus-1.0 /usr/lib/x86_64-linux-gnu/dbus-1.0/include)
set(GTK_LIB -lgtk-3 -lgdk-3 -lz -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0)
elseif (WIN32)
set(OS "_windows")
set(RC "windows/libsdl2gui.rc")
Expand All @@ -24,10 +43,10 @@ endif()

if (WIN32)
set(LIBS SDL2.lib SDL2_image.lib SDL2_ttf.lib libxml2.lib)
set(LIBS_TEST SDL2.lib)
set(TEST_LIBS SDL2.lib)
else()
set(LIBS -lSDL2 -lSDL2_image -lSDL2_ttf -lxml2)
set(LIBS_TEST -lSDL2)
set(TEST_LIBS -lSDL2)
endif()

file(GLOB INC_H "inc/*.h")
Expand All @@ -38,64 +57,111 @@ file(GLOB TEST_H "test/*.h")
file(GLOB TEST_CPP "test/*.cpp")
file(GLOB UI "ui/*")

add_library(libsdl2gui SHARED ${SOURCES_CPP} ${SOURCES_H} ${INC_H} ${RC})
if (IOS)
add_library(sdl2gui STATIC ${SOURCES_CPP} ${SOURCES_H} ${INC_H} ${RC})
else()
add_library(sdl2gui SHARED ${SOURCES_CPP} ${SOURCES_H} ${INC_H} ${RC})
endif()

source_group("Resources" FILES ${RC})
target_compile_definitions(libsdl2gui PRIVATE ${OS} _CRT_SECURE_NO_WARNINGS MAKEDLL)
target_include_directories(libsdl2gui PRIVATE "inc" ${INC_DIR})
target_link_directories(libsdl2gui PRIVATE ${LIB_DIR})
target_link_libraries(libsdl2gui PRIVATE ${LIBS})
set_property(TARGET libsdl2gui PROPERTY CXX_STANDARD ${CPP_VERSION})
target_compile_definitions(sdl2gui PRIVATE ${OS} _CRT_SECURE_NO_WARNINGS NOMINMAX MAKEDLL)
target_include_directories(sdl2gui PRIVATE "inc" ${INC_DIR} "${INC_DIR}/libxml2" ${GTK_INC})
target_link_directories(sdl2gui PRIVATE ${LIB_DIR})
target_link_libraries(sdl2gui PRIVATE ${LIBS} ${GTK_LIB} ${MACOSX_LIBS})

add_executable(testsdl2gui ${TEST_CPP} ${TEST_H} ${INC_H} ${IMG} ${UI})
source_group("Images" FILES ${IMG})
source_group("UI" FILES ${UI})
target_compile_definitions(testsdl2gui PRIVATE ${OS})
target_include_directories(testsdl2gui PRIVATE "inc" ${INC_DIR})
target_link_directories(testsdl2gui PRIVATE ${LIB_DIR})
target_link_libraries(testsdl2gui PRIVATE libsdl2gui ${LIBS_TEST})
set_property(TARGET testsdl2gui PROPERTY CXX_STANDARD ${CPP_VERSION})
target_link_libraries(testsdl2gui PRIVATE sdl2gui ${TEST_LIBS} ${IOS_LIBS})

if (WIN32)
set_target_properties(testsdl2gui PROPERTIES LINK_FLAGS_DEBUG "-SUBSYSTEM:CONSOLE,5.02")
set_target_properties(testsdl2gui PROPERTIES LINK_FLAGS_RELEASE "-SUBSYSTEM:WINDOWS,5.02")
endif()

set(BUILD_DIR "${CMAKE_BINARY_DIR}")
set(SRC_DIR "${CMAKE_SOURCE_DIR}")
set(DIST_DIR "${BUILD_DIR}/dist")

if (APPLE)
set(DLL_EXT "dylib")
if (IOS)
set(DLL_EXT "a")
set(LIB_EXT "a")
set(OUT_DIR "${BUILD_DIR}/out")
elseif (UNIX)
set(DLL_EXT "so")
set(LIB_EXT "a")
set(CFG_DIR "Release-iphoneos/")
elseif (APPLE)
set(DLL_EXT "dylib")
set(LIB_EXT "dylib")
set(OUT_DIR "${BUILD_DIR}/out")
set(CFG_DIR "Release/")
elseif (WIN32)
set(DLL_EXT "dll")
set(LIB_EXT "lib")
set(OUT_DIR "${BUILD_DIR}/$(Configuration)")
else()
set(DLL_EXT "so")
set(LIB_EXT "so")
set(OUT_DIR "${BUILD_DIR}/out")
endif()

add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND if not exist \"${DIST_DIR}/bin\" mkdir \"${DIST_DIR}/bin\")
add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND if not exist \"${DIST_DIR}/inc\" mkdir \"${DIST_DIR}/inc\")
add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND if not exist \"${DIST_DIR}/lib\" mkdir \"${DIST_DIR}/lib\")
add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND if not exist \"${OUT_DIR}\" mkdir \"${OUT_DIR}\")

add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND cp -f ${LIB_DIR}/SDL2.${DLL_EXT} ${OUT_DIR})
add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND cp -f ${LIB_DIR}/SDL2_image.${DLL_EXT} ${OUT_DIR})
add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND cp -f ${LIB_DIR}/SDL2_ttf.${DLL_EXT} ${OUT_DIR})
add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND cp -f ${LIB_DIR}/libxml2.${DLL_EXT} ${OUT_DIR})
if (WIN32)
set(TEST_EXE "testsdl2gui.exe")
else()
set(LIB_PREP "lib")
set(TEST_EXE "testsdl2gui")
endif()

add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND cp -f ${OUT_DIR}/*.${DLL_EXT} ${DIST_DIR}/bin/)
add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND cp -f ${SRC_DIR}/inc/libsdl2gui*.h ${DIST_DIR}/inc/)
add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND cp -f ${OUT_DIR}/libsdl2gui*.${LIB_EXT} ${DIST_DIR}/lib/)
add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND cp -f ${SRC_DIR}/LICENSE ${DIST_DIR}/LICENSE.txt)
add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND cp -f ${EXT_LIB_DIR}/LICENSE-sdl2.txt ${DIST_DIR}/)
add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND cp -f ${EXT_LIB_DIR}/LICENSE-sdl2_ttf.txt ${DIST_DIR}/)
add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND cp -f ${EXT_LIB_DIR}/LICENSE-sdl2_image.txt ${DIST_DIR}/)
add_custom_command(TARGET libsdl2gui POST_BUILD COMMAND cp -f ${EXT_LIB_DIR}/LICENSE-libxml2.txt ${DIST_DIR}/)
if (OS STREQUAL "_macosx")
add_custom_command(TARGET sdl2gui PRE_LINK COMMAND install_name_tool -id @rpath/libSDL2.dylib ${LIB_DIR}/libSDL2.dylib)
add_custom_command(TARGET sdl2gui PRE_LINK COMMAND install_name_tool -id @rpath/libSDL2_image.dylib ${LIB_DIR}/libSDL2_image.dylib)
add_custom_command(TARGET sdl2gui PRE_LINK COMMAND install_name_tool -id @rpath/libSDL2_ttf.dylib ${LIB_DIR}/libSDL2_ttf.dylib)
add_custom_command(TARGET sdl2gui PRE_LINK COMMAND install_name_tool -id @rpath/libxml2.dylib ${LIB_DIR}/libxml2.dylib)

add_custom_command(TARGET testsdl2gui POST_BUILD COMMAND cp -rf ../img ${OUT_DIR})
add_custom_command(TARGET testsdl2gui POST_BUILD COMMAND cp -rf ../ui ${OUT_DIR})
add_custom_command(TARGET sdl2gui PRE_LINK COMMAND install_name_tool -change @executable_path/../Frameworks/libSDL2.dylib @rpath/libSDL2.dylib ${LIB_DIR}/libSDL2_image.dylib)
add_custom_command(TARGET sdl2gui PRE_LINK COMMAND install_name_tool -change @executable_path/../Frameworks/libSDL2.dylib @rpath/libSDL2.dylib ${LIB_DIR}/libSDL2_ttf.dylib)
endif()

if (WIN32)
set_target_properties(testsdl2gui PROPERTIES LINK_FLAGS_DEBUG "-SUBSYSTEM:CONSOLE,5.02")
set_target_properties(testsdl2gui PROPERTIES LINK_FLAGS_RELEASE "-SUBSYSTEM:WINDOWS,5.02")
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND if not exist \"${DIST_DIR}/bin\" mkdir \"${DIST_DIR}/bin\")
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND if not exist \"${DIST_DIR}/inc\" mkdir \"${DIST_DIR}/inc\")
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND if not exist \"${DIST_DIR}/lib\" mkdir \"${DIST_DIR}/lib\")
else()
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND mkdir -p \"${DIST_DIR}/bin\")
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND mkdir -p \"${DIST_DIR}/inc\")
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND mkdir -p \"${DIST_DIR}/lib\")

add_custom_command(TARGET sdl2gui POST_BUILD COMMAND mkdir \"${OUT_DIR}\")
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${CFG_DIR}${LIB_PREP}sdl2gui* ${OUT_DIR}/)
endif()

add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${LIB_DIR}/${LIB_PREP}SDL2.${DLL_EXT} ${OUT_DIR}/)
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${LIB_DIR}/${LIB_PREP}SDL2_image.${DLL_EXT} ${OUT_DIR}/)
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${LIB_DIR}/${LIB_PREP}SDL2_ttf.${DLL_EXT} ${OUT_DIR}/)
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${LIB_DIR}/libxml2.${DLL_EXT} ${OUT_DIR}/)

add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${OUT_DIR}/*.${DLL_EXT} ${DIST_DIR}/bin/)
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${OUT_DIR}/*.${DLL_EXT} ${DIST_DIR}/lib/)
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${OUT_DIR}/*.${LIB_EXT} ${DIST_DIR}/lib/)
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${SRC_DIR}/inc/*.h ${DIST_DIR}/inc/)
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${SRC_DIR}/LICENSE ${DIST_DIR}/LICENSE.txt)
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${EXT_LIB_DIR}/LICENSE-sdl2.txt ${DIST_DIR}/)
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${EXT_LIB_DIR}/LICENSE-sdl2_ttf.txt ${DIST_DIR}/)
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${EXT_LIB_DIR}/LICENSE-sdl2_image.txt ${DIST_DIR}/)
add_custom_command(TARGET sdl2gui POST_BUILD COMMAND cp -f ${EXT_LIB_DIR}/LICENSE-libxml2.txt ${DIST_DIR}/)

add_custom_command(TARGET testsdl2gui POST_BUILD COMMAND cp -rf ../img ${OUT_DIR}/)
add_custom_command(TARGET testsdl2gui POST_BUILD COMMAND cp -rf ../ui ${OUT_DIR}/)

if (NOT WIN32)
add_custom_command(TARGET testsdl2gui POST_BUILD COMMAND cp -f ${CFG_DIR}${TEST_EXE} ${OUT_DIR}/)
endif()

add_custom_command(TARGET testsdl2gui POST_BUILD COMMAND cp -rf ${OUT_DIR}/img ${DIST_DIR}/bin/)
add_custom_command(TARGET testsdl2gui POST_BUILD COMMAND cp -rf ${OUT_DIR}/ui ${DIST_DIR}/bin/)
add_custom_command(TARGET testsdl2gui POST_BUILD COMMAND cp -f ${OUT_DIR}/${TEST_EXE} ${DIST_DIR}/bin/)

install(DIRECTORY ${DIST_DIR}/inc/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/libsdl2gui)
install(DIRECTORY ${DIST_DIR}/bin/ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin PATTERN ${TEST_EXE} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(DIRECTORY ${DIST_DIR}/lib/ DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
Loading

0 comments on commit 2be8d4d

Please sign in to comment.