Skip to content

Commit

Permalink
Various minor cleanups to oscar/
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Sep 16, 2024
1 parent c57db56 commit 2be9380
Show file tree
Hide file tree
Showing 22 changed files with 44 additions and 89 deletions.
2 changes: 1 addition & 1 deletion src/OpenSimCreator/UI/MeshWarper/MeshWarpingTabToolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class osc::MeshWarpingTabToolbar::Impl final {
// undo/redo-related stuff
m_UndoButton.on_draw();
ui::same_line();
m_RedoButton.onDraw();
m_RedoButton.on_draw();
ui::same_line();

ui::draw_vertical_separator();
Expand Down
6 changes: 3 additions & 3 deletions src/oscar/Maths/CoordinateAxis.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include <oscar/Utils/Assertions.h>

#include <cstdint>
#include <compare>
#include <optional>
Expand Down Expand Up @@ -48,7 +46,9 @@ namespace osc
explicit constexpr CoordinateAxis(int axis_index) :
axis_index_{static_cast<uint8_t>(axis_index)}
{
OSC_ASSERT(0 <= axis_index && axis_index <= 2 && "out-of-range index given to a CoordinateAxis");
if (not (0 <= axis_index && axis_index <= 2)) {
throw std::runtime_error{"out-of-range index given to a CoordinateAxis"};
}
}

// `CoordinateAxis`es are equality-comparable and totally ordered as X < Y < Z
Expand Down
1 change: 0 additions & 1 deletion src/oscar/Maths/MatFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <oscar/Maths/Qua.h>
#include <oscar/Maths/UnitVec3.h>
#include <oscar/Maths/Vec.h>
#include <oscar/Utils/Assertions.h>
#include <oscar/Utils/HashHelpers.h>

#include <concepts>
Expand Down
4 changes: 1 addition & 3 deletions src/oscar/Maths/MathsImplementation.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include <oscar/Maths.h>
#include <oscar/Platform/Log.h>
#include <oscar/Utils/Algorithms.h>

#include <oscar/Utils/Assertions.h>
#include <oscar/Utils/EnumHelpers.h>

#include <cmath>
#include <algorithm>
Expand Down
2 changes: 1 addition & 1 deletion src/oscar/Maths/Scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ namespace osc
concept Scalar = IsScalarV<T>;

template<typename T>
concept ScalarOrBoolean = Scalar<T> || std::same_as<bool, T>;
concept ScalarOrBoolean = Scalar<T> or std::same_as<bool, T>;
}
1 change: 0 additions & 1 deletion src/oscar/Maths/Tetrahedron.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <oscar/Maths/Vec3.h>

#include <array>
#include <cstddef>

namespace osc
Expand Down
10 changes: 0 additions & 10 deletions src/oscar/Maths/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include <oscar/Maths/Vec3.h>

#include <ostream>
#include <sstream>
#include <string>
#include <utility>

namespace osc
{
Expand Down Expand Up @@ -62,11 +59,4 @@ namespace osc
{
return out << "Transform(position = " << transform.position << ", rotation = " << transform.rotation << ", scale = " << transform.scale << ')';
}

inline std::string to_string(const Transform& transform)
{
std::stringstream ss;
ss << transform;
return std::move(ss).str();
}
}
11 changes: 0 additions & 11 deletions src/oscar/Maths/Vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
#include <cstddef>
#include <functional>
#include <ostream>
#include <sstream>
#include <string>
#include <string_view>
#include <utility>

namespace osc
{
Expand All @@ -30,14 +27,6 @@ namespace osc
return out;
}

template<size_t L, Scalar T>
std::string to_string(const Vec<L, T>& vec)
{
std::stringstream ss;
ss << vec;
return std::move(ss).str();
}

// when handled as a tuple-like object, a `Vec` decomposes into its elements

template<size_t I, size_t L, Scalar T>
Expand Down
6 changes: 2 additions & 4 deletions src/oscar/Platform/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ namespace osc
RightShift = 1<<1,
LeftCtrl = 1<<2,
RightCtrl = 1<<3,
// Windows key / MacOS command key / Ubuntu Key, etc.
LeftGui = 1<<4,
// Windows key / MacOS command key / Ubuntu Key, etc.
RightGui = 1<<5,
LeftGui = 1<<4, // Windows key / MacOS command key / Ubuntu Key, etc.
RightGui = 1<<5, // Windows key / MacOS command key / Ubuntu Key, etc.
LeftAlt = 1<<6,
RightAlt = 1<<7,
NUM_FLAGS = 8,
Expand Down
19 changes: 9 additions & 10 deletions src/oscar/UI/Screens/TabTestingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,34 @@ class osc::TabTestingScreen::Impl final :
{}

