# Changes 0.2.7
- Add UI7 32Bit Version Num - Fix ClipRect Bug with Separators - Fix Triangle/Rect Render order Bug (UI7 - Bug of Lithium) - Add Position to Menus and Movement by dragging the Title bar - Add Menu Collabse (+ Flag to disable) - Add About and Metrics Menus to Context
This commit is contained in:
@ -78,28 +78,32 @@ void UI7::Menu::Image(Texture::Ref img, vec2 size) {
|
||||
r->HandleScrolling(scrolling_off, view_area);
|
||||
}
|
||||
|
||||
void UI7::Menu::DebugLabels() {
|
||||
void UI7::Menu::DebugLabels(Menu::Ref m, Menu::Ref t) {
|
||||
if (t == nullptr) {
|
||||
t = m;
|
||||
}
|
||||
std::stringstream s;
|
||||
s << "Name: " << name << " [";
|
||||
s << std::hex << std::setw(8) << std::setfill('0') << id;
|
||||
s << "Name: " << m->name << " [";
|
||||
s << std::hex << std::setw(8) << std::setfill('0') << m->id;
|
||||
s << std::dec << "]";
|
||||
this->Label(s.str());
|
||||
this->Label(
|
||||
t->Label(s.str());
|
||||
t->Label(std::format("Size: {:.2f}, {:.2f}", m->max.x(), m->max.y()));
|
||||
t->Label(
|
||||
"Pre: " +
|
||||
Strings::FormatNanos(
|
||||
Sys::GetTraceRef("MPRE_" + name)->GetProtocol()->GetAverage()));
|
||||
this->Label(
|
||||
Sys::GetTraceRef("MPRE_" + m->name)->GetProtocol()->GetAverage()));
|
||||
t->Label(
|
||||
"Post: " +
|
||||
Strings::FormatNanos(
|
||||
Sys::GetTraceRef("MPOS_" + name)->GetProtocol()->GetAverage()));
|
||||
this->Label(
|
||||
Sys::GetTraceRef("MPOS_" + m->name)->GetProtocol()->GetAverage()));
|
||||
t->Label(
|
||||
"Update: " +
|
||||
Strings::FormatNanos(
|
||||
Sys::GetTraceRef("MUPT_" + name)->GetProtocol()->GetAverage()));
|
||||
this->Label(
|
||||
Sys::GetTraceRef("MUPT_" + m->name)->GetProtocol()->GetAverage()));
|
||||
t->Label(
|
||||
"MUser: " +
|
||||
Strings::FormatNanos(
|
||||
Sys::GetTraceRef("MUSR_" + name)->GetProtocol()->GetAverage()));
|
||||
Sys::GetTraceRef("MUSR_" + m->name)->GetProtocol()->GetAverage()));
|
||||
}
|
||||
|
||||
void UI7::Menu::Update(float delta) {
|
||||
@ -108,7 +112,11 @@ void UI7::Menu::Update(float delta) {
|
||||
if (!scroll_anim.IsFinished()) {
|
||||
scrolling_off = scroll_anim;
|
||||
}
|
||||
main->PushClipRect(vec4(5, tbh, view_area.z() - 12, view_area.w()));
|
||||
if (!(flags & UI7MenuFlags_NoClipRect)) {
|
||||
main->PushClipRect(vec4(pos.x() + 5, pos.y() + tbh,
|
||||
pos.x() + view_area.z() - 12,
|
||||
pos.y() + view_area.w()));
|
||||
}
|
||||
std::vector<int> tbr;
|
||||
for (int i = 0; i < (int)objects.size(); i++) {
|
||||
auto& it = objects[i];
|
||||
@ -132,7 +140,9 @@ void UI7::Menu::Update(float delta) {
|
||||
for (auto it : tbr) {
|
||||
idobjs.erase(idobjs.begin() + it);
|
||||
}
|
||||
main->PopClipRect();
|
||||
if (!(flags & UI7MenuFlags_NoClipRect)) {
|
||||
main->PopClipRect();
|
||||
}
|
||||
this->back->Process();
|
||||
this->main->Process();
|
||||
this->front->Process();
|
||||
@ -163,28 +173,79 @@ void UI7::Menu::PreHandler(UI7MenuFlags flags) {
|
||||
this->scrolling[0] = flags & UI7MenuFlags_HzScrolling;
|
||||
this->scrolling[1] = flags & UI7MenuFlags_VtScrolling;
|
||||
has_touch = main->ren->CurrentScreen()->ScreenType() == Screen::Bottom;
|
||||
if (!(flags & UI7MenuFlags_NoBackground)) {
|
||||
back->AddRectangle(0, view_area.zw(), theme->Get(UI7Color_Background));
|
||||
if (!(flags & UI7MenuFlags_NoBackground) && is_open) {
|
||||
back->AddRectangle(pos, view_area.zw(), theme->Get(UI7Color_Background));
|
||||
}
|
||||
if (!(flags & UI7MenuFlags_NoTitlebar)) {
|
||||
tbh = front->ren->TextScale() * 30.f;
|
||||
front->AddRectangle(0, vec2(view_area.z(), tbh),
|
||||
front->AddRectangle(pos, vec2(view_area.z(), tbh),
|
||||
theme->Get(UI7Color_Header));
|
||||
vec2 tpos(5, tbh * 0.5 - front->ren->GetTextDimensions(name).y() * 0.5);
|
||||
if (!(flags & UI7MenuFlags_NoCollapse)) {
|
||||
tpos.x() += 18;
|
||||
vec2 cpos = pos + 5;
|
||||
UI7Color clr = UI7Color_FrameBackground;
|
||||
if (inp->IsUp(inp->Touch) &&
|
||||
LI::Renderer::InBox(inp->TouchPosLast(), vec4(cpos, vec2(18, tbh))) &&
|
||||
has_touch) {
|
||||
is_open = !is_open;
|
||||
}
|
||||
if (inp->IsHeld(inp->Touch) &&
|
||||
LI::Renderer::InBox(inp->TouchPos(), vec4(cpos, vec2(18, tbh))) &&
|
||||
has_touch) {
|
||||
clr = UI7Color_FrameBackgroundHovered;
|
||||
}
|
||||
vec2 positions[2] = {
|
||||
vec2(12, 6),
|
||||
vec2(0, 12),
|
||||
};
|
||||
if (is_open) {
|
||||
float t = positions[0].y();
|
||||
positions[0].y() = positions[1].x();
|
||||
positions[1].x() = t;
|
||||
}
|
||||
this->front->AddTriangle(cpos, cpos + positions[0], cpos + positions[1],
|
||||
theme->Get(clr));
|
||||
}
|
||||
LITextFlags tflags = LITextFlags_None;
|
||||
if (flags & UI7MenuFlags_CenterTitle) {
|
||||
tpos = 0;
|
||||
tflags = LITextFlags_AlignMid;
|
||||
}
|
||||
front->AddText(tpos, this->name, theme->Get(UI7Color_Text), tflags,
|
||||
front->Layer(front->Layer() + 1);
|
||||
front->AddText(pos + tpos, this->name, theme->Get(UI7Color_Text), tflags,
|
||||
vec2(view_area.z(), tbh));
|
||||
main_area[1] = tbh;
|
||||
CursorInit();
|
||||
// Add a clip Rect for Separators
|
||||
if (!(flags & UI7MenuFlags_NoClipRect)) {
|
||||
main->PushClipRect(vec4(pos.x() + 5, pos.y() + tbh,
|
||||
pos.x() + view_area.z() - 12,
|
||||
pos.y() + view_area.w()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UI7::Menu::PostHandler() {
|
||||
TT::Scope st("MPOS_" + name);
|
||||
if (inp->IsDown(inp->Touch) &&
|
||||
LI::Renderer::InBox(inp->TouchPos(),
|
||||
vec4(pos + vec2(18, 0), vec2(view_area.z(), tbh))) &&
|
||||
has_touch) {
|
||||
mouse = inp->TouchPos();
|
||||
} else if (inp->IsUp(inp->Touch) &&
|
||||
LI::Renderer::InBox(
|
||||
inp->TouchPos(),
|
||||
vec4(pos + vec2(18, 0), vec2(view_area.z(), tbh))) &&
|
||||
has_touch) {
|
||||
mouse = 0;
|
||||
} else if (inp->IsHeld(inp->Touch) &&
|
||||
LI::Renderer::InBox(
|
||||
inp->TouchPosLast(),
|
||||
vec4(pos + vec2(18, 0), vec2(view_area.z(), tbh))) &&
|
||||
has_touch) {
|
||||
pos = inp->TouchPos() - mouse;
|
||||
}
|
||||
if (scrolling[1]) {
|
||||
scroll_allowed[1] = (max[1] > 235);
|
||||
scrollbar[1] = scroll_allowed[1];
|
||||
@ -286,15 +347,21 @@ void UI7::Menu::PostHandler() {
|
||||
0.f, float(szs - vslider_h - 4));
|
||||
|
||||
/// Rendering Stage
|
||||
front->AddRectangle(vec2(screen_w - 12, tsp), vec2(slider_w * 2, szs),
|
||||
front->AddRectangle(pos + vec2(screen_w - 12, tsp),
|
||||
vec2(slider_w * 2, szs),
|
||||
theme->Get(UI7Color_FrameBackground));
|
||||
front->AddRectangle(vec2(screen_w - 10, tsp + 2), vec2(slider_w, szs - 4),
|
||||
front->AddRectangle(pos + vec2(screen_w - 10, tsp + 2),
|
||||
vec2(slider_w, szs - 4),
|
||||
theme->Get(UI7Color_FrameBackgroundHovered));
|
||||
front->AddRectangle(vec2(screen_w - 10, srpos + 2),
|
||||
front->AddRectangle(pos + vec2(screen_w - 10, srpos + 2),
|
||||
vec2(slider_w, vslider_h),
|
||||
theme->Get(UI7Color_Button));
|
||||
}
|
||||
}
|
||||
// Remove the Clip Rect
|
||||
if (!(flags & UI7MenuFlags_NoClipRect)) {
|
||||
main->PopClipRect();
|
||||
}
|
||||
TT::End("MUSR_" + name);
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,14 @@ SOFTWARE.
|
||||
#include <pd/ui7/ui7.hpp>
|
||||
|
||||
namespace PD {
|
||||
std::string UI7::GetVersion(bool show_build) {
|
||||
std::stringstream s;
|
||||
s << ((UI7_VERSION >> 24) & 0xFF) << ".";
|
||||
s << ((UI7_VERSION >> 16) & 0xFF) << ".";
|
||||
s << ((UI7_VERSION >> 8) & 0xFF);
|
||||
if (show_build) s << "-" << ((UI7_VERSION) & 0xFF);
|
||||
return s.str();
|
||||
}
|
||||
bool UI7::Context::BeginMenu(const ID& id, UI7MenuFlags flags) {
|
||||
Assert(!this->current, "You are already in another Menu!");
|
||||
Assert(std::find(amenus.begin(), amenus.end(), (u32)id) == amenus.end(),
|
||||
@ -50,7 +58,10 @@ bool UI7::Context::BeginMenu(const ID& id, UI7MenuFlags flags) {
|
||||
this->current->ViewArea(this->ren->GetViewport());
|
||||
this->current->PreHandler(flags);
|
||||
amenus.push_back(this->current->GetID());
|
||||
return true;
|
||||
if (!this->current->is_open) {
|
||||
this->current = nullptr;
|
||||
}
|
||||
return this->current->is_open;
|
||||
}
|
||||
|
||||
UI7::Menu::Ref UI7::Context::GetCurrentMenu() {
|
||||
@ -74,6 +85,8 @@ void UI7::Context::EndMenu() {
|
||||
void UI7::Context::Update(float delta) {
|
||||
TT::Scope st("UI7_Update");
|
||||
Assert(current == nullptr, "Still in a Menu!");
|
||||
this->delta = delta;
|
||||
s_delta->Add(delta * 1000);
|
||||
this->back->BaseLayer(root_layer + 10);
|
||||
this->back->Process();
|
||||
for (auto it : amenus) {
|
||||
@ -83,4 +96,44 @@ void UI7::Context::Update(float delta) {
|
||||
this->front->Process();
|
||||
this->amenus.clear();
|
||||
}
|
||||
|
||||
void UI7::Context::AboutMenu() {
|
||||
if (this->BeginMenu("About UI7", UI7MenuFlags_Scrolling)) {
|
||||
auto m = this->GetCurrentMenu();
|
||||
|
||||
m->Label("Palladium - UI7 " + GetVersion());
|
||||
m->Separator();
|
||||
m->Label("(c) 2023-2025 René Amthor");
|
||||
m->Label("UI7 is licensed under the MIT License.");
|
||||
m->Label("See LICENSE for more information.");
|
||||
static bool show_build;
|
||||
m->Checkbox("Show Build Info", show_build);
|
||||
if (show_build) {
|
||||
m->SeparatorText("Build Info");
|
||||
m->Label("Full Version -> " + GetVersion(true));
|
||||
m->Label("sizeof(size_t) -> " + std::to_string(sizeof(size_t)));
|
||||
m->Label("sizeof(LI::Vertex) -> " + std::to_string(sizeof(LI::Vertex)));
|
||||
m->Label("__cplusplus -> " + std::to_string(__cplusplus));
|
||||
m->Label("Compiler -> " + LibInfo::CompiledWith());
|
||||
}
|
||||
this->EndMenu();
|
||||
}
|
||||
}
|
||||
|
||||
void UI7::Context::MetricsMenu() {
|
||||
if (this->BeginMenu("UI7 Metrics", UI7MenuFlags_Scrolling)) {
|
||||
auto m = this->GetCurrentMenu();
|
||||
|
||||
m->Label("Palladium - UI7 " + GetVersion());
|
||||
m->Separator();
|
||||
m->Label(std::format("Average {:.3f} ms/f ({:.1f} FPS)",
|
||||
((float)s_delta->GetAverage() / 1000.f),
|
||||
1000.f / ((float)s_delta->GetAverage() / 1000.f)));
|
||||
m->Label(std::format("Vertices: {} Indices: {}", ren->Vertices(),
|
||||
ren->Indices()));
|
||||
m->Label("Triangles: " + std::to_string(ren->Indices() / 3));
|
||||
m->Label("Menus: " + std::to_string(menus.size()));
|
||||
this->EndMenu();
|
||||
}
|
||||
}
|
||||
} // namespace PD
|
Reference in New Issue
Block a user