Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
913eb0b
OptiRender: fix optimization failed issue
GADDQ Apr 27, 2026
d1c7457
Window: reabstract interface
GADDQ Apr 27, 2026
888f417
add some docs
GADDQ Apr 27, 2026
7f62b26
add some docs
GADDQ Apr 27, 2026
dfcd53c
OptiRender: force redraw when components/layers update
GADDQ Apr 27, 2026
e65f9cf
add some docs
GADDQ Apr 27, 2026
e1d8e87
Component: Layer render test
GADDQ Apr 27, 2026
8ca5d05
Window: fix PopStyle logic
GADDQ Apr 27, 2026
b0ca0fb
Component: Layer test
GADDQ Apr 27, 2026
aa40831
Component: Layer test
GADDQ Apr 27, 2026
31c891b
MD3: first buggy implement test
GADDQ Apr 28, 2026
e312acd
fix build issue on linux/macos
GADDQ May 1, 2026
4e20248
fix render issue on linux/macos
GADDQ May 1, 2026
8c0dd4a
fix animation stop playing when mouse didn't hover the window
GADDQ May 6, 2026
527dd1b
fix namespace issue
GADDQ May 6, 2026
30d7663
fix a possible segmentation fault
GADDQ May 6, 2026
aaa6c8c
fix incorrect parent relationship when removeComponent
GADDQ May 6, 2026
e06332c
add const keyword
GADDQ May 6, 2026
da25c2f
why cout will cause issue?
GADDQ May 6, 2026
9c558c9
remove unused headers
GADDQ May 7, 2026
81b9381
replace imgui timer to glfw timer
GADDQ May 7, 2026
58d4d47
fix high cpu/gpu usage
GADDQ May 7, 2026
9bd92cc
change name
GADDQ May 7, 2026
0c9b1b9
change name
GADDQ May 7, 2026
65b3e39
add some docs
GADDQ May 7, 2026
878e2f2
Merge remote-tracking branch 'origin/animation' into animation
GADDQ May 7, 2026
851c28d
update docs
GADDQ May 7, 2026
cf8bc3a
update docs
GADDQ May 8, 2026
518978c
update docs, rebuild IEvent
GADDQ May 9, 2026
cb40d4e
update docs
GADDQ May 9, 2026
b8bbd4e
update docs, expand Animation System, fix serious lag issue
GADDQ May 14, 2026
9487457
update docs, expand Animation System, fix serious lag issue
GADDQ May 14, 2026
d076355
update docs, expand Animation System, fix serious lag issue
GADDQ May 14, 2026
63f3a3a
Merge remote-tracking branch 'origin/animation' into animation
GADDQ May 14, 2026
38c80c8
update docs, expand Animation System, fix serious lag issue
GADDQ May 14, 2026
05c5ed1
update docs, expand Animation System, fix serious lag issue
GADDQ May 14, 2026
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: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ Design your own components however you wish using OpenGL 3.3 Core and ImGui APIs
## Hybrid Mode
Neither Immediate Mode nor Retained Mode—but ***both***. CMaterial leverages Retained Mode at the **UI Layer** for the structural integrity of a mature framework, while empowering the **Component Layer** with Immediate Mode for unrestricted control over how every pixel is rendered.

## Pure Upper-Layer Construction
All of CMaterial's functionality is implemented entirely at the upper layer, **without modifying a single line of code from dependent libraries**. In most cases, you can update the dependent libraries on your own, enjoying all upstream updates **without spending time re-porting the framework**.

---

