- Fix minor issues
- Add Custom UV Support to Drawlist and Menu Image
- Add DoubleClick to IO Input API
- Add Flashbang Theme (Not completly done)
- Fix Menu glitch when scrolling was possible when not allowed
This commit is contained in:
2025-03-12 21:09:45 +01:00
parent b94dfc0c53
commit ba77dc9b42
15 changed files with 83 additions and 39 deletions

View File

@ -50,8 +50,10 @@ void Button::Draw() {
Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
io->Ren->OnScreen(screen);
list->AddRectangle(FinalPos(), size, io->Theme->Get(color));
list->Layer(list->Layer() + 1);
list->AddText(FinalPos() + size * 0.5 - tdim * 0.5, label,
io->Theme->Get(UI7Color_Text));
list->Layer(list->Layer() - 1);
}
void Button::Update() {

View File

@ -29,7 +29,7 @@ void Image::Draw() {
Assert(io.get() && list.get(), "Did you run Container::Init correctly?");
Assert(img.get(), "Image is nullptr!");
io->Ren->OnScreen(screen);
list->AddImage(FinalPos(), img, newsize);
list->AddImage(FinalPos(), img, newsize, this->cuv);
}
} // namespace UI7
} // namespace PD

View File

@ -95,28 +95,11 @@ void DrawList::AddText(vec2 pos, const std::string& text, const UI7Color& clr,
ren->CurrentScreen()->ScreenType() == Screen::Bottom, it));
}
e->GetRawObject()->ReCopy();
////// STILL LEAVING THE OLD CODE BELOW AS IT IS MAYBE NEEDED //////
////// IF STATIC TEXT SYSTEM SHOULD HAVE AN DISABLE OPTION //////
// Dont create a Command here as TextCommand has autosetup
// cause it needs to generate multiple commands if
// Font uses multiple textures
// Oh and Handle Layer management here as well
// int l = ren->Layer();
// ren->Layer(base + layer);
// std::vector<LI::Command::Ref> cmds;
// ren->TextCommand(cmds, pos, clr, text, flags, box);
// ren->Layer(l);
// for (auto c : cmds) {
// commands.push_back(
// std::make_pair(ren->CurrentScreen()->ScreenType() == Screen::Bottom,
// c));
// }
}
void DrawList::AddImage(vec2 pos, Texture::Ref img, vec2 size) {
void DrawList::AddImage(vec2 pos, Texture::Ref img, vec2 size, LI::Rect uv) {
size = size == 0.f ? img->GetSize() : size;
uv = (uv.Top() == 0.0f && uv.Bot() == 0.0f) ? img->GetUV() : uv;
if (!ren->InBox(pos, size, ren->GetViewport())) {
return;
}
@ -129,7 +112,7 @@ void DrawList::AddImage(vec2 pos, Texture::Ref img, vec2 size) {
cmd->SetScissorMode(LI::ScissorMode_Normal);
cmd->ScissorRect(clip_rects.top());
}
ren->QuadCommand(cmd, rect, img->GetUV(), 0xffffffff);
ren->QuadCommand(cmd, rect, uv, 0xffffffff);
commands.push_back(std::make_pair(
ren->CurrentScreen()->ScreenType() == Screen::Bottom, cmd));
}

View File

@ -30,6 +30,7 @@ void UI7::IO::Update() {
DragTime->Update();
DragReleased = false;
DragReleasedAW = false;
DragDoubleRelease = false;
Framerate = 1000.f / Delta;
DrawListRegestry.clear();
RegisterDrawList("CtxBackList", Back);

View File

@ -85,8 +85,8 @@ void UI7::Menu::Checkbox(const std::string& label, bool& v) {
r->HandleScrolling(scrolling_off, view_area);
}
void UI7::Menu::Image(Texture::Ref img, vec2 size) {
Container::Ref r = ObjectPush(PD::New<UI7::Image>(img, size));
void UI7::Menu::Image(Texture::Ref img, vec2 size, LI::Rect uv) {
Container::Ref r = ObjectPush(PD::New<UI7::Image>(img, size, uv));
r->SetPos(AlignPos(Cursor(), r->GetSize(), view_area, GetAlignment()));
CursorMove(r->GetSize());
r->Init(io, main);
@ -538,6 +538,7 @@ bool UI7::Menu::BeginTreeNode(const UI7::ID& id) {
}
return n->second;
}
void UI7::Menu::EndTreeNode() {
icursoroff.x() -= 10.f;
cursor.x() -= 10;
@ -591,6 +592,9 @@ void UI7::Menu::MoveHandler() {
if (has_touch &&
io->DragObject(name + "tmv",
vec4(view_area.xy(), vec2(view_area.z(), tbh)))) {
if (io->DragDoubleRelease) {
is_open = !is_open;
}
view_area =
vec4(view_area.xy() + (io->DragPosition - io->DragLastPosition),
view_area.zw());
@ -626,7 +630,8 @@ void UI7::Menu::CollapseHandler() {
void UI7::Menu::PostScrollHandler() {
if (has_touch && io->DragObject(id, view_area) && scrolling[1] &&
flags & UI7MenuFlags_VtScrolling) {
flags & UI7MenuFlags_VtScrolling &&
max[1] - view_area.w() + io->MenuPadding[1] > 0) {
if (io->DragReleased) {
scroll_mod = (io->DragPosition - io->DragLastPosition);
} else {

View File

@ -44,5 +44,24 @@ void Theme::Default(Theme& theme) {
theme.Set(UI7Color_ListEven, Color("#CCCCCCFF"));
theme.Set(UI7Color_ListOdd, Color("#BBBBBBFF"));
}
void Theme::Flashbang(Theme& theme) {
theme.Set(UI7Color_Text, Color("#000000FF"));
theme.Set(UI7Color_TextDead, Color("#333333FF"));
theme.Set(UI7Color_Background, Color("#eeeeeeFF"));
theme.Set(UI7Color_Button, Color("#ccccccFF"));
theme.Set(UI7Color_ButtonDead, Color("#bbbbbbFF"));
theme.Set(UI7Color_ButtonActive, Color("#ccccccFF"));
theme.Set(UI7Color_ButtonHovered, Color("#cbcbcbFF"));
theme.Set(UI7Color_Header, Color("#ddddddFF"));
theme.Set(UI7Color_HeaderDead, Color("#cdcdcdFF"));
theme.Set(UI7Color_Selector, Color("#222222FF"));
theme.Set(UI7Color_Checkmark, Color("#ccccccFF"));
theme.Set(UI7Color_FrameBackground, Color("#aaaaaaFF"));
theme.Set(UI7Color_FrameBackgroundHovered, Color("#909090FF"));
theme.Set(UI7Color_Progressbar, Color("#00FF00FF"));
theme.Set(UI7Color_ListEven, Color("#CCCCCCFF"));
theme.Set(UI7Color_ListOdd, Color("#BBBBBBFF"));
}
} // namespace UI7
} // namespace PD

View File

@ -178,6 +178,18 @@ void UI7::Context::MetricsMenu(bool* show) {
m->Label(std::format("NumIndices: {} -> {} Tris", io->NumIndices,
io->NumIndices / 3));
m->Label("Menus: " + std::to_string(menus.size()));
if (m->BeginTreeNode("Font")) {
for (u32 i = 0; i <= 0x00ff; i++) {
auto& c = io->Ren->Font()->GetCodepoint(i);
if (!c.invalid()) {
m->Image(c.tex(), c.size(), c.uv());
if ((i % 15) != 0 || i == 0) {
m->SameLine();
}
}
}
m->EndTreeNode();
}
m->SeparatorText("TimeTrace");
if (m->BeginTreeNode("Traces (" +
std::to_string(Sys::GetTraceMap().size()) + ")")) {
@ -280,6 +292,13 @@ void UI7::Context::StyleEditor(bool* show) {
io->ItemSpace += 1;
}
m->SeparatorText("Theme");
if (m->Button("Dark")) {
UI7::Theme::Default(*io->Theme.get());
}
m->SameLine();
if (m->Button("Flashbang")) {
UI7::Theme::Flashbang(*io->Theme.get());
}
/// Small trick to print without prefix
#define ts(x) m->ColorEdit(std::string(#x).substr(9), &io->Theme->GetRef(x));
ts(UI7Color_Background);