Auto Offset Grid

This commit is contained in:
tobid7 2024-02-25 14:26:35 +01:00
parent 0627fa71be
commit ce7c59a162
5 changed files with 30 additions and 57 deletions

View File

@ -14,11 +14,10 @@
- Removed Old Font/Text Handlers
- Added UI7 (New UI Api)
- Remove Old UI Api
- Added Music Player (MP3, Vorbis)
- Rewrite of RenderD7::Image
- Internal Debugger/Database (IDB)
- Removed BitmapPrinter
- Added nimg and nimg_engine
- Added nimg and swr(render2nimg | SoftwareRender)
- Removed Old Error/Message Handler
- GetTextSize (extra buffer) + New TextShorter
- Require specific FLAG for Music/MemTrack
@ -27,6 +26,7 @@
- Remove INI reader
- Python based clangformat script
- Move some Init code into functions to not use twice
- Added Font class
## 0.9.4
- Implement new Security System To prevent from crashes
- Implement Functiontrace for better Timing Tests

View File

@ -46,8 +46,8 @@ void InputText(const std::string &label, std::string &text,
bool BeginMenu(const std::string &title, R7Vec2 size = R7Vec2(0, 0),
UI7MenuFlags flags = 0);
void EndMenu();
void Grid(const std::string &name, const R7Vec2 &size,
R7Vec2 (*display_func)(void *, R7Vec2), void **data_array,
void Grid(const std::string &name, const R7Vec2 &size, const R7Vec2 &entry_size,
void (*display_func)(void *, R7Vec2), void **data_array,
size_t num_entrys);
bool BeginTree(const std::string &text);
void EndTree();

View File

@ -1,26 +1,5 @@
#include "scene.hpp"
void ColorThemeSample() {
RD7::ColorNew(RD7Color_Text, RD7::Color::Hex("#000000", 255));
RD7::ColorNew(RD7Color_TextDisabled, RD7::Color::Hex("#212121", 200));
RD7::ColorNew(RD7Color_Text2, RD7::Color::Hex("#ffffff", 255));
RD7::ColorNew(RD7Color_Background, RD7::Color::Hex("#eeeeee", 170));
RD7::ColorNew(RD7Color_Header, RD7::Color::Hex("#222222", 190));
RD7::ColorNew(RD7Color_Selector, RD7::Color::Hex("#4444dd", 200));
RD7::ColorNew(RD7Color_SelectorFade, RD7::Color::Hex("#7777dd", 200));
RD7::ColorNew(RD7Color_List0, RD7::Color::Hex("#555555", 130));
RD7::ColorNew(RD7Color_List1, RD7::Color::Hex("#777777", 130));
RD7::ColorNew(RD7Color_MessageBackground, RD7::Color::Hex("#222222", 180));
RD7::ColorNew(RD7Color_Button, RD7::Color::Hex("#4444dd", 150));
RD7::ColorNew(RD7Color_ButtonHovered, RD7::Color::Hex("#6666dd", 150));
RD7::ColorNew(RD7Color_ButtonDisabled, RD7::Color::Hex("#2222dd", 150));
RD7::ColorNew(RD7Color_ButtonActive, RD7::Color::Hex("#7777dd", 150));
RD7::ColorNew(RD7Color_Checkmark, RD7::Color::Hex("#4444dd", 130));
RD7::ColorNew(RD7Color_FrameBg, RD7::Color::Hex("#555555", 160));
RD7::ColorNew(RD7Color_FrameBgHovered, RD7::Color::Hex("#777777", 160));
RD7::ColorNew(RD7Color_Progressbar, RD7::Color::Hex("#4444dd", 200));
}
extern void IdbServer();
int main() {
@ -30,7 +9,6 @@ int main() {
RD7::Init::Main("rd7tf");
RD7::FadeIn();
// IdbServer();
ColorThemeSample();
RD7::Init::NdspFirm();
RD7::Scene::Load(std::make_unique<Sample>());
RD7::Ftrace::End("app", "app_init");

View File

@ -51,10 +51,7 @@ void DrawWave(R7Vec2 position, R7Vec2 size, float time, bool dbg) {
R7Vec2 testv2 = R7Vec2(48, 48);
std::vector<int*> img;
R7Vec2 display_icon(void* v, R7Vec2 p) {
DV2::RFS(p, testv2, 0xff00ffff);
return testv2;
}
void display_icon(void* v, R7Vec2 p) { DV2::RFS(p, testv2, 0xff00ffff); }
Sample::Sample() {
auto t = RD7::FileSystem::GetDirContent("sdmc:/music/");
@ -98,8 +95,8 @@ void Sample::Draw() const {
UI7::RestoreCursor();
if (state == State_Menu) {
UI7::Label("SZS: " + std::to_string(img.size()));
UI7::Grid("Images", R7Vec2(390, 180), display_icon, (void**)&img[0],
img.size());
UI7::Grid("Images", R7Vec2(390, 180), testv2, display_icon,
(void**)&img[0], img.size());
}
UI7::EndMenu();
}
@ -124,9 +121,9 @@ void Sample::Draw() const {
UI7::SameLine();
if (UI7::Button("def")) txt_size = 0.5;
UI7::Label("GridControl: ");
if(UI7::Button("icn++")) testv2 += R7Vec2(1, 1);
if (UI7::Button("icn++")) testv2 += R7Vec2(1, 1);
UI7::SameLine();
if(UI7::Button("icn--")) testv2 -= R7Vec2(1, 1);
if (UI7::Button("icn--")) testv2 -= R7Vec2(1, 1);
}
UI7::EndMenu();
}

View File

@ -123,7 +123,6 @@ struct UI7_Ctx {
bool in_menu;
bool debugging;
UI7ID current_menu;
std::map<std::string, R7Vec2> grid_mapping;
std::unordered_map<std::string, UI7ID *> ids;
std::vector<UI7OBJ> objects;
};
@ -476,44 +475,43 @@ bool BeginMenu(const std::string &title, R7Vec2 size, UI7MenuFlags flags) {
void EndMenu() { UI7CtxEndMenu(); }
void Grid(const std::string &name, const R7Vec2 &size,
R7Vec2 (*display_func)(void *, R7Vec2), void **data_array,
void Grid(const std::string &name, const R7Vec2 &size, const R7Vec2 &entry_size,
void (*display_func)(void *, R7Vec2), void **data_array,
size_t num_entrys) {
if (!UI7CtxValidate()) return;
if (num_entrys <= 0) return;
if (data_array == nullptr) return;
if (ui7_ctx->grid_mapping.find(UI7ID(name).real_id) ==
ui7_ctx->grid_mapping.end())
ui7_ctx->grid_mapping[UI7ID(name).real_id] =
R7Vec2(); // Register id not exist
R7Vec2 pos = GetCursorPos();
R7Vec2 cpos(pos);
UI7CtxRegObj(UI7OBJ(R7Vec4(pos, size), 1));
int neh = std::floor(size.x / (entry_size.x + 4));
int nev = std::floor(size.y / (entry_size.y + 4));
// Inside Grid Offset
R7Vec2 igoff = R7Vec2();
if (neh >= 2 && nev >= 2) {
igoff = R7Vec2(
((size.x) / 2 - (((neh - 1) * (entry_size.x + 4)) + entry_size.x) / 2),
((size.y) / 2 - ((nev - 1) * ((entry_size.y + 4)) + entry_size.y) / 2));
}
// Y-Offset
int yoff = 0;
pos += ui7_ctx->grid_mapping[UI7ID(name).real_id];
pos += igoff;
for (size_t i = 0; i < num_entrys; i++) {
R7Vec2 szs = display_func(data_array[i], pos);
UI7CtxRegObj(UI7OBJ(R7Vec4(pos, szs), 2));
if(ui7_ctx->debugging) RenderD7::Draw2::Text(pos + R7Vec2(4, 4), std::to_string(i));
if (pos.x + (szs.x * 2) > (cpos.x + size.x) &&
pos.y + (szs.y*2) > cpos.y + size.y) {
if (ui7_ctx->grid_mapping[UI7ID(name).real_id].y == 0)
ui7_ctx->grid_mapping[UI7ID(name).real_id].y =
(cpos.y + size.y) / 2 - ((yoff+2) * (szs.y + 4)) / 2;
display_func(data_array[i], pos);
UI7CtxRegObj(UI7OBJ(R7Vec4(pos, entry_size), 2));
if (ui7_ctx->debugging)
RenderD7::Draw2::Text(pos + R7Vec2(4, 4), std::to_string(i));
if (pos.x + (entry_size.x * 2) > (cpos.x + size.x) &&
pos.y + (entry_size.y * 2) > cpos.y + size.y) {
break;
} else if (pos.x + (szs.x * 2) > (cpos.x + size.x)) {
if (ui7_ctx->grid_mapping[UI7ID(name).real_id].x == 0)
ui7_ctx->grid_mapping[UI7ID(name).real_id].x =
(cpos.x + size.x) / 2 - ((i + 1) * (szs.x + 4)) / 2;
pos = R7Vec2(5 + ui7_ctx->grid_mapping[UI7ID(name).real_id].x,
pos.y + szs.y + 4);
} else if (pos.x + (entry_size.x * 2) > (cpos.x + size.x)) {
pos = R7Vec2(5 + igoff.x, pos.y + entry_size.y + 4);
yoff++;
} else {
pos += R7Vec2(szs.x + 4, 0);
pos += R7Vec2(entry_size.x + 4, 0);
}
}