Auto Offset Grid
This commit is contained in:
		@@ -14,11 +14,10 @@
 | 
				
			|||||||
- Removed Old Font/Text Handlers
 | 
					- Removed Old Font/Text Handlers
 | 
				
			||||||
- Added UI7 (New UI Api)
 | 
					- Added UI7 (New UI Api)
 | 
				
			||||||
- Remove Old UI Api
 | 
					- Remove Old UI Api
 | 
				
			||||||
- Added Music Player (MP3, Vorbis)
 | 
					 | 
				
			||||||
- Rewrite of RenderD7::Image
 | 
					- Rewrite of RenderD7::Image
 | 
				
			||||||
- Internal Debugger/Database (IDB)
 | 
					- Internal Debugger/Database (IDB)
 | 
				
			||||||
- Removed BitmapPrinter
 | 
					- Removed BitmapPrinter
 | 
				
			||||||
- Added nimg and nimg_engine
 | 
					- Added nimg and swr(render2nimg | SoftwareRender)
 | 
				
			||||||
- Removed Old Error/Message Handler
 | 
					- Removed Old Error/Message Handler
 | 
				
			||||||
- GetTextSize (extra buffer) + New TextShorter
 | 
					- GetTextSize (extra buffer) + New TextShorter
 | 
				
			||||||
- Require specific FLAG for Music/MemTrack
 | 
					- Require specific FLAG for Music/MemTrack
 | 
				
			||||||
@@ -27,6 +26,7 @@
 | 
				
			|||||||
- Remove INI reader
 | 
					- Remove INI reader
 | 
				
			||||||
- Python based clangformat script
 | 
					- Python based clangformat script
 | 
				
			||||||
- Move some Init code into functions to not use twice
 | 
					- Move some Init code into functions to not use twice
 | 
				
			||||||
 | 
					- Added Font class
 | 
				
			||||||
## 0.9.4
 | 
					## 0.9.4
 | 
				
			||||||
- Implement new Security System To prevent from crashes
 | 
					- Implement new Security System To prevent from crashes
 | 
				
			||||||