private:
void impl_on_mount() override
void impl_on_mount() final
{
current_tab_ = registry_entry_.construct_tab(ParentPtr<Impl>{shared_from_this()});
ui::context::init();
current_tab_->on_mount();
App::upd().make_main_loop_polling();
}

void impl_on_unmount() override
void impl_on_unmount() final
{
App::upd().make_main_loop_waiting();
current_tab_->on_unmount();
ui::context::shutdown();
}

bool impl_on_event(const Event& e) override
bool impl_on_event(const Event& e) final
{
bool handled = ui::context::on_event(e);
handled = current_tab_->on_event(e) || handled;
handled = current_tab_->on_event(e) or handled;
return handled;
}

void impl_on_tick() override
void impl_on_tick() final
{
current_tab_->on_tick();
}

void impl_on_draw() override
void impl_on_draw() final
{
App::upd().clear_screen();
ui::context::on_start_new_frame();
Expand All @@ -66,10 +66,9 @@ class osc::TabTestingScreen::Impl final :
}
}

UID impl_add_tab(std::unique_ptr<ITab>) override { return UID{}; }
void impl_select_tab(UID) override {}
void impl_close_tab(UID) override {}
void impl_reset_imgui() override {}
UID impl_add_tab(std::unique_ptr<ITab>) final { return UID{}; }
void impl_select_tab(UID) final {}
void impl_close_tab(UID) final {}

TabRegistryEntry registry_entry_;
std::unique_ptr<ITab> current_tab_;
Expand Down
10 changes: 5 additions & 5 deletions src/oscar/UI/Screens/TabTestingScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace osc
TabTestingScreen& operator=(TabTestingScreen&&) noexcept = default;
~TabTestingScreen() noexcept override = default;
private:
void impl_on_mount() override;
void impl_on_unmount() override;
bool impl_on_event(const Event&) override;
void impl_on_tick() override;
void impl_on_draw() override;
void impl_on_mount() final;
void impl_on_unmount() final;
bool impl_on_event(const Event&) final;
void impl_on_tick() final;
void impl_on_draw() final;

class Impl;
std::shared_ptr<Impl> impl_;
Expand Down
23 changes: 4 additions & 19 deletions src/oscar/UI/Tabs/ITabHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,10 @@ namespace osc
return add_tab(std::make_unique<T>(std::forward<Args>(args)...));
}

UID add_tab(std::unique_ptr<ITab> tab)
{
return impl_add_tab(std::move(tab));
}

void select_tab(UID tab_id)
{
impl_select_tab(tab_id);
}

void close_tab(UID tab_id)
{
impl_close_tab(tab_id);
}

void reset_imgui()
{
impl_reset_imgui();
}
UID add_tab(std::unique_ptr<ITab> tab) { return impl_add_tab(std::move(tab)); }
void select_tab(UID tab_id) { impl_select_tab(tab_id); }
void close_tab(UID tab_id) { impl_close_tab(tab_id); }
void reset_imgui() { impl_reset_imgui(); }

template<std::derived_from<ITab> T, typename... Args>
requires std::constructible_from<T, Args&&...>
Expand Down
4 changes: 2 additions & 2 deletions src/oscar/UI/Tabs/ScreenshotTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ using namespace osc;

