Change fonts, nicer combobox, add/remove audio track button

This commit is contained in:
dec05eba
2024-08-06 03:11:43 +02:00
parent ae1897cf2c
commit b778fd7cc6
15 changed files with 239 additions and 92 deletions

View File

@@ -1,6 +1,11 @@
#pragma once
#include <mglpp/system/MemoryMappedFile.hpp>
#include <mglpp/graphics/Color.hpp>
#include <mglpp/graphics/Font.hpp>
#include <mglpp/graphics/Texture.hpp>
#include <string>
namespace gsr {
struct GsrInfo;
@@ -10,12 +15,22 @@ namespace gsr {
Theme(const Theme&) = delete;
Theme& operator=(const Theme&) = delete;
float window_height = 0.0f;
mgl::Color tint_color = mgl::Color(118, 185, 0);
mgl::Color scrollable_page_bg_color = mgl::Color(38, 43, 47);
mgl::Color text_color = mgl::Color(255, 255, 255);
mgl::MemoryMappedFile body_font_file;
mgl::MemoryMappedFile title_font_file;
mgl::Font body_font;
mgl::Font title_font;
mgl::Font top_bar_font;
mgl::Texture combobox_arrow;
};
void init_theme(const gsr::GsrInfo &gsr_info);
bool init_theme(const gsr::GsrInfo &gsr_info, mgl::vec2i window_size, const std::string &resources_path);
void deinit_theme();
const Theme& get_theme();
Theme& get_theme();
}

View File

@@ -9,6 +9,8 @@
namespace gsr {
class Button : public Widget {
public:
// If width is 0 then the width of the text is used instead (with padding).
// If height is 0 then the height of the text is used instead (with padding).
Button(mgl::Font *font, const char *text, mgl::vec2f size, mgl::Color bg_color);
Button(const Button&) = delete;
Button& operator=(const Button&) = delete;
@@ -16,7 +18,7 @@ namespace gsr {
bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override;
void draw(mgl::Window &window, mgl::vec2f offset) override;
mgl::vec2f get_size() override { return size; }
mgl::vec2f get_size() override;
std::function<void()> on_click;
private:

View File

@@ -2,6 +2,7 @@
#include "Widget.hpp"
#include <mglpp/graphics/Text.hpp>
#include <mglpp/graphics/Sprite.hpp>
#include <string>
#include <vector>
@@ -21,6 +22,7 @@ namespace gsr {
mgl::vec2f get_size() override;
private:
void update_if_dirty();
float get_dropdown_arrow_height() const;
private:
struct Item {
mgl::Text text;
@@ -30,6 +32,7 @@ namespace gsr {
mgl::vec2f max_size;
mgl::Font *font;
std::vector<Item> items;
mgl::Sprite dropdown_arrow;
bool dirty = true;
bool show_dropdown = false;
size_t selected_item = 0;

View File

@@ -25,10 +25,19 @@ namespace gsr {
bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override;
void draw(mgl::Window &window, mgl::vec2f offset) override;
//void remove_child_widget(Widget *widget) override;
void add_widget(std::unique_ptr<Widget> widget);
void remove_widget(Widget *widget);
mgl::vec2f get_size() override;
private:
void update();
void remove_widget_immediate(Widget *widget);
protected:
std::vector<std::unique_ptr<Widget>> widgets;
std::vector<std::unique_ptr<Widget>> add_queue;
std::vector<Widget*> remove_queue;
Orientation orientation;
Alignment content_alignment;
};

View File

@@ -12,6 +12,8 @@ namespace gsr {
Page& operator=(const Page&) = delete;
virtual ~Page() = default;
//void remove_child_widget(Widget *widget) override;
void add_widget(std::unique_ptr<Widget> widget);
protected:
std::vector<std::unique_ptr<Widget>> widgets;

View File

@@ -24,6 +24,8 @@ namespace gsr {
virtual void draw(mgl::Window &window, mgl::vec2f offset) = 0;
virtual void set_position(mgl::vec2f position);
//virtual void remove_child_widget(Widget *widget) { (void)widget; }
virtual mgl::vec2f get_position() const;
virtual mgl::vec2f get_size() = 0;
protected: