# Stage 2.2

- Move Timer to core
- Use Timer for app_time
- Fix Deltatime Bug in App
- Add HwInfo to lib3ds (stolen from hbloader 2 pd-rewrite port)
- Add GetSystemLanguage to lib3ds
- Add Net Header for pd-net (still need to find a way to make this working)
- Add base Decoder and Player Headers for pd-sound
- Add Mp3 Decoder (useless and untested yet)
- Add GetDataDirectory to App
- Add InitFLag to App for HwInfo
- Actually write the Timer class
- Rework the UI7 Theme API to use SmartCtor
- UI7::Menu::JoinAlign: Use a loop to determinate max width for centering a group
- Add some Doctumentation around UI7::Menu
This commit is contained in:
2025-02-28 19:49:24 +01:00
parent f9a1d8aefb
commit debedf59c6
27 changed files with 840 additions and 98 deletions

View File

@ -34,8 +34,8 @@ namespace PD {
namespace UI7 {
class Menu : public SmartCtor<Menu> {
public:
Menu(ID id, Theme* tl, Hid::Ref h) {
linked_theme = tl;
Menu(ID id, Theme::Ref tl, Hid::Ref h) {
theme = tl;
this->inp = h;
this->id = id;
this->name = id.GetName();
@ -48,37 +48,97 @@ class Menu : public SmartCtor<Menu> {
};
~Menu() {}
/// Objects
/// Objects ///
/// @brief Render a Simple Label
/// @param label The text to draw
void Label(const std::string& label);
/// @brief Render a Button
/// @param label The buttons text
/// @return if the button was pressed
bool Button(const std::string& label);
/// @brief Render a Checkbox
/// @param label Label of the Checkbox
/// @param v A value to update
void Checkbox(const std::string& label, bool& v);
/// @brief Render an Image
/// @param img Texture reference of the image
/// @param size a Custom Size if needed
void Image(Texture::Ref img, vec2 size = 0.f);
/// Basic API
/// Basic API ///
/// @brief Add the Next object to the same line
void SameLine();
/// @brief Add a Separator Line
void Separator();
/// @brief Render a Separator Line with a Text
/// @todo determinate text position by current alignment
/// @param label The Text to show
void SeparatorText(const std::string& label);
/// @brief Put the last Added Object into the Joinlist
void Join();
/// @brief Add the Last element to the join list
/// and perform an alignment operation
/// @param a Alignment Oeration(s)
void JoinAlign(UI7Align a);
/// @brief Align the Last Object
/// @param a Alignment Operation
void AfterAlign(UI7Align a);
/// @brief Set a Temp alignment op for the next Object
/// @param a Alignment Operation
void NextAlign(UI7Align a) { tmpalign = a; }
/// @brief Align Every Single Object by this operationset
/// @param a Alignment
void PushAlignment(UI7Align a) { alignment = a; }
/// @brief Use default alignment
void PopAlignment() { alignment = UI7Align_Default; }
/// @brief Get a New Position depending on the Alignment
/// @param pos Current Position
/// @param size Object size
/// @param view Viewport [position and size]
/// @param a Alignment Operations
/// @return new position based on the alignment
static vec2 AlignPos(vec2 pos, vec2 size, vec4 view, UI7Align a);
/// @brief Returns a Reference to the theme
/// @return Reference to the base Theme of the context
Theme::Ref GetTheme() { return theme; }
/// @brief Directly return a Color by using the
/// m->ThemeColor(UI7Color_Text) for example
/// @param clr The Input UI7 Color
/// @return The 32bit color value
u32 ThemeColor(UI7Color clr) const { return theme->Get(clr); }
/// API for Custom Objects
/// @brief Handles the Position of Objects in Scrolling Menu
/// @note As Containers have their own FUnc to handle this, this
/// function is only useful to Render Live Objects whicch cannot be aligned
/// by the internal Alignment Api
/// @param pos position reference to write the new position to
/// @param size size of the Object
/// @return if the object can be skipped in rendering
bool HandleScrolling(vec2& pos, const vec2& size);
/// @brief Get the Cursor Position
/// @return Cursor Pos
vec2 Cursor() const { return cursor; }
/// @brief Set the Cursor position
/// @note The old Position can be restored with RestoreCursor
/// @param v New Position
void Cursor(const vec2& v) {
bcursor = cursor;
cursor = v;
}
/// @brief Restore to the last cursor Position
void RestoreCursor() {
cursor = bcursor;
bcursor = vec2();
}
/// @brief Return if a Vertical Scrollbar exists
bool HasVerticalScrollbar() { return scrollbar[1]; }
/// @brief Return if a Horizontal Scrollbar exists
bool HasHorizontalScrollbar() { return scrollbar[0]; }
/// @brief Get the Titlebar height
float TitleBarHeight() { return tbh; }
/// @brief Set a Custom Titlebar heigt
/// @note Could destroy some basic functionality
@ -86,39 +146,72 @@ class Menu : public SmartCtor<Menu> {
/// @brief Init the Cursor
/// @note Useful when using with a Custom TitlebarHeight
void CursorInit() { Cursor(vec2(5, tbh + 5)); }
/// @brief Move the Cursor for new Object
/// @param szs Size of the current Object
void CursorMove(const vec2& szs);
/// @brief Get the ViewArea of the Menu
vec4 ViewArea() const { return view_area; }
/// @brief Get the Main Area of the Menu
/// (only relevant for input)
vec4 MainArea() const { return main_area; }
/// @brief Set a MainArea for input
/// @param v Area where Objects can receive inputs
void MainArea(const vec4& v) { main_area = v; }
/// @brief Get The Scrolling offset
vec2 ScrollOffset() const { return scrolling_off; }
/// @brief Set a Scrolling offset
/// @param v Custom Scrolling offset
void ScrollOffset(const vec2& v) { scrolling_off = v; }
/// @brief Get the Current Scrollmodification value
vec2 ScrollMod() const { return scroll_mod; }
/// @brief Animated Scroll to Position
/// @param pos Destination Position
void ScrollTo(vec2 pos) {
scroll_anim.From(scrolling_off)
.To(pos)
.In(1.f)
.As(scroll_anim.EaseInOutSine);
}
/// @brief Check if Still in ScrollAnimation
bool IsAnimatedScroll() { return !scroll_anim.IsFinished(); }
/// Objects API
/// Objects API ///
/// @brief Push an object to the current ListHandler
/// @param obj Object reference to use
/// @return Reference to the Object (from a time
/// where ObjectPush(Container::New()) was used)
Container::Ref ObjectPush(Container::Ref obj);
/// @brief Search for an Object by an id
/// @param id 32 Bit hash/id
/// @return the found Object or nullptr
Container::Ref FindIDObj(u32 id);
/// Draw Lists
/// Draw Lists ///
/// @brief Background Layer Drawlist
DrawList::Ref BackList() { return back; }
/// @brief Setter for Background Layer Drawlist
void BackList(DrawList::Ref v) { back = v; }
/// @brief Main Layer Drawlist
DrawList::Ref MainList() { return main; }
/// @brief Setter for Main Layer Drawlist
void MainList(DrawList::Ref v) { main = v; }
/// @brief Foreground Layer Drawlist
DrawList::Ref FrontList() { return front; }
/// @brief Setter for Foreground Layer Drawlist
void FrontList(DrawList::Ref v) { front = v; }
/// Advanced
/// Advanced ///
/// @brief Display Debug Labels of the Menu
void DebugLabels();
/// Uneditable Stuff
/// Uneditable Stuff ///
/// @brief Menu Name
std::string GetName() const { return name; }
/// @brief Menu ID [Hash of the Name]
u32 GetID() const { return id; }
private:
@ -166,7 +259,7 @@ class Menu : public SmartCtor<Menu> {
bool scroll_allowed[2];
bool has_touch;
Menu::Ref submenu;
Container::Ref tmp_parent;
/// Objects API
std::vector<Container::Ref> objects;
@ -186,7 +279,7 @@ class Menu : public SmartCtor<Menu> {
vec2 last_size;
// Theme
Theme* linked_theme;
Theme::Ref theme;
// Input Reference
Hid::Ref inp;