namespace
{
constexpr Color c_unselected_color = {1.0f, 1.0f, 1.0f, 0.4f};
constexpr Color c_selected_color = {1.0f, 0.0f, 0.0f, 0.8f};
constexpr Color c_unselected_color = Color::white().with_alpha(0.4f);
constexpr Color c_selected_color = Color::red().with_alpha(0.8f);

// returns a rect that fully spans at least one dimension of the target rect, but has
// the given aspect ratio
Expand Down
2 changes: 1 addition & 1 deletion src/oscar/UI/Widgets/RedoButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ osc::RedoButton::RedoButton(std::shared_ptr<UndoRedoBase> undo_redo) :

osc::RedoButton::~RedoButton() noexcept = default;

void osc::RedoButton::onDraw()
void osc::RedoButton::on_draw()
{
int ui_id = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/oscar/UI/Widgets/RedoButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace osc
RedoButton& operator=(RedoButton&&) noexcept = default;
~RedoButton() noexcept;

void onDraw();
void on_draw();
private:
std::shared_ptr<UndoRedoBase> undo_redo_;
};
Expand Down
3 changes: 1 addition & 2 deletions src/oscar/UI/Widgets/StandardPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ bool osc::StandardPopup::impl_begin_popup()
return false;
}
}
else
{
else {
// if specified, set the position of the modal upon appearing
//
// else, do nothing - the popup's position will be determined
Expand Down
1 change: 0 additions & 1 deletion src/oscar/UI/ui_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <oscar/Utils/Algorithms.h>
#include <oscar/Utils/Perf.h>

#define IMGUI_USER_CONFIG <oscar/UI/oscimgui_config.h> // NOLINT(bugprone-macro-parentheses)
#include <imgui.h>
#include <ImGuizmo.h>
#include <implot.h>
Expand Down
5 changes: 0 additions & 5 deletions src/oscar/Utils/Concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ namespace osc
{*ptr} -> std::convertible_to<DerefType>;
};

template<typename T>
concept Hashable = requires(T v) {
{ std::hash<T>{}(v) } -> std::convertible_to<size_t>;
};

template<typename T>
concept NamedInputStream = requires(T v) {
{ v } -> std::convertible_to<std::istream&>;
Expand Down
8 changes: 6 additions & 2 deletions src/oscar/Utils/HashHelpers.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#pragma once

#include <oscar/Utils/Concepts.h>

#include <concepts>
#include <cstddef>
#include <functional>
#include <ranges>
#include <utility>

namespace osc
{
template<typename T>
concept Hashable = requires(T v) {
{ std::hash<T>{}(v) } -> std::convertible_to<size_t>;
};

// combines hash of `T` into the seed value
template<Hashable T>
size_t hash_combine(size_t seed, const T& v)
Expand Down
4 changes: 2 additions & 2 deletions src/oscar/Variant/Variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ osc::Variant::operator std::string() const
[](const float& v) { return std::to_string(v); },
[](const int& v) { return std::to_string(v); },
[](std::string_view s) { return std::string{s}; },
[](const Vec2& v) { return to_string(v); },
[](const Vec3& v) { return to_string(v); },
[](const Vec2& v) { return stream_to_string(v); },
[](const Vec3& v) { return stream_to_string(v); },
}, data_);
}

Expand Down
5 changes: 3 additions & 2 deletions src/oscar_simbody/UI/TPS2DTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <oscar/Utils/Algorithms.h>
#include <oscar/Utils/Assertions.h>
#include <oscar/Utils/StdVariantHelpers.h>
#include <oscar/Utils/StringHelpers.h>
#include <Simbody.h>

#include <cmath>
Expand Down Expand Up @@ -472,7 +473,7 @@ class osc::TPS2DTab::Impl final {
const Vec2 mouseImageRelPos = mouseImagePos / dimensions_of(ht.item_screen_rect);
const Vec2 mouseImageNDCPos = topleft_relative_pos_to_ndc_point(mouseImageRelPos);

ui::draw_tooltip_body_only(to_string(mouseImageNDCPos));
ui::draw_tooltip_body_only(stream_to_string(mouseImageNDCPos));

if (ui::is_mouse_clicked(ui::MouseButton::Left))
{
Expand All @@ -488,7 +489,7 @@ class osc::TPS2DTab::Impl final {
const Vec2 mouseImageRelPos = mouseImagePos / dimensions_of(ht.item_screen_rect);
const Vec2 mouseImageNDCPos = topleft_relative_pos_to_ndc_point(mouseImageRelPos);

ui::draw_tooltip_body_only(to_string(mouseImageNDCPos) + "*");
ui::draw_tooltip_body_only(stream_to_string(mouseImageNDCPos) + "*");

if (ui::is_mouse_clicked(ui::MouseButton::Left))
{
Expand Down
4 changes: 2 additions & 2 deletions tests/testoscar/Variant/TestVariant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ TEST(Variant, Vec2ValueToStringReturnsSameAsDirectlyConvertingVectorToString)
});

for (const auto& testCase : testCases) {
ASSERT_EQ(to<std::string>(Variant{testCase}), to_string(testCase));
ASSERT_EQ(to<std::string>(Variant{testCase}), stream_to_string(testCase));
}
}

Expand Down Expand Up @@ -788,7 +788,7 @@ TEST(Variant, Vec3ValueToStringReturnsSameAsDirectlyConvertingVectorToString)
});

for (const auto& testCase : testCases) {
ASSERT_EQ(to<std::string>(Variant{testCase}), to_string(testCase));
ASSERT_EQ(to<std::string>(Variant{testCase}), stream_to_string(testCase));
}
}

Expand Down

0 comments on commit 2be9380

Please sign in to comment.