Skip to content
Draft
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
7 changes: 1 addition & 6 deletions Core/Source/Lux/Core/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,8 @@ namespace Lux {

if (!m_Specification.Decorated)
{
// This removes titlebar on all platforms
// and all of the native window effects on non-Windows platforms
#ifdef LUX_PLATFORM_WINDOWS
glfwWindowHint(GLFW_TITLEBAR, false);
#else
// Disable native decorations so editor can render a fully custom titlebar.
glfwWindowHint(GLFW_DECORATED, false);
#endif
}

m_WindowHandle = glfwCreateWindow((int)m_Specification.Width, (int)m_Specification.Height, m_Data.Title.c_str(), m_Specification.Fullscreen ? glfwGetPrimaryMonitor() : nullptr, nullptr);
Expand Down
11 changes: 6 additions & 5 deletions Core/Source/Lux/ImGui/ImGuiEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Lux/ImGui/ImGuiWidgets.h"
//#include "Lux/Scene/Prefab.h"
#include "Lux/Scene/Scene.h"
#include "Lux/UI/UI.h"
#include "Lux/Utilities/StringUtils.h"

#include <choc/text/choc_StringUtilities.h>
Expand Down Expand Up @@ -2802,7 +2803,7 @@ namespace Lux::ImGuiEx {
uintptr_t tempLength = length;
FieldType nativeType = arrayStorage->GetFieldInfo()->Type;

if (UI::PropertyInput("Length", tempLength, 1, 1, ImGuiInputTextFlags_EnterReturnsTrue))
if (PropertyInput("Length", tempLength, 1, 1, ImGuiInputTextFlags_EnterReturnsTrue))
{
arrayStorage->Resize((uint32_t)tempLength);
length = tempLength;
Expand All @@ -2827,12 +2828,12 @@ namespace Lux::ImGuiEx {
size_t dataSize = ImGui::DataTypeGetInfo(dataType)->Size;
if (components > 1)
{
if (UI::DragScalarN(GenerateID(), dataType, &data, components, 1.0f, (const void*)0, (const void*)0, format, 0))
if (DragScalarN(GenerateID(), dataType, &data, components, 1.0f, (const void*)0, (const void*)0, format, 0))
arrayStorage->SetValue<std::remove_reference_t<decltype(data)>>((uint32_t)index, data);
}
else
{
if (UI::DragScalar(GenerateID(), dataType, &data, 1.0f, (const void*)0, (const void*)0, format, (ImGuiSliderFlags)0))
if (DragScalar(GenerateID(), dataType, &data, 1.0f, (const void*)0, (const void*)0, format, (ImGuiSliderFlags)0))
arrayStorage->SetValue<std::remove_reference_t<decltype(data)>>((uint32_t)index, data);
}

Expand Down Expand Up @@ -2863,7 +2864,7 @@ namespace Lux::ImGuiEx {
const float buttonSize = ImGui::GetFrameHeight();
ImGui::SetNextItemWidth(ImMax(1.0f, ImGui::CalcItemWidth() - (buttonSize + style.ItemInnerSpacing.x)));

if (UI::InputText(GenerateID(), &data))
if (InputText(GenerateID(), &data))
arrayStorage->SetValue<std::string>((uint32_t)index, data);

const ImVec2 backupFramePadding = style.FramePadding;
Expand Down Expand Up @@ -2892,7 +2893,7 @@ namespace Lux::ImGuiEx {
case FieldType::Bool:
{
bool value = arrayStorage->GetValue<bool>(i);
if (UI::Property(indexString.c_str(), value))
if (Property(indexString.c_str(), value))
{
arrayStorage->SetValue(i, value);
modified = true;
Expand Down
124 changes: 117 additions & 7 deletions Core/Source/Lux/UI/UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,144 @@

#include <imgui/imgui.h>

#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <imgui/imgui_internal.h>

#include "Lux/ImGui/Colors.h"
#include "Lux/ImGui/ImGuiUtilities.h"

namespace Lux::UI {

struct ScopedStyleColor
// =========================================================================
// Scoped helpers — mirrors the Hazel UI:: namespace conventions
// =========================================================================

/// RAII wrapper for ImGui::PushStyleColor / PopStyleColor
struct ScopedColour
{
ScopedStyleColor() = default;
ScopedColour() = default;

ScopedColour(ImGuiCol idx, ImVec4 colour, bool predicate = true)
: m_Set(predicate)
{
if (predicate)
ImGui::PushStyleColor(idx, colour);
}

ScopedStyleColor(ImGuiCol idx, ImVec4 color, bool predicate = true)
ScopedColour(ImGuiCol idx, ImU32 colour, bool predicate = true)
: m_Set(predicate)
{
if (predicate)
ImGui::PushStyleColor(idx, color);
ImGui::PushStyleColor(idx, colour);
}

ScopedStyleColor(ImGuiCol idx, ImU32 color, bool predicate = true)
ScopedColour(ImGuiCol idx, ImColor colour, bool predicate = true)
: m_Set(predicate)
{
if (predicate)
ImGui::PushStyleColor(idx, color);
ImGui::PushStyleColor(idx, colour.Value);
}

~ScopedStyleColor()
~ScopedColour()
{
if (m_Set)
ImGui::PopStyleColor();
}

ScopedColour(const ScopedColour&) = delete;
ScopedColour& operator=(const ScopedColour&) = delete;
private:
bool m_Set = false;
};

// Legacy alias kept for backwards compatibility
using ScopedStyleColor = ScopedColour;

/// RAII wrapper for ImGui::PushStyleVar / PopStyleVar
struct ScopedStyle
{
ScopedStyle(ImGuiStyleVar styleVar, float value) { ImGui::PushStyleVar(styleVar, value); }
ScopedStyle(ImGuiStyleVar styleVar, ImVec2 value) { ImGui::PushStyleVar(styleVar, value); }
~ScopedStyle() { ImGui::PopStyleVar(); }

ScopedStyle(const ScopedStyle&) = delete;
ScopedStyle& operator=(const ScopedStyle&) = delete;
};

/// RAII wrapper for ImGui::PushFont / PopFont
struct ScopedFont
{
ScopedFont(ImFont* font) { ImGui::PushFont(font); }
~ScopedFont() { ImGui::PopFont(); }

ScopedFont(const ScopedFont&) = delete;
ScopedFont& operator=(const ScopedFont&) = delete;
};

// =========================================================================
// Cursor helpers
// =========================================================================

/// Shift the cursor position along the X axis by the given amount
inline void ShiftCursorX(float distance)
{
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + distance);
}

/// Shift the cursor position along the Y axis by the given amount
inline void ShiftCursorY(float distance)
{
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + distance);
}

/// Shift the cursor position along both axes
inline void ShiftCursor(float x, float y)
{
const ImVec2 cursor = ImGui::GetCursorPos();
ImGui::SetCursorPos(ImVec2(cursor.x + x, cursor.y + y));
}

// =========================================================================
// DrawButtonImage — draws a texture directly into an already-placed item
// rect, choosing the tint based on the item interaction state.
// =========================================================================

/// Draw a button image using separate textures for each interaction state.
/// Call this *after* an invisible button or any other item that occupies the
/// desired rect, then the tint colour is picked automatically.
inline void DrawButtonImage(
const Ref<Texture2D>& imageNormal,
const Ref<Texture2D>& imageHovered,
const Ref<Texture2D>& imagePressed,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
ImVec2 rectMin, ImVec2 rectMax,
ImVec2 uv0 = ImVec2(0.0f, 0.0f), ImVec2 uv1 = ImVec2(1.0f, 1.0f))
{
// Delegate to ImGuiEx which has the full implementation
ImGuiEx::DrawButtonImage(imageNormal, imageHovered, imagePressed,
tintNormal, tintHovered, tintPressed, rectMin, rectMax, uv0, uv1);
}

/// Convenience overload — single texture for all states
inline void DrawButtonImage(
const Ref<Texture2D>& image,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
ImVec2 rectMin, ImVec2 rectMax,
ImVec2 uv0 = ImVec2(0.0f, 0.0f), ImVec2 uv1 = ImVec2(1.0f, 1.0f))
{
ImGuiEx::DrawButtonImage(image, tintNormal, tintHovered, tintPressed,
rectMin, rectMax, uv0, uv1);
}

/// Convenience overload — uses the last item rect for the image bounds
inline void DrawButtonImage(
const Ref<Texture2D>& image,
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
ImVec2 uv0 = ImVec2(0.0f, 0.0f), ImVec2 uv1 = ImVec2(1.0f, 1.0f))
{
ImGuiEx::DrawButtonImage(image, tintNormal, tintHovered, tintPressed, uv0, uv1);
}

}
Loading