# Stage 2

- reAdd Text Shorting
- make SpriteSheet part of SmartCtor
- Add Some Gaussian Blur func (not functional for now)
-  Add Image Indexing functions and Reverse32 for (RGBA -> ABGR)
- Add Transparency flag to Keyboard and Fix its Render Prder
- Add UI7 Alignment API
  - Incldes PushAlignment (One way Alignment, JoinAlign, etc)
- Make Setter for Scroll Offset public
- Make Getter for ScrollMod Public
- Add a Check if Menu is duing an animated scroll
- Add FindMenu to Context for Modifications after Context::EndMenu
- Fix Major Issue in Lithium InBox Function
- Fix TextAlignRight and Add PerLine Text Shorting
- Fix Screen being unused in Performance Overlay
- Add Beta Slider Dragging
- Dont Handle Inputs for Objects when scrolling
- Add a MainArea to Not Handle Inputs outside of it
- Simplefied some logic

- TODO:
  - Write TextWrap Function
  - Add PerLine text Align
  - Track and Fix a lot of UI7 Bugs such as Alignment Issues etc
This commit is contained in:
tobid7 2025-02-17 22:20:30 +01:00
parent ca26189f52
commit cbdb15e0de
22 changed files with 379 additions and 41 deletions

View File

@ -47,6 +47,7 @@ set(SRC_FILES
source/maths/color.cpp source/maths/color.cpp
source/maths/bit_util.cpp source/maths/bit_util.cpp
source/maths/img_convert.cpp source/maths/img_convert.cpp
source/maths/img_blur.cpp
# Graphics # Graphics
source/graphics/texture.cpp source/graphics/texture.cpp
source/graphics/spritesheet.cpp source/graphics/spritesheet.cpp

View File

@ -37,6 +37,7 @@ SOFTWARE.
// Maths // Maths
#include <pd/maths/bit_util.hpp> #include <pd/maths/bit_util.hpp>
#include <pd/maths/color.hpp> #include <pd/maths/color.hpp>
#include <pd/maths/img_blur.hpp>
#include <pd/maths/img_convert.hpp> #include <pd/maths/img_convert.hpp>
#include <pd/maths/vec.hpp> #include <pd/maths/vec.hpp>
// Overlays // Overlays

View File

@ -481,6 +481,8 @@ class Renderer : public SmartCtor<Renderer> {
void TextCommand(std::vector<Command::Ref>& cmds, const vec2& pos, u32 color, void TextCommand(std::vector<Command::Ref>& cmds, const vec2& pos, u32 color,
const std::string& text, LITextFlags flags, const vec2& box); const std::string& text, LITextFlags flags, const vec2& box);
vec2 GetTextDimensions(const std::string& text); vec2 GetTextDimensions(const std::string& text);
std::string ShortText(const std::string& text, int maxlen, vec2& newsize);
std::string WrapText(const std::string& text, int maxlen, vec2& newsize);
private: private:
/// Helper Funcitons /// /// Helper Funcitons ///

View File

@ -31,7 +31,7 @@ SOFTWARE.
#include <pd/graphics/texture.hpp> #include <pd/graphics/texture.hpp>
namespace PD { namespace PD {
class SpriteSheet { class SpriteSheet : public SmartCtor<SpriteSheet> {
public: public:
SpriteSheet() {} SpriteSheet() {}
SpriteSheet(const std::string& path) { this->LoadFile(path); } SpriteSheet(const std::string& path) { this->LoadFile(path); }

39
include/pd/maths/img.hpp Normal file
View File

@ -0,0 +1,39 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/common/common.hpp>
#include <pd/maths/vec.hpp>
namespace PD {
namespace Img {
inline int Index3dsTex(int x, int y, int width) {
return ((((y >> 3) * (width >> 3) + (x >> 3)) << 6) +
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) |
((x & 4) << 2) | ((y & 4) << 3)));
}
inline int IndexDefault(int x, int y, int width) { return y * width + x; }
} // namespace Img
} // namespace PD

View File

@ -0,0 +1,54 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/common/common.hpp>
#include <pd/maths/img.hpp>
#include <pd/maths/vec.hpp>
namespace PD {
namespace ImgBlur {
std::vector<float> GaussianKernel(int radius, float si);
/// @brief Gaussian Blur for basic Image Buffer
/// @param buf Image Buffer (unsigned char)
/// @param w // width of the image
/// @param h // width of the image
/// @param radius // Blur radius
/// @param si // Blur sigma
/// @param idxfn // Indexing function (if buffer is 3ds tiled)
void GaussianBlur(std::vector<u8> &buf, int w, int h, float radius, float si,
std::function<int(int, int, int)> idxfn = Img::IndexDefault);
/// @brief Advanced func to access memory directly
/// @param buf Referenvce to the buffer
/// @param w // width of the image
/// @param h // width of the image
/// @param bpp Bytes per Pixels (RGB[A], RGB565, etc)
/// @param radius // Blur radius
/// @param si // Blur sigma
/// @param idxfn // Indexing function (if buffer is 3ds tiled)
void GaussianBlur(void *buf, int w, int h, int bpp, float radius, float si,
std::function<int(int, int, int)> idxfn = Img::IndexDefault);
} // namespace ImgBlur
} // namespace PD

View File

@ -30,5 +30,10 @@ namespace PD {
namespace ImgConvert { namespace ImgConvert {
void RGB24toRGBA32(std::vector<u8> &out, const std::vector<u8> &in, void RGB24toRGBA32(std::vector<u8> &out, const std::vector<u8> &in,
const int &w, const int &h); const int &w, const int &h);
/// @brief Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
/// @param buf Buffer to convert
/// @param w width
/// @param h height
void Reverse32(std::vector<u8> &buf, const int &w, const int &h);
} // namespace ImgConvert } // namespace ImgConvert
} // namespace PD } // namespace PD

View File

@ -64,6 +64,7 @@ class Keyboard : public Overlay {
Flags_BlendTop = 1 << 0, Flags_BlendTop = 1 << 0,
Flags_BlendBottom = 1 << 1, Flags_BlendBottom = 1 << 1,
Flags_LockControls = 1 << 2, Flags_LockControls = 1 << 2,
Flags_Transparency = 1 << 3,
Flags_Default = Flags_BlendBottom | Flags_BlendTop | Flags_LockControls, Flags_Default = Flags_BlendBottom | Flags_BlendTop | Flags_LockControls,
}; };
Keyboard(std::string& text, State& state, const std::string& hint = "", Keyboard(std::string& text, State& state, const std::string& hint = "",

View File

@ -24,6 +24,7 @@ SOFTWARE.
*/ */
using UI7MenuFlags = unsigned int; using UI7MenuFlags = unsigned int;
using UI7Align = unsigned int;
enum UI7MenuFlags_ { enum UI7MenuFlags_ {
UI7MenuFlags_None = 0, UI7MenuFlags_None = 0,
@ -34,3 +35,14 @@ enum UI7MenuFlags_ {
UI7MenuFlags_NoBackground = 1 << 4, UI7MenuFlags_NoBackground = 1 << 4,
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling, UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
}; };
/// @brief Probably need to update this
enum UI7Align_ {
UI7Align_Left = 1 << 0,
UI7Align_Center = 1 << 1,
UI7Align_Right = 1 << 2,
UI7Align_Top = 1 << 3,
UI7Align_Mid = 1 << 4,
UI7Align_Bottom = 1 << 5,
UI7Align_Default = UI7Align_Left | UI7Align_Top,
};

View File

@ -59,9 +59,12 @@ class Menu : public SmartCtor<Menu> {
void Separator(); void Separator();
void SeparatorText(const std::string& label); void SeparatorText(const std::string& label);
void Join(); void Join();
/// @brief Horizontal Center Joined objects void JoinAlign(UI7Align a);
void JoinOpHzCenter(); void AfterAlign(UI7Align a);
void AfterAlignCenter(); void NextAlign(UI7Align a) { tmpalign = a; }
void PushAlignment(UI7Align a) { alignment = a; }
void PopAlignment() { alignment = UI7Align_Default; }
static vec2 AlignPos(vec2 pos, vec2 size, vec4 view, UI7Align a);
/// API for Custom Objects /// API for Custom Objects
bool HandleScrolling(vec2& pos, const vec2& size); bool HandleScrolling(vec2& pos, const vec2& size);
@ -89,12 +92,15 @@ class Menu : public SmartCtor<Menu> {
vec4 MainArea() const { return main_area; } vec4 MainArea() const { return main_area; }
void MainArea(const vec4& v) { main_area = v; } void MainArea(const vec4& v) { main_area = v; }
vec2 ScrollOffset() const { return scrolling_off; } vec2 ScrollOffset() const { return scrolling_off; }
void ScrollOffset(const vec2& v) { scrolling_off = v; }
vec2 ScrollMod() const { return scroll_mod; }
void ScrollTo(vec2 pos) { void ScrollTo(vec2 pos) {
scroll_anim.From(scrolling_off) scroll_anim.From(scrolling_off)
.To(pos) .To(pos)
.In(1.f) .In(1.f)
.As(scroll_anim.EaseInOutSine); .As(scroll_anim.EaseInOutSine);
} }
bool IsAnimatedScroll() { return !scroll_anim.IsFinished(); }
/// Objects API /// Objects API
Container::Ref ObjectPush(Container::Ref obj); Container::Ref ObjectPush(Container::Ref obj);
@ -124,10 +130,17 @@ class Menu : public SmartCtor<Menu> {
vec2 SameLineCursor() const { return slcursor; } vec2 SameLineCursor() const { return slcursor; }
void SameLineCursor(const vec2& v) { slcursor = v; } void SameLineCursor(const vec2& v) { slcursor = v; }
void ViewArea(const vec4& v) { view_area = v; } void ViewArea(const vec4& v) { view_area = v; }
void ScrollOffset(const vec2& v) { scrolling_off = v; }
vec2 ScrollMod() const { return scroll_mod; }
void ScrollMod(const vec2& v) { scroll_mod = v; } void ScrollMod(const vec2& v) { scroll_mod = v; }
UI7Align GetAlignment() {
if (tmpalign) {
auto t = tmpalign;
tmpalign = 0;
return t;
}
return alignment;
}
/// Internal Processing /// Internal Processing
void Update(float delta); void Update(float delta);
@ -135,6 +148,8 @@ class Menu : public SmartCtor<Menu> {
friend class Context; friend class Context;
/// Data /// Data
UI7Align alignment = UI7Align_Default;
UI7Align tmpalign = 0;
UI7MenuFlags flags = 0; UI7MenuFlags flags = 0;
u32 id; u32 id;
std::string name; std::string name;

View File

@ -45,6 +45,7 @@ class Context : public SmartCtor<Context> {
bool BeginMenu(const ID& id, UI7MenuFlags flags = 0); bool BeginMenu(const ID& id, UI7MenuFlags flags = 0);
Menu::Ref GetCurrentMenu(); Menu::Ref GetCurrentMenu();
Menu::Ref FindMenu(const ID& id);
void EndMenu(); void EndMenu();
/// Theme Management /// Theme Management

View File

@ -281,8 +281,8 @@ void Renderer::StaticText::SetPos(const vec2& pos) {
void Renderer::StaticText::SetLayer(int layer) { text->ReLayer(layer); } void Renderer::StaticText::SetLayer(int layer) { text->ReLayer(layer); }
bool Renderer::InBox(const vec2& pos, const vec2& szs, const vec4& rect) { bool Renderer::InBox(const vec2& pos, const vec2& szs, const vec4& rect) {
return (pos[0] < rect[2] || pos[1] < rect[3] || pos[0] + szs[0] > rect[0] || return (pos[0] + szs[0] >= rect[0] && pos[1] + szs[1] >= rect[1] &&
pos[1] + szs[1] > rect[1]); pos[0] <= rect[2] && pos[1] <= rect[3]);
} }
bool Renderer::InBox(const vec2& pos, const vec4& rect) { bool Renderer::InBox(const vec2& pos, const vec4& rect) {
@ -398,7 +398,7 @@ void Renderer::TextCommand(std::vector<Command::Ref>& cmds, const vec2& pos,
rpos = rbox * 0.5 - td * 0.5 + pos; rpos = rbox * 0.5 - td * 0.5 + pos;
} }
if (flags & LITextFlags_AlignRight) { if (flags & LITextFlags_AlignRight) {
rpos[0] = rbox[0] - td[0]; rpos[0] = rpos[0] - td[0];
} }
std::vector<std::string> lines; std::vector<std::string> lines;
@ -409,7 +409,13 @@ void Renderer::TextCommand(std::vector<Command::Ref>& cmds, const vec2& pos,
} }
for (auto& it : lines) { for (auto& it : lines) {
if (rpos[1] + off[1] + lh < 0) { if (flags & LITextFlags_Short) {
vec2 tmp_dim;
it = ShortText(it, box.x() - pos.x(), tmp_dim);
}
/// Well support OOS Rendering here as well
/// Fixes UI7 Scroll back up bug
if (rpos[1] + off[1] + lh < 0 && !(flags & LITextFlags_RenderOOS)) {
off[1] += lh; off[1] += lh;
continue; continue;
} else if (rpos[1] + off[1] > GetViewport().w() && } else if (rpos[1] + off[1] > GetViewport().w() &&
@ -468,6 +474,58 @@ void Renderer::TextCommand(std::vector<Command::Ref>& cmds, const vec2& pos,
vec4 Renderer::GetViewport() { return vec4(vec2(), screen->GetSize()); } vec4 Renderer::GetViewport() { return vec4(vec2(), screen->GetSize()); }
std::string Renderer::ShortText(const std::string& text, int maxlen,
vec2& newsize) {
vec2 cdim;
if (flags & RenderFlags_TMS) {
auto e = tms.find(text);
if (e != tms.end()) {
e->second.TimeCreated(Sys::GetTime());
if (e->second.Optional()) {
return e->second.Text();
}
cdim = e->second.Size();
}
}
cdim = this->GetTextDimensions(text);
if (cdim[0] < (float)maxlen) {
return text;
}
std::string ext;
/// Forgot why i called this var ending cause
/// Its more a placeholder for removed content
std::string ending = "...";
std::string cpy = text;
std::string res;
size_t extension = text.find_last_of('.');
if (extension != text.npos) {
ext = text.substr(extension);
cpy = text.substr(0, extension);
maxlen -= GetTextDimensions(ext).x();
}
maxlen -= GetTextDimensions(ending).x();
for (auto& it : cpy) {
if (GetTextDimensions(res).x() > (float)maxlen) {
res += ending;
res += ext;
newsize = GetTextDimensions(res);
if (flags & RenderFlags_TMS) {
auto& tmp = tms[text];
tmp.Text(res);
tmp.Size(newsize);
tmp.TimeCreated(Sys::GetTime());
tmp.Optional(true);
}
break;
}
res += it;
}
return res;
}
std::string Renderer::WrapText(const std::string& text, int maxlen,
vec2& newsize) {}
vec2 Renderer::GetTextDimensions(const std::string& text) { vec2 Renderer::GetTextDimensions(const std::string& text) {
if (!font) { if (!font) {
// No font no size (oder so) // No font no size (oder so)

88
source/maths/img_blur.cpp Normal file
View File

@ -0,0 +1,88 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <cstring>
#include <memory>
#include <pd/maths/img_blur.hpp>
#include <pd/maths/img_convert.hpp>
namespace PD {
namespace ImgBlur {
std::vector<float> GaussianKernel(int r, float si) {
/// Define radius as r to be shorter
int size = 2 * r + 1;
std::vector<float> kernel(size);
float sum = 0.0f;
for (int i = -r; i <= r; i++) {
kernel[i + r] = exp(-0.5f * (i * i) / (si * si));
sum += kernel[i + r];
}
for (int i = 0; i < size; i++) {
kernel[i] /= sum;
}
return kernel;
}
void GaussianBlur(std::vector<u8> &buf, int w, int h, float radius, float si,
std::function<int(int, int, int)> idxfn) {
GaussianBlur(buf.data(), w, h, 4, radius, si, idxfn);
}
void GaussianBlur(void *buf, int w, int h, int bpp, float radius, float si,
std::function<int(int, int, int)> idxfn) {
if (bpp != 4 && bpp != 3) {
return;
}
std::vector<float> kernel = GaussianKernel(radius, si);
int hks = kernel.size() / 2;
int end = w * h * bpp;
std::vector<unsigned char> res((u8 *)buf, ((u8 *)buf) + end);
ImgConvert::Reverse32(res, w, h);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
float r = 0.0f, g = 0.0f, b = 0.0f;
for (int ky = -hks; ky <= hks; ky++) {
for (int kx = -hks; kx <= hks; kx++) {
int xoff = std::min(std::max(x + kx, 0), w - 1);
int yoff = std::min(std::max(y + ky, 0), h - 1);
int idx = idxfn(xoff, yoff, w) * 4;
float weight = kernel[ky + hks] * kernel[kx + hks];
r += ((u8 *)buf)[idx] * weight;
g += ((u8 *)buf)[idx + 1] * weight;
b += ((u8 *)buf)[idx + 2] * weight;
}
}
int idx = idxfn(x, y, w) * bpp;
res[idx] = std::min(std::max(int(r), 0), 255);
res[idx + 1] = std::min(std::max(int(g), 0), 255);
res[idx + 2] = std::min(std::max(int(b), 0), 255);
}
}
ImgConvert::Reverse32(res, w, h);
std::memcpy(buf, res.data(), res.size());
}
} // namespace ImgBlur
} // namespace PD

View File

@ -21,6 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include <pd/maths/img.hpp>
#include <pd/maths/img_convert.hpp> #include <pd/maths/img_convert.hpp>
namespace PD::ImgConvert { namespace PD::ImgConvert {
@ -38,4 +39,17 @@ void RGB24toRGBA32(std::vector<u8> &out, const std::vector<u8> &in,
} }
} }
} }
void Reverse32(std::vector<u8> &buf, const int &w, const int &h) {
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
int i = Img::IndexDefault(x, y, w);
u8 t0 = buf[i + 0];
u8 t1 = buf[i + 1];
buf[i + 0] = buf[i + 3];
buf[i + 1] = buf[i + 2];
buf[i + 3] = t0;
buf[i + 2] = t1;
}
}
}
} // namespace PD::ImgConvert } // namespace PD::ImgConvert

View File

@ -531,8 +531,10 @@ void Keyboard::Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) {
/// Get the current start possition /// Get the current start possition
vec2 start = flymgr; vec2 start = flymgr;
// Draw head and Keyboard background // Draw head and Keyboard background
ren->DrawRectSolid(
vec2(0, start.y()), vec2(320, 125),
PD::Color("#222222ff").a((flags & Flags_Transparency) ? 0xaa : 0xff));
ren->DrawRectSolid(vec2(0, start.y()), vec2(320, 17), 0xaa000000); ren->DrawRectSolid(vec2(0, start.y()), vec2(320, 17), 0xaa000000);
ren->DrawRectSolid(vec2(0, start.y()), vec2(320, 125), 0xaa222222);
/// Grab the base layer and go one up for texts /// Grab the base layer and go one up for texts
int l = ren->Layer(); int l = ren->Layer();
ren->Layer(l + 2); ren->Layer(l + 2);

View File

@ -32,7 +32,7 @@ void Performance::Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) {
if (*skill) { if (*skill) {
Kill(); Kill();
} }
ren->OnScreen(ren->GetScreen(false)); ren->OnScreen(ren->GetScreen(*screen));
ren->TextScale(0.6); ren->TextScale(0.6);
vec2 pos; vec2 pos;
Line(pos, std::format("{:.1f} FPS / {:.2f}ms", 1000.f / delta, delta), ren); Line(pos, std::format("{:.1f} FPS / {:.2f}ms", 1000.f / delta, delta), ren);

View File

@ -16,13 +16,13 @@ void SettingsMenu::Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) {
auto m = ctx->GetCurrentMenu(); auto m = ctx->GetCurrentMenu();
m->SeparatorText("Library Info"); m->SeparatorText("Library Info");
m->Label(LibInfo::CompiledWith()); m->Label(LibInfo::CompiledWith());
m->AfterAlignCenter(); m->AfterAlign(UI7Align_Center);
m->Label(LibInfo::CxxVersion()); m->Label(LibInfo::CxxVersion());
m->AfterAlignCenter(); m->AfterAlign(UI7Align_Center);
m->Label("Version: " + LibInfo::Version() + "[" + LibInfo::Commit() + "]"); m->Label("Version: " + LibInfo::Version() + "[" + LibInfo::Commit() + "]");
m->AfterAlignCenter(); m->AfterAlign(UI7Align_Center);
m->Label("Build Time: " + LibInfo::BuildTime()); m->Label("Build Time: " + LibInfo::BuildTime());
m->AfterAlignCenter(); m->AfterAlign(UI7Align_Center);
ctx->EndMenu(); ctx->EndMenu();
} }
ren->OnScreen(ren->GetScreen(true)); ren->OnScreen(ren->GetScreen(true));

View File

@ -32,9 +32,7 @@ void Container::HandleScrolling(vec2 scrolling, vec4 viewport) {
} }
last_use = Sys::GetTime(); last_use = Sys::GetTime();
pos -= vec2(0, scrolling.y()); pos -= vec2(0, scrolling.y());
if (!LI::Renderer::InBox(pos, size, viewport)) { skippable = !LI::Renderer::InBox(pos, size, viewport);
skippable = true;
}
} }
} // namespace UI7 } // namespace UI7
} // namespace PD } // namespace PD

View File

@ -68,6 +68,7 @@ void DrawList::AddText(vec2 pos, const std::string& text, const UI7Color& clr,
if (!e->second->IsSetup() || e->second->Font() != ren->Font()) { if (!e->second->IsSetup() || e->second->Font() != ren->Font()) {
int l = ren->Layer(); int l = ren->Layer();
ren->Layer(base); ren->Layer(base);
/// Probably a simple ren.get() would handle the job too
e->second->Setup(&(*ren), pos, clr, text, flags, box); e->second->Setup(&(*ren), pos, clr, text, flags, box);
e->second->Font(ren->Font()); e->second->Font(ren->Font());
ren->Layer(l); ren->Layer(l);

View File

@ -30,6 +30,7 @@ namespace UI7 {
void UI7::Menu::Label(const std::string& label) { void UI7::Menu::Label(const std::string& label) {
Container::Ref r = Container::Ref r =
ObjectPush(PD::New<UI7::Label>(label, Cursor(), this->back->ren)); ObjectPush(PD::New<UI7::Label>(label, Cursor(), this->back->ren));
r->SetPos(AlignPos(r->GetPos(), r->GetSize(), view_area, GetAlignment()));
CursorMove(r->GetSize()); CursorMove(r->GetSize());
r->Init(main->ren, main, linked_theme); r->Init(main->ren, main, linked_theme);
r->HandleScrolling(scrolling_off, view_area); r->HandleScrolling(scrolling_off, view_area);
@ -45,7 +46,7 @@ bool UI7::Menu::Button(const std::string& label) {
r->Init(main->ren, main, linked_theme); r->Init(main->ren, main, linked_theme);
} }
ObjectPush(r); ObjectPush(r);
r->SetPos(Cursor()); r->SetPos(AlignPos(Cursor(), r->GetSize(), view_area, GetAlignment()));
CursorMove(r->GetSize()); CursorMove(r->GetSize());
r->HandleScrolling(scrolling_off, view_area); r->HandleScrolling(scrolling_off, view_area);
if (!r->Skippable()) { if (!r->Skippable()) {
@ -63,7 +64,7 @@ void UI7::Menu::Checkbox(const std::string& label, bool& v) {
r->Init(main->ren, main, linked_theme); r->Init(main->ren, main, linked_theme);
} }
ObjectPush(r); ObjectPush(r);
r->SetPos(Cursor()); r->SetPos(AlignPos(Cursor(), r->GetSize(), view_area, GetAlignment()));
CursorMove(r->GetSize()); CursorMove(r->GetSize());
r->HandleScrolling(scrolling_off, view_area); r->HandleScrolling(scrolling_off, view_area);
} }
@ -71,6 +72,7 @@ void UI7::Menu::Checkbox(const std::string& label, bool& v) {
void UI7::Menu::Image(Texture::Ref img, vec2 size) { void UI7::Menu::Image(Texture::Ref img, vec2 size) {
Container::Ref r = Container::Ref r =
ObjectPush(PD::New<UI7::Image>(img, Cursor(), this->back->ren, size)); ObjectPush(PD::New<UI7::Image>(img, Cursor(), this->back->ren, size));
r->SetPos(AlignPos(r->GetPos(), r->GetSize(), view_area, GetAlignment()));
CursorMove(r->GetSize()); CursorMove(r->GetSize());
r->Init(main->ren, main, linked_theme); r->Init(main->ren, main, linked_theme);
r->HandleScrolling(scrolling_off, view_area); r->HandleScrolling(scrolling_off, view_area);
@ -113,7 +115,9 @@ void UI7::Menu::Update(float delta) {
idobjs.push_back(it); idobjs.push_back(it);
} }
if (!it->Skippable()) { if (!it->Skippable()) {
it->HandleInput(inp); if (scroll_mod[1] == 0.f) {
it->HandleInput(inp);
}
/// Unlock Input after to ensure nothing is checked twice /// Unlock Input after to ensure nothing is checked twice
it->UnlockInput(); it->UnlockInput();
it->Draw(); it->Draw();
@ -262,6 +266,20 @@ void UI7::Menu::PostHandler() {
} }
} }
/// Slider Dragging????
/// Probably need a new API for this
auto tp = inp->TouchPos();
if (inp->IsHeld(inp->Touch) &&
LI::Renderer::InBox(tp, vec4(screen_w - 12, tsp, 8, szs))) {
float drag_center = vslider_h / 2.0f;
float drag_pos =
std::clamp(static_cast<float>((tp[1] - tsp - drag_center) /
(szs - vslider_h - 4)),
0.0f, 1.0f);
scrolling_off[1] = drag_pos * (max[1] - 240.f);
}
int srpos = int srpos =
tsp + std::clamp(float(szs - vslider_h - 4) * tsp + std::clamp(float(szs - vslider_h - 4) *
(scrolling_off[1] / (max[1] - view_area[3])), (scrolling_off[1] / (max[1] - view_area[3])),
@ -318,10 +336,8 @@ void UI7::Menu::SeparatorText(const std::string& label) {
bool UI7::Menu::HandleScrolling(vec2& pos, const vec2& size) { bool UI7::Menu::HandleScrolling(vec2& pos, const vec2& size) {
if (scrolling[1]) { if (scrolling[1]) {
vec2 p = pos;
pos -= vec2(0, scrolling_off.y()); pos -= vec2(0, scrolling_off.y());
if (pos.y() > view_area.w() || if (pos.y() > view_area.w() || (pos.y() + size.y() < view_area.y())) {
(pos.y() + size.y() < tbh - 5 && p.y() > tbh)) {
return true; return true;
} }
} }
@ -347,22 +363,50 @@ void UI7::Menu::Join() {
join.push_back(objects.back().get()); join.push_back(objects.back().get());
} }
void UI7::Menu::JoinOpHzCenter() { void UI7::Menu::JoinAlign(UI7Align a) {
if (a == 0) {
a = UI7Align_Default;
}
this->Join(); this->Join();
float spos = join.front()->GetPos().x();
float szs = join.back()->GetPos().x() + join.back()->GetSize().x() - spos; vec2 spos = join.front()->GetPos();
float off = (view_area.x() + view_area.z() * 0.5) - (spos + szs * 0.5); vec2 szs = join.back()->GetPos() + join.back()->GetSize() - spos;
vec2 off;
if (a & UI7Align_Center) {
off[0] = (view_area[0] + view_area[2] * 0.5) - (spos[0] + szs[0] * 0.5);
}
if (a & UI7Align_Mid) {
off[1] = (view_area[1] + view_area[3] * 0.5) - (spos[1] + szs[1] * 0.5);
}
for (auto it : join) { for (auto it : join) {
it->SetPos(it->GetPos() + vec2(off, 0.f)); it->SetPos(it->GetPos() + off);
} }
join.clear(); join.clear();
} }
void UI7::Menu::AfterAlignCenter() {
vec2 UI7::Menu::AlignPos(vec2 pos, vec2 size, vec4 view, UI7Align a) {
vec2 np = pos;
if (a & UI7Align_Center) {
np[0] = (view[0] + view[2] * 0.5) - (pos[0] + size[0] * 0.5);
}
if (a & UI7Align_Mid) {
np[1] = (view[1] + view[3] * 0.5) - (pos[1] + size[1] * 0.5);
}
return np;
}
void UI7::Menu::AfterAlign(UI7Align a) {
Container* ref = objects.back().get(); Container* ref = objects.back().get();
vec2 p = ref->GetPos(); vec2 p = ref->GetPos();
vec2 s = ref->GetSize(); vec2 s = ref->GetSize();
float newx = (view_area.x() + view_area.z() * 0.5) - (p.x() + s.x() * 0.5); vec2 np = p;
ref->SetPos(vec2(newx, p.y())); if (a & UI7Align_Center) {
np[0] = (view_area[0] + view_area[2] * 0.5) - (p[0] + s[0] * 0.5);
}
if (a & UI7Align_Mid) {
np[1] = (view_area[1] + view_area[3] * 0.5) - (p[1] + s[1] * 0.5);
}
ref->SetPos(np);
} }
} // namespace UI7 } // namespace UI7
} // namespace PD } // namespace PD

View File

@ -58,6 +58,14 @@ UI7::Menu::Ref UI7::Context::GetCurrentMenu() {
return current; return current;
} }
UI7::Menu::Ref UI7::Context::FindMenu(const ID& id) {
auto e = this->menus.find(id);
if (e != this->menus.end()) {
return e->second;
}
return nullptr;
}
void UI7::Context::EndMenu() { void UI7::Context::EndMenu() {
this->current->PostHandler(); this->current->PostHandler();
this->current = nullptr; this->current = nullptr;

View File

@ -60,26 +60,20 @@ class Test : public PD::App {
m->SeparatorText("Menu Timings"); m->SeparatorText("Menu Timings");
m->DebugLabels(); m->DebugLabels();
m->SeparatorText("Palladium Info"); m->SeparatorText("Palladium Info");
m->PushAlignment(UI7Align_Center);
m->Label("Version: " + PD::LibInfo::Version() + " [" + m->Label("Version: " + PD::LibInfo::Version() + " [" +
PD::LibInfo::Commit() + "]"); PD::LibInfo::Commit() + "]");
m->AfterAlignCenter();
m->Label("CompileInfo: " + PD::LibInfo::CompiledWith() + " - " + m->Label("CompileInfo: " + PD::LibInfo::CompiledWith() + " - " +
PD::LibInfo::CxxVersion()); PD::LibInfo::CxxVersion());
m->AfterAlignCenter();
m->Label("Build at " + PD::LibInfo::BuildTime()); m->Label("Build at " + PD::LibInfo::BuildTime());
m->AfterAlignCenter();
m->SeparatorText("Basic Info"); m->SeparatorText("Basic Info");
m->Label("sizeof(size_t): " + std::to_string(sizeof(size_t)) + " -> " + m->Label("sizeof(size_t): " + std::to_string(sizeof(size_t)) + " -> " +
std::to_string(sizeof(size_t) * 8) + "Bit"); std::to_string(sizeof(size_t) * 8) + "Bit");
m->AfterAlignCenter();
m->Label("__cplusplus=" + std::to_string(__cplusplus)); m->Label("__cplusplus=" + std::to_string(__cplusplus));
m->AfterAlignCenter();
m->Label(PD::Strings::GetCompilerVersion()); m->Label(PD::Strings::GetCompilerVersion());
m->AfterAlignCenter();
m->Label("sizeof(LI::Vertex): " + std::to_string(sizeof(PD::LI::Vertex))); m->Label("sizeof(LI::Vertex): " + std::to_string(sizeof(PD::LI::Vertex)));
m->AfterAlignCenter();
m->Label("sizeof(PD::u16): " + std::to_string(sizeof(PD::u16))); m->Label("sizeof(PD::u16): " + std::to_string(sizeof(PD::u16)));
m->AfterAlignCenter(); m->PopAlignment();
m->SeparatorText("UI7 Tests"); m->SeparatorText("UI7 Tests");
m->Label("This seems to be a label"); m->Label("This seems to be a label");
m->Image(test); m->Image(test);