## Libraries
- **[GLFW](https://github.com/glfw/glfw)** : A lightweight, cross-platform API for creating windows, contexts, handling input and events.
- **[GLAD](https://github.com/dav1dde/glad)** : A multi-Language Vulkan/GL/GLES/EGL/GLX/WGL loader-generator based on the official specifications.
- **[ImGui](https://github.com/ocornut/imgui)** : A bloat-free Graphical User interface for C++ with minimal dependencies.
- **[GLAD](https://github.com/dav1dde/glad)** : A multi-Language Vulkan/GL/GLES/EGL/GLX/WGL loader-generator based on the official specifications.
- **[GLFW](https://github.com/glfw/glfw)** : A lightweight, cross-platform API for creating windows, contexts, handling input and events.
- **[tweeny](https://github.com/mobius3/tweeny)** : An inbetweening library designed for the creation of complex animations and beautiful interactive software.
- **[stb_image](https://github.com/nothings/stb)** : A highly renowned single-file public domain library for loading images in C/C++.
- **[mimalloc](https://github.com/microsoft/mimalloc)** : A compact general purpose allocator with excellent performance.
Expand Down
7 changes: 5 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
## 混合模式
不是即时模式,也不是保留模式——因为它***全都是***。CMaterial 允许你在 **UI 层** 使用保留模式,就像任何一个成熟的 GUI 框架那样,而同时在 **组件层** 使用即时模式,尽情的定义组件如何进行绘制。

## 纯上层构建
CMaterial 的所有功能实现全部处于上层,**没有更改任何一行来自依赖库的代码**。多数情况下,你可以自行更新依赖库,享受来自上游的全部更新,而**无需花费时间重新移植框架**。

---

## 依赖库
- **[GLFW](https://github.com/glfw/glfw)** : 一个轻量级、跨平台的 API,用于创建窗口、上下文、读取输入及处理事件。
- **[GLAD](https://github.com/dav1dde/glad)** : 基于官方规范的多语言 Vulkan/GL/GLES/EGL/GLX/WGL 加载器生成工具。
- **[ImGui](https://github.com/ocornut/imgui)** : 一个依赖极简、无冗余的 C++ 图形用户界面。
- **[GLAD](https://github.com/dav1dde/glad)** : 基于官方规范的多语言 Vulkan/GL/GLES/EGL/GLX/WGL 加载器生成工具。
- **[GLFW](https://github.com/glfw/glfw)** : 一个轻量级、跨平台的 API,用于创建窗口、上下文、读取输入及处理事件。
- **[tweeny](https://github.com/mobius3/tweeny)** : 一个专为游戏和其他精美交互式软件打造的复杂补间动画库。
- **[stb_image](https://github.com/nothings/stb)** : C/C++ 领域极具盛名的单头文件公共域图像加载库。
- **[mimalloc](https://github.com/microsoft/mimalloc)** : 一款性能卓越、体积精简的通用内存分配器。
Expand Down
26 changes: 26 additions & 0 deletions src/content/animation/material/HoverAnimation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Created by Earth_Studio on 2026/5/13.
//

#ifndef CMATERIAL_HOVERANIMATION_H
#define CMATERIAL_HOVERANIMATION_H
#include <engine/animation/IAnimation.h>
#include "tweeny.h"

namespace cmaterial::component::material::animation {
class HoverAnimation : public cmaterial::animation::IAnimation {
public:
HoverAnimation(double* alpha, double target, INode* parent) : IAnimation(parent) {
// 150ms = 15000 steps
bind(alpha, new tweeny::tween<double>(tweeny::from(*alpha).to(target).during(15000)));
}
~HoverAnimation() override {
for (auto& pair : animationBinders) delete pair.second;
animationBinders.clear();
}
};
}



#endif //CMATERIAL_HOVERANIMATION_H
32 changes: 32 additions & 0 deletions src/content/animation/material/RippleAnimation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Created by Earth_Studio on 2026/5/13.
//

#ifndef CMATERIAL_RIPPLEANIMATION_H
#define CMATERIAL_RIPPLEANIMATION_H
#include "engine/animation/IAnimation.h"
#include "tweeny.h"


namespace cmaterial::component::material::animation {
class RippleAnimation : public cmaterial::animation::IAnimation {
public:
RippleAnimation(double* progress, double* alpha, INode* node) : IAnimation(node) {
progressTween = tweeny::from(0.0).to(1.0).during(40000).via(tweeny::easing::quadraticOut);
alphaTween = tweeny::from(0.12).to(0.0).during(40000).via(tweeny::easing::quadraticOut);

bind(progress, &progressTween);
bind(alpha, &alphaTween);
}
~RippleAnimation() override {
animationBinders.clear();
}

private:
tweeny::tween<double> progressTween;
tweeny::tween<double> alphaTween;
};
}


#endif //CMATERIAL_RIPPLEANIMATION_H
2 changes: 1 addition & 1 deletion src/content/component/BasicButton/BasicButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "BasicButton.h"

void cmaterial::component::BasicButton::render(ImGuiIO *io) {
void cmaterial::component::BasicButton::update(ImGuiIO *io) {
if (ImGui::Button(name.c_str()))
onActive();
}
2 changes: 1 addition & 1 deletion src/content/component/BasicButton/BasicButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace cmaterial::component {
BasicButton() = default;
~BasicButton() = default;

void render(ImGuiIO *io) override;
void update(ImGuiIO *io) override;
void (*onActive)() =[]() {};
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/content/component/CreatorButton/CreatorButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace cmaterial::component {
public:
using IComponent::IComponent;

void render(ImGuiIO *io) override {
void update(ImGuiIO *io) override {
if (ImGui::Button("SpawnWindow")) {
static int count = 0;
auto* req = new event::SpawnWindowRequest();
Expand Down
18 changes: 18 additions & 0 deletions src/content/component/MultiLayerButton/MultiLayerButton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Created by Earth_Studio on 2026/4/25.
//

#include "MultiLayerButton.h"

namespace cmaterial::component {
MultiLayerButton::MultiLayerButton() {
addLayer(&backgroundLayer);
addLayer(&overlayLayer);
}

void MultiLayerButton::update(ImGuiIO *io) {
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.0f, 1.0f, 0.0f, 1.0f));
ImGui::Button(name.c_str());
ImGui::PopStyleColor();
}
} // namespace cmaterial::component
31 changes: 31 additions & 0 deletions src/content/component/MultiLayerButton/MultiLayerButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Created by Earth_Studio on 2026/4/25.
//

#ifndef CMATERIAL_ANIMATIONBUTTON_H
#define CMATERIAL_ANIMATIONBUTTON_H


#include "engine/component/IComponent.h"

#include "layer/BackgroundLayer.h"
#include "layer/OverlayLayer.h"


namespace cmaterial::component {
class MultiLayerButton : public IComponent {
public:
MultiLayerButton();
~MultiLayerButton() = default;

void update(ImGuiIO *io) override;

private:
layer::animationbutton::BackgroundLayer backgroundLayer;
layer::animationbutton::OverlayLayer overlayLayer;
};
}



#endif //CMATERIAL_ANIMATIONBUTTON_H
18 changes: 18 additions & 0 deletions src/content/component/MultiLayerButton/layer/BackgroundLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Created by Earth_Studio on 2026/4/27.
//

#include "BackgroundLayer.h"

namespace cmaterial::component::layer::animationbutton {
BackgroundLayer::BackgroundLayer() {
priority = -1;
}

void BackgroundLayer::render(ImDrawList *drawList, ImVec2 startPos, ImVec2 size) {
ImGui::SetCursorPos(startPos);
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.0f, 0.0f, 1.0f, 1.0f));
ImGui::Button("BackGround", ImVec2(size.x + 5, size.y + 5));
ImGui::PopStyleColor();
}
}
22 changes: 22 additions & 0 deletions src/content/component/MultiLayerButton/layer/BackgroundLayer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Created by Earth_Studio on 2026/4/27.
//

#ifndef CMATERIAL_MULTILAYERBUTTON_BACKGROUNDLAYER_H
#define CMATERIAL_MULTILAYERBUTTON_BACKGROUNDLAYER_H
#include "engine/component/ILayer.hpp"


namespace cmaterial::component::layer::animationbutton {
class BackgroundLayer : public ILayer{
public:
BackgroundLayer();
~BackgroundLayer() = default;

void render(ImDrawList *drawList, ImVec2 startPos, ImVec2 size) override;
};
}



#endif //CMATERIAL_BACKGROUNDLAYER_H
14 changes: 14 additions & 0 deletions src/content/component/MultiLayerButton/layer/OverlayLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Created by Earth_Studio on 2026/4/27.
//

#include "OverlayLayer.h"

namespace cmaterial::component::layer::animationbutton {
void OverlayLayer::render(ImDrawList *drawList, ImVec2 startPos, ImVec2 size) {
ImGui::SetCursorPos(startPos);
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
ImGui::Button("OverLay", ImVec2(size.x - 5, size.y - 5));
ImGui::PopStyleColor();
}
} // namespace cmaterial::component::layer::animationbutton
22 changes: 22 additions & 0 deletions src/content/component/MultiLayerButton/layer/OverlayLayer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Created by Earth_Studio on 2026/4/27.
//

#ifndef CMATERIAL_OVERLAYLAYER_H
#define CMATERIAL_OVERLAYLAYER_H
#include "engine/component/ILayer.hpp"


namespace cmaterial::component::layer::animationbutton {
class OverlayLayer : public ILayer {
public:
OverlayLayer() = default;
~OverlayLayer() = default;

void render(ImDrawList *drawList, ImVec2 startPos, ImVec2 size) override;
};
}



#endif //CMATERIAL_OVERLAYLAYER_H
71 changes: 71 additions & 0 deletions src/content/component/material/Button/Button.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// Created by Earth_Studio on 2026/5/12.
//

#include "Button.h"

#include "engine/animation/Player.h"
#include "engine/eventbus/EventBus.h"

#include "content/component/material/Button/layer/RippleLayer.h"

namespace cmaterial::component::material {
Button::Button() {
m_bgLayer = new layer::BGLayer();
addLayer(m_bgLayer);
}

Button::~Button() {
if (m_hoverAnim) {
cmaterial::animation::Player::stop(m_hoverAnim);
delete m_hoverAnim;
}
}

void Button::update(ImGuiIO *io) {
m_bgLayer->primaryColor = this->primaryColor;
m_bgLayer->onPrimaryColor = this->onPrimaryColor;

ImVec2 size(ImGui::CalcTextSize(name.c_str()).x + 48.0f, 40.0f);
ImVec2 p_min = ImGui::GetCursorScreenPos();
ImGui::InvisibleButton(name.c_str(), size);

bool hovered = ImGui::IsItemHovered();
bool active = ImGui::IsItemActive();
bool clicked = ImGui::IsItemClicked();

if (hovered && !m_isHovering) {
m_isHovering = true;
if (m_hoverAnim) { cmaterial::animation::Player::stop(m_hoverAnim); delete m_hoverAnim; }
m_hoverAnim = new animation::HoverAnimation(&m_bgLayer->hoverAlpha, 1.0, this);
m_hoverAnim->parent = this;
cmaterial::animation::Player::play(m_hoverAnim);
} else if (!hovered && m_isHovering) {
m_isHovering = false;
if (m_hoverAnim) { cmaterial::animation::Player::stop(m_hoverAnim); delete m_hoverAnim; }
m_hoverAnim = new animation::HoverAnimation(&m_bgLayer->hoverAlpha, 0.0, this);
m_hoverAnim->parent = this;
cmaterial::animation::Player::play(m_hoverAnim);
}

if (clicked) {
addLayer(new layer::RippleLayer(io->MousePos, this->onPrimaryColor));
}

if (active && !m_isPressed) m_isPressed = true;
else if (!active && m_isPressed) {
m_isPressed = false;
if (hovered) {
// auto* e = new event::ButtonClickedEvent();
// e->buttonName = this->name;
// e->buttonInstance = this;
// event::EventBus::postEvent(e);
}
}

ImGui::GetWindowDrawList()->AddText(
ImVec2(p_min.x + 24.0f, p_min.y + (40.0f - ImGui::CalcTextSize(name.c_str()).y) / 2.0f),
ImGui::GetColorU32(onPrimaryColor), name.c_str()
);
}
}
32 changes: 32 additions & 0 deletions src/content/component/material/Button/Button.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Created by Earth_Studio on 2026/5/12.
//

#ifndef CMATERIAL_BUTTON_H
#define CMATERIAL_BUTTON_H
#include "content/animation/material/HoverAnimation.h"
#include "engine/component/IComponent.h"
#include "layer/BGLayer.h"

namespace cmaterial::component::material {
class Button : public IComponent {
public:
Button();
~Button() override;
void update(ImGuiIO *io) override;

ImVec4 primaryColor = ImVec4(0.404f, 0.314f, 0.643f, 1.0f);
ImVec4 onPrimaryColor = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);

private:
bool m_isHovering = false;
bool m_isPressed = false;

layer::BGLayer * m_bgLayer = nullptr;
animation::HoverAnimation* m_hoverAnim = nullptr;
};
}



#endif //CMATERIAL_BUTTON_H
35 changes: 35 additions & 0 deletions src/content/component/material/Button/layer/BGLayer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Created by Earth_Studio on 2026/5/13.
//

#ifndef CMATERIAL_BACKGROUNDLAYER_H
#define CMATERIAL_BACKGROUNDLAYER_H
#include "engine/component/ILayer.hpp"
#include "imgui.h"


namespace cmaterial::component::material::layer {
class BGLayer : public ILayer {
public:
BGLayer() { priority = -2; }
void render(ImDrawList* drawList, ImVec2 startPos, ImVec2 size) override {
float mix = static_cast<float>(hoverAlpha) * 0.08f;
ImVec4 finalColor = ImVec4(
primaryColor.x * (1.0f - mix) + onPrimaryColor.x * mix,
primaryColor.y * (1.0f - mix) + onPrimaryColor.y * mix,
primaryColor.z * (1.0f - mix) + onPrimaryColor.z * mix,
primaryColor.w
);
drawList->AddRectFilled(startPos, ImVec2(startPos.x + size.x, startPos.y + size.y),
ImGui::GetColorU32(finalColor), size.y / 2.0f);
}

double hoverAlpha = 0.0;
ImVec4 primaryColor = ImVec4(0.404f, 0.314f, 0.643f, 1.0f);
ImVec4 onPrimaryColor = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
};
}



#endif //CMATERIAL_BACKGROUNDLAYER_H
Loading
Loading