Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions inc/cvc/ariadne/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ struct Track {
};

enum class LayoutKind { Vertical, Horizontal, Grid };
enum class BorderShow { None, Inner, Outer, All };
// `Off`, not `None`: X11 <X11/X.h> defines `None` as a macro, which would break this
// declaration in any translation unit that includes an X11 header first.
enum class BorderShow { Off, Inner, Outer, All };

// A container's layout (§3.0.2 / §3.0.3b). `col_widths` sizes the tracks of a
// Grid/Horizontal layout; `resizable` lets the user drag the column seams (native
Expand All @@ -90,12 +92,12 @@ struct Layout {
std::vector<Track> col_widths; // Grid/Horizontal column tracks
std::vector<Track> row_heights; // Grid row tracks (§3.0.3b increment 2)
bool resizable = false;
BorderShow borders = BorderShow::None;
BorderShow borders = BorderShow::Off;
bool has_border_color = false;
float border_color[4] = {0.3f, 0.3f, 0.35f, 1.0f};
bool is_set() const {
return kind != LayoutKind::Vertical || !col_widths.empty() || !row_heights.empty() ||
resizable || borders != BorderShow::None;
resizable || borders != BorderShow::Off;
}
// A resizable grid with sized rows is realized as a vertical split-pane stack
// with draggable seams (§3.0.3b: "rows are a manual splitter"); anything else
Expand Down
5 changes: 3 additions & 2 deletions inc/cvc/gl/nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ class VisibilityMask : public Node {
std::uint32_t m_mask = 0xFFFFFFFFu;
};

// Inventor's SoSwitch: traverse one child, or none (-1), or all (-3).
// Inventor's SoSwitch: traverse one child, or none (Off, -1), or all (All, -3). `Off`, not
// `None`: X11 <X11/X.h> defines `None` as a macro.
class Switch : public Group {
public:
static constexpr int None = -1;
static constexpr int Off = -1;
static constexpr int All = -3;

using Group::Group;
Expand Down
2 changes: 1 addition & 1 deletion src/cvc/ariadne/ftxui_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void FtxuiBackend::end_grid() {
fx::Element box = cells.empty()
? fx::text("")
: (vertical ? fx::vbox(std::move(cells)) : fx::hbox(std::move(cells)));
if (layout.borders != BorderShow::None)
if (layout.borders != BorderShow::Off)
box = fx::border(box);
m_->add(box);
}
Expand Down
10 changes: 10 additions & 0 deletions src/cvc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_executable(text_test text_test.cpp)
add_executable(ariadne_loader_test ariadne_loader_test.cpp)
add_executable(ariadne_runtime_test ariadne_runtime_test.cpp)
add_executable(ariadne_bind_test ariadne_bind_test.cpp)
add_executable(x11_macro_headers_test x11_macro_headers_test.cpp)
add_executable(net_http_client_test net_http_client_test.cpp)
add_executable(uri_http_cache_test uri_http_cache_test.cpp)
add_executable(state_test state_test.cpp)
Expand Down Expand Up @@ -176,6 +177,7 @@ set(TEST_TARGETS
ariadne_loader_test
ariadne_runtime_test
ariadne_bind_test
x11_macro_headers_test
net_http_client_test
uri_http_cache_test
state_test
Expand Down Expand Up @@ -442,6 +444,13 @@ target_link_libraries(ariadne_bind_test
GTest::gtest_main
)

target_link_libraries(x11_macro_headers_test
PRIVATE
cvc
GTest::gtest
GTest::gtest_main
)

target_link_libraries(state_test
PRIVATE
cvc
Expand Down Expand Up @@ -1647,6 +1656,7 @@ cvc_discover_tests(text_test)
cvc_discover_tests(ariadne_loader_test)
cvc_discover_tests(ariadne_runtime_test)
cvc_discover_tests(ariadne_bind_test)
cvc_discover_tests(x11_macro_headers_test)
cvc_discover_tests(net_http_client_test)
cvc_discover_tests(uri_http_cache_test)
cvc_discover_tests(state_test)
Expand Down
23 changes: 23 additions & 0 deletions src/cvc/tests/x11_macro_headers_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// X11's <X11/X.h> defines object-like macros named like ordinary identifiers -- notably
// `None` (0L) -- so a public header that declares anything called `None` stops compiling
// in a translation unit that includes an X11 header first. This TU includes <X11/X.h>
// FIRST (where X11 is available) and then the ariadne widget header, whose BorderShow enum
// used to have a `None` enumerator. Platforms without X11 build it without the macro.
//
// gtest comes BEFORE X11: googletest itself declares `struct None` (gtest-type-util.h), so
// the macro would break gtest, not just libcvc. This test is about libcvc's headers.
#include <gtest/gtest.h>

#if __has_include(<X11/X.h>)
#include <X11/X.h>
#endif

#include <cvc/ariadne/widget.h>

TEST(X11MacroHeaders, BorderShowDefaultsToOff) {
#ifdef None
static_assert(None == 0L, "X11's None macro is in effect for this translation unit");
#endif
cvc::ariadne::Layout layout;
EXPECT_EQ(layout.borders, cvc::ariadne::BorderShow::Off);
}
8 changes: 7 additions & 1 deletion src/cvcGL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ add_executable(cvcgl_traversal test/cvcgl_traversal.cpp)
target_link_libraries(cvcgl_traversal PRIVATE cvcGL)
add_test(NAME cvcgl_traversal COMMAND cvcgl_traversal)

# X11 <X11/X.h> macros (None, Success, ...) vs the cvc/gl headers, in the order VTK's X11
# render window produces (VTK first, then X11, then cvc/gl). Compile-time check; headless.
add_executable(cvcgl_x11_macros test/cvcgl_x11_macros.cpp)
target_link_libraries(cvcgl_x11_macros PRIVATE cvcGL)
add_test(NAME cvcgl_x11_macros COMMAND cvcgl_x11_macros)

# The world grid must enclose the geometry actually in the scene. It was sized
# only from GraphicsNode::transformChanged, so it tracked geometry that MOVED
# and ignored geometry that was merely ADDED — every static scene drew a
Expand Down Expand Up @@ -899,7 +905,7 @@ endif()
# locked unless it is listed here as headless.
get_property(_cvcgl_gl_tests DIRECTORY PROPERTY TESTS)
list(REMOVE_ITEM _cvcgl_gl_tests
cvcgl_smoke cvcgl_metadata_mirror cvcgl_volume_range cvcgl_traversal
cvcgl_smoke cvcgl_metadata_mirror cvcgl_volume_range cvcgl_traversal cvcgl_x11_macros
cvcgl_grid_bounds cvcgl_bounds_walk cvcgl_scene_chrome cvcgl_remove
cvcgl_teardown cvcgl_light_state_thread cvcgl_pose_echo
cvcgl_node_outlives_scene cvcgl_texture cvcgl_texture_zerocopy
Expand Down
2 changes: 1 addition & 1 deletion src/cvcGL/nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void Separator::traverse(Action &action) {

// ── Switch ─────────────────────────────────────────────────────────────────
void Switch::traverse(Action &action) {
if (m_which == None)
if (m_which == Off)
return;
if (m_which == All) {
traverseChildren(action);
Expand Down
2 changes: 1 addition & 1 deletion src/cvcGL/test/cvcgl_traversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static void test_switch() {
return a.visitedShapes();
};
CHECK(count(Switch::All) == 2);
CHECK(count(Switch::None) == 0);
CHECK(count(Switch::Off) == 0);
CHECK(count(0) == 1);
CHECK(count(1) == 1);
CHECK(count(99) == 0); // out of range is not a crash
Expand Down
24 changes: 24 additions & 0 deletions src/cvcGL/test/cvcgl_x11_macros.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// cvcGL apps on Linux pull X11 in through VTK's X11 render window, which includes
// <X11/Xlib.h> after VTK's own headers -- so cvc/gl headers can be parsed with X11's
// object-like macros (None, Success, ...) already defined. Mirror that order: VTK headers
// first (X11 before them breaks VTK's own vtksys/Status.hxx on `Success`), then X11, then
// the cvc/gl header. Switch's "no child" constant used to be named `None`.
#include <vtkMatrix4x4.h>
#include <vtkSmartPointer.h>

#if __has_include(<X11/X.h>)
#include <X11/X.h>
#endif

#include <cstdio>
#include <cvc/gl/nodes.h>

int main() {
#ifdef None
static_assert(None == 0L, "X11's None macro is in effect for this translation unit");
#endif
static_assert(cvc::gl::Switch::Off == -1, "Switch::Off traverses no child");
static_assert(cvc::gl::Switch::All == -3, "Switch::All traverses every child");
std::puts("cvcgl_x11_macros: ok");
return 0;
}
Loading