- Implement Functiontrace for better Timing Tests
 | 
					- Implement Functiontrace for better Timing Tests
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,8 +46,8 @@ void InputText(const std::string &label, std::string &text,
 | 
				
			|||||||
bool BeginMenu(const std::string &title, R7Vec2 size = R7Vec2(0, 0),
 | 
					bool BeginMenu(const std::string &title, R7Vec2 size = R7Vec2(0, 0),
 | 
				
			||||||
               UI7MenuFlags flags = 0);
 | 
					               UI7MenuFlags flags = 0);
 | 
				
			||||||
void EndMenu();
 | 
					void EndMenu();
 | 
				
			||||||
void Grid(const std::string &name, const R7Vec2 &size,
 | 
					void Grid(const std::string &name, const R7Vec2 &size, const R7Vec2 &entry_size,
 | 
				
			||||||
          R7Vec2 (*display_func)(void *, R7Vec2), void **data_array,
 | 
					          void (*display_func)(void *, R7Vec2), void **data_array,
 | 
				
			||||||
          size_t num_entrys);
 | 
					          size_t num_entrys);
 | 
				
			||||||
bool BeginTree(const std::string &text);
 | 
					bool BeginTree(const std::string &text);
 | 
				
			||||||
void EndTree();
 | 
					void EndTree();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,26 +1,5 @@
 | 
				
			|||||||
#include "scene.hpp"
 | 
					#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();
 | 
					extern void IdbServer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main() {
 | 
					int main() {
 | 
				
			||||||
@@ -30,7 +9,6 @@ int main() {
 | 
				
			|||||||
  RD7::Init::Main("rd7tf");
 | 
					  RD7::Init::Main("rd7tf");
 | 
				
			||||||
  RD7::FadeIn();
 | 
					  RD7::FadeIn();
 | 
				
			||||||
  // IdbServer();
 | 
					  // IdbServer();
 | 
				
			||||||
  ColorThemeSample();
 | 
					 | 
				
			||||||
  RD7::Init::NdspFirm();
 | 
					  RD7::Init::NdspFirm();
 | 
				
			||||||
  RD7::Scene::Load(std::make_unique<Sample>());
 | 
					  RD7::Scene::Load(std::make_unique<Sample>());
 | 
				
			||||||
  RD7::Ftrace::End("app", "app_init");
 | 
					  RD7::Ftrace::End("app", "app_init");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,10 +51,7 @@ void DrawWave(R7Vec2 position, R7Vec2 size, float time, bool dbg) {
 | 
				
			|||||||
R7Vec2 testv2 = R7Vec2(48, 48);
 | 
					R7Vec2 testv2 = R7Vec2(48, 48);
 | 
				
			||||||
std::vector<int*> img;
 | 
					std::vector<int*> img;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
R7Vec2 display_icon(void* v, R7Vec2 p) {
 | 
					void display_icon(void* v, R7Vec2 p) { DV2::RFS(p, testv2, 0xff00ffff); }
 | 
				
			||||||
  DV2::RFS(p, testv2, 0xff00ffff);
 | 
					 | 
				
			||||||
  return testv2;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
Sample::Sample() {
 | 
					Sample::Sample() {
 | 
				
			||||||
  auto t = RD7::FileSystem::GetDirContent("sdmc:/music/");
 | 
					  auto t = RD7::FileSystem::GetDirContent("sdmc:/music/");
 | 
				
			||||||
@@ -98,8 +95,8 @@ void Sample::Draw() const {
 | 
				
			|||||||
    UI7::RestoreCursor();
 | 
					    UI7::RestoreCursor();
 | 
				
			||||||
    if (state == State_Menu) {
 | 
					    if (state == State_Menu) {
 | 
				
			||||||
      UI7::Label("SZS: " + std::to_string(img.size()));
 | 
					      UI7::Label("SZS: " + std::to_string(img.size()));
 | 
				
			||||||
      UI7::Grid("Images", R7Vec2(390, 180), display_icon, (void**)&img[0],
 | 
					      UI7::Grid("Images", R7Vec2(390, 180), testv2, display_icon,
 | 
				
			||||||
                img.size());
 | 
					                (void**)&img[0], img.size());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    UI7::EndMenu();
 | 
					    UI7::EndMenu();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -124,9 +121,9 @@ void Sample::Draw() const {
 | 
				
			|||||||
      UI7::SameLine();
 | 
					      UI7::SameLine();
 | 
				
			||||||
      if (UI7::Button("def")) txt_size = 0.5;
 | 
					      if (UI7::Button("def")) txt_size = 0.5;
 | 
				
			||||||
      UI7::Label("GridControl: ");
 | 
					      UI7::Label("GridControl: ");
 | 
				
			||||||
      if(UI7::Button("icn++")) testv2 += R7Vec2(1, 1);
 | 
					      if (UI7::Button("icn++")) testv2 += R7Vec2(1, 1);
 | 
				
			||||||
      UI7::SameLine();
 | 
					      UI7::SameLine();
 | 
				
			||||||
      if(UI7::Button("icn--")) testv2 -= R7Vec2(1, 1);
 | 
					      if (UI7::Button("icn--")) testv2 -= R7Vec2(1, 1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    UI7::EndMenu();
 | 
					    UI7::EndMenu();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -123,7 +123,6 @@ struct UI7_Ctx {
 | 
				
			|||||||
  bool in_menu;
 | 
					  bool in_menu;
 | 
				
			||||||
  bool debugging;
 | 
					  bool debugging;
 | 
				
			||||||
  UI7ID current_menu;
 | 
					  UI7ID current_menu;
 | 
				
			||||||
  std::map<std::string, R7Vec2> grid_mapping;
 | 
					 | 
				
			||||||
  std::unordered_map<std::string, UI7ID *> ids;
 | 
					  std::unordered_map<std::string, UI7ID *> ids;
 | 
				
			||||||
  std::vector<UI7OBJ> objects;
 | 
					  std::vector<UI7OBJ> objects;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@@ -476,44 +475,43 @@ bool BeginMenu(const std::string &title, R7Vec2 size, UI7MenuFlags flags) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void EndMenu() { UI7CtxEndMenu(); }
 | 
					void EndMenu() { UI7CtxEndMenu(); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Grid(const std::string &name, const R7Vec2 &size,
 | 
					void Grid(const std::string &name, const R7Vec2 &size, const R7Vec2 &entry_size,
 | 
				
			||||||
          R7Vec2 (*display_func)(void *, R7Vec2), void **data_array,
 | 
					          void (*display_func)(void *, R7Vec2), void **data_array,
 | 
				
			||||||
          size_t num_entrys) {
 | 
					          size_t num_entrys) {
 | 
				
			||||||
  if (!UI7CtxValidate()) return;
 | 
					  if (!UI7CtxValidate()) return;
 | 
				
			||||||
  if (num_entrys <= 0) return;
 | 
					  if (num_entrys <= 0) return;
 | 
				
			||||||
  if (data_array == nullptr) 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 pos = GetCursorPos();
 | 
				
			||||||
  R7Vec2 cpos(pos);
 | 
					  R7Vec2 cpos(pos);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  UI7CtxRegObj(UI7OBJ(R7Vec4(pos, size), 1));
 | 
					  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
 | 
					  // Y-Offset
 | 
				
			||||||
  int yoff = 0;
 | 
					  int yoff = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pos += ui7_ctx->grid_mapping[UI7ID(name).real_id];
 | 
					  pos += igoff;
 | 
				
			||||||
  for (size_t i = 0; i < num_entrys; i++) {
 | 
					  for (size_t i = 0; i < num_entrys; i++) {
 | 
				
			||||||
    R7Vec2 szs = display_func(data_array[i], pos);
 | 
					    display_func(data_array[i], pos);
 | 
				
			||||||
    UI7CtxRegObj(UI7OBJ(R7Vec4(pos, szs), 2));
 | 
					    UI7CtxRegObj(UI7OBJ(R7Vec4(pos, entry_size), 2));
 | 
				
			||||||
    if(ui7_ctx->debugging) RenderD7::Draw2::Text(pos + R7Vec2(4, 4), std::to_string(i));
 | 
					    if (ui7_ctx->debugging)
 | 
				
			||||||
    if (pos.x + (szs.x * 2) > (cpos.x + size.x) &&
 | 
					      RenderD7::Draw2::Text(pos + R7Vec2(4, 4), std::to_string(i));
 | 
				
			||||||
        pos.y + (szs.y*2) > cpos.y + size.y) {
 | 
					    if (pos.x + (entry_size.x * 2) > (cpos.x + size.x) &&
 | 
				
			||||||
        if (ui7_ctx->grid_mapping[UI7ID(name).real_id].y == 0)
 | 
					        pos.y + (entry_size.y * 2) > cpos.y + size.y) {
 | 
				
			||||||
          ui7_ctx->grid_mapping[UI7ID(name).real_id].y =
 | 
					 | 
				
			||||||
            (cpos.y + size.y) / 2 - ((yoff+2) * (szs.y + 4)) / 2;
 | 
					 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
    } else if (pos.x + (szs.x * 2) > (cpos.x + size.x)) {
 | 
					    } else if (pos.x + (entry_size.x * 2) > (cpos.x + size.x)) {
 | 
				
			||||||
      if (ui7_ctx->grid_mapping[UI7ID(name).real_id].x == 0)
 | 
					      pos = R7Vec2(5 + igoff.x, pos.y + entry_size.y + 4);
 | 
				
			||||||
        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);
 | 
					 | 
				
			||||||
      yoff++;
 | 
					      yoff++;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      pos += R7Vec2(szs.x + 4, 0);
 | 
					      pos += R7Vec2(entry_size.x + 4, 0);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user