Start Implement AutoSizing into UI7

This commit is contained in:
tobid7 2024-02-20 20:35:31 +01:00
parent 168614d579
commit 33bb37be06
6 changed files with 24 additions and 4 deletions

View File

@ -26,6 +26,7 @@ namespace RenderD7 {
R7Vec2 GetTextDimensions(const std::string& text);
void CustomTextSize(float size);
void TextDefaultSize();
float TextGetSize();
std::string TextShort(const std::string& in, int max_len);
// Overrite TextBox Size (by default Screenwidth x Text.h)
void TextMaxBox(R7Vec2 size);

View File

@ -104,12 +104,19 @@ void Sample::Draw() const {
UI7::SameLine();
UI7::Checkbox("RD7-Debug", rd7_debugging);
UI7::InputText("Search", search__, "Tap Here");
UI7::Label("Text Control:");
if(UI7::Button("text++")) txt_size+=0.01;
UI7::SameLine();
if(UI7::Button("text--")) txt_size -= 0.01;
UI7::SameLine();
if(UI7::Button("def")) txt_size = 0.5;
}
UI7::EndMenu();
}
}
void Sample::Logic() {
RenderD7::CustomTextSize(txt_size);
for (const auto& it : shared_requests) {
if (it.first == 1U) {
if (it.second) RenderD7::LoadSettings();

View File

@ -28,5 +28,6 @@ class Sample : public RenderD7::Scene {
mutable std::vector<std::string> names;
mutable std::vector<std::string> files;
mutable int sel;
mutable float txt_size = 0.5f;
State state = State_Menu;
};

View File

@ -109,6 +109,8 @@ void TextFont(Font fnt) { rd7i_d2_fnt = fnt.ptr(); }
void TextDefaultFont() { rd7i_d2_fnt = rd7i_base_font; }
float TextGetSize() { return rd7i_d2_txt_size; }
std::string TextShort(const std::string &in, int max_len) {
return GetShortedText(in, max_len);
}

View File

@ -272,6 +272,8 @@ Ovl_Metrik::Ovl_Metrik(bool* is_enabled, bool* screen, uint32_t* mt_color,
}
void Ovl_Metrik::Draw(void) const {
float tmp_txt = RenderD7::TextGetSize();
RenderD7::TextDefaultSize();
if (i_screen[0]) {
RenderD7::OnScreen(Bottom);
} else {
@ -332,6 +334,7 @@ void Ovl_Metrik::Draw(void) const {
R7Vec2(320, Hid::GetTouchPosition().y),
RenderD7::Color::Hex("#ff0000"));
}
RenderD7::CustomTextSize(tmp_txt);
}
void Ovl_Metrik::Logic() {

View File

@ -242,7 +242,8 @@ bool Button(const std::string &label, R7Vec2 size) {
void Checkbox(const std::string &label, bool &c) {
if (!UI7CtxValidate()) return;
R7Vec2 cbs = R7Vec2(18, 18);
float sv = (RenderD7::TextGetSize()*40)*0.9;
R7Vec2 cbs = R7Vec2(sv, sv);
R7Vec2 txtdim = RenderD7::GetTextDimensions(label);
R7Vec2 inp = cbs + R7Vec2(txtdim.x + 5, 0);
RD7Color bg = RD7Color_FrameBg;
@ -307,6 +308,8 @@ void BrowserList(const std::vector<std::string> &entrys, int &selection,
RD7TextFlags txtflags, R7Vec2 size, int max_entrys) {
if (!UI7CtxValidate()) return;
if (selection < 0) return;
float tmp_txt = RenderD7::TextGetSize();
RenderD7::TextDefaultSize();
R7Vec2 pos = GetCursorPos();
if (pos.y + 15 * max_entrys > 230) max_entrys = (int)((230 - pos.y) / 15);
if (size.x == 0) size.x = (rd7i_current_screen ? 400 : 320) - (pos.x * 2);
@ -352,12 +355,14 @@ void BrowserList(const std::vector<std::string> &entrys, int &selection,
RenderD7::Ftrace::End("app", "short_algo");
}
}
RenderD7::CustomTextSize(tmp_txt);
}
void InputText(const std::string &label, std::string &text,
const std::string &hint) {
if (!UI7CtxValidate()) return;
R7Vec2 cbs = R7Vec2(144, 18);
float sv = (RenderD7::TextGetSize()*40)*0.9;
R7Vec2 cbs = R7Vec2(144, sv);
R7Vec2 txtdim = RenderD7::GetTextDimensions(label);
R7Vec2 inp = cbs + R7Vec2(txtdim.x + 5, 0);
RD7Color bg = RD7Color_FrameBg;
@ -394,19 +399,20 @@ bool BeginMenu(const std::string &title, R7Vec2 size, UI7MenuFlags flags) {
size.y = 240;
}
RD7TextFlags txtflags = 0;
float tbh = RenderD7::TextGetSize()*40;
if (flags & UI7MenuFlags_NoTitlebar) titlebar = false;
if (flags & UI7MenuFlags_TitleMid) txtflags = RD7TextFlags_AlignMid;
RenderD7::Draw2::RFS(R7Vec2(0, 0), size,
RenderD7::StyleColor(RD7Color_Background));
if (titlebar) {
RenderD7::Draw2::RFS(R7Vec2(0, 0), R7Vec2(size.x, 20),
RenderD7::Draw2::RFS(R7Vec2(0, 0), R7Vec2(size.x, tbh),
RenderD7::StyleColor(RD7Color_Header));
RenderD7::TextColorByBg(RD7Color_Header);
RenderD7::Draw2::Text(R7Vec2(5, 2), id->title, txtflags);
RenderD7::UndoColorEdit(RD7Color_Text);
}
SetCursorPos(R7Vec2(5, 25));
SetCursorPos(R7Vec2(5, tbh+5));
return UI7CtxBeginMenu(title);
}