From 33bb37be061fb0fb99460b5e0bf8d165a97791f6 Mon Sep 17 00:00:00 2001 From: tobid7 Date: Tue, 20 Feb 2024 20:35:31 +0100 Subject: [PATCH] Start Implement AutoSizing into UI7 --- include/renderd7/DrawV2.hpp | 1 + rd7tf/source/scene.cpp | 7 +++++++ rd7tf/source/scene.hpp | 1 + source/DrawV2.cpp | 2 ++ source/Overlays.cpp | 3 +++ source/UI7.cpp | 14 ++++++++++---- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/renderd7/DrawV2.hpp b/include/renderd7/DrawV2.hpp index 2389e02..435cfe4 100644 --- a/include/renderd7/DrawV2.hpp +++ b/include/renderd7/DrawV2.hpp @@ -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); diff --git a/rd7tf/source/scene.cpp b/rd7tf/source/scene.cpp index 7639227..46ff636 100644 --- a/rd7tf/source/scene.cpp +++ b/rd7tf/source/scene.cpp @@ -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(); diff --git a/rd7tf/source/scene.hpp b/rd7tf/source/scene.hpp index f4b1b06..921fa13 100644 --- a/rd7tf/source/scene.hpp +++ b/rd7tf/source/scene.hpp @@ -28,5 +28,6 @@ class Sample : public RenderD7::Scene { mutable std::vector names; mutable std::vector files; mutable int sel; + mutable float txt_size = 0.5f; State state = State_Menu; }; \ No newline at end of file diff --git a/source/DrawV2.cpp b/source/DrawV2.cpp index 6c9acd1..5004c5f 100644 --- a/source/DrawV2.cpp +++ b/source/DrawV2.cpp @@ -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); } diff --git a/source/Overlays.cpp b/source/Overlays.cpp index cf44f0d..cc57bce 100644 --- a/source/Overlays.cpp +++ b/source/Overlays.cpp @@ -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() { diff --git a/source/UI7.cpp b/source/UI7.cpp index 8a566d6..04469ce 100644 --- a/source/UI7.cpp +++ b/source/UI7.cpp @@ -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 &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 &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); }