aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/DropdownButton.cpp11
-rw-r--r--src/gui/FileChooser.cpp39
2 files changed, 30 insertions, 20 deletions
diff --git a/src/gui/DropdownButton.cpp b/src/gui/DropdownButton.cpp
index b9b962f..28c1b5b 100644
--- a/src/gui/DropdownButton.cpp
+++ b/src/gui/DropdownButton.cpp
@@ -15,9 +15,8 @@ namespace gsr {
static const float icon_spacing_scale = 0.008f;
static const float border_scale = 0.003f;
- DropdownButton::DropdownButton(mgl::Font *title_font, mgl::Font *description_font, const char *title, const char *description_activated, const char *description_deactivated, mgl::Texture *icon_texture, mgl::vec2f size) :
- title_font(title_font), description_font(description_font), size(size), title(title, *title_font), description(description_deactivated, *description_font),
- description_activated(description_activated), description_deactivated(description_deactivated)
+ DropdownButton::DropdownButton(mgl::Font *title_font, mgl::Font *description_font, const char *title, const char *description, mgl::Texture *icon_texture, mgl::vec2f size) :
+ title_font(title_font), description_font(description_font), size(size), title(title, *title_font), description(description, *description_font)
{
if(icon_texture && icon_texture->is_valid()) {
icon_sprite.set_texture(icon_texture);
@@ -202,6 +201,10 @@ namespace gsr {
}
}
+ void DropdownButton::set_description(std::string description_text) {
+ description.set_string(std::move(description_text));
+ }
+
void DropdownButton::set_activated(bool activated) {
if(this->activated == activated)
return;
@@ -209,11 +212,9 @@ namespace gsr {
this->activated = activated;
if(activated) {
- description = mgl::Text(description_activated, *description_font);
description.set_color(get_theme().tint_color);
icon_sprite.set_color(get_theme().tint_color);
} else {
- description = mgl::Text(description_deactivated, *description_font);
description.set_color(mgl::Color(150, 150, 150));
icon_sprite.set_color(mgl::Color(255, 255, 255));
}
diff --git a/src/gui/FileChooser.cpp b/src/gui/FileChooser.cpp
index 8ec498f..d445ccf 100644
--- a/src/gui/FileChooser.cpp
+++ b/src/gui/FileChooser.cpp
@@ -223,15 +223,36 @@ namespace gsr {
current_directory_padding_top_scale * get_theme().window_height + current_directory_padding_bottom_scale * get_theme().window_height
);
- mgl::vec2f current_directory_background_size = mgl::vec2f(size.x, current_directory_text.get_bounds().size.y + current_directory_padding.y).floor();
+ const float current_directory_background_height = (int)(current_directory_text.get_bounds().size.y + current_directory_padding.y);
+
+ draw_pos += mgl::vec2f(0.0f, current_directory_background_height + spacing_between_current_directory_and_content * get_theme().window_height);
+ const mgl::vec2f body_size = mgl::vec2f(size.x, size.y - (draw_pos.y - draw_pos_start.y)).floor();
+ scrollable_page.set_size(body_size);
+ file_chooser_body_ptr->set_size(scrollable_page.get_inner_size());
+ mgl::Rectangle content_background(scrollable_page.get_inner_size().floor());
+ content_background.set_position(draw_pos.floor());
+ content_background.set_color(mgl::Color(0, 0, 0, 120));
+ window.draw(content_background);
+
+ draw_navigation(window, draw_pos_start);
+
+ scrollable_page.draw(window, draw_pos.floor());
+ }
+
+ void FileChooser::draw_navigation(mgl::Window &window, mgl::vec2f draw_pos) {
+ const mgl::vec2f current_directory_padding(
+ current_directory_padding_left_scale * get_theme().window_height + current_directory_padding_right_scale * get_theme().window_height,
+ current_directory_padding_top_scale * get_theme().window_height + current_directory_padding_bottom_scale * get_theme().window_height
+ );
+ mgl::vec2f current_directory_background_size = mgl::vec2f(size.x, current_directory_text.get_bounds().size.y + current_directory_padding.y).floor();
up_arrow_sprite.set_height((int)(current_directory_background_size.y * 0.8f));
- up_arrow_sprite.set_position((draw_pos + mgl::vec2f(size.x - up_arrow_sprite.get_size().x, current_directory_background_size.y * 0.5f - up_arrow_sprite.get_size().y * 0.5f)).floor());
+ up_arrow_sprite.set_position((draw_pos + mgl::vec2f(file_chooser_body_ptr->get_size().x - up_arrow_sprite.get_size().x, current_directory_background_size.y * 0.5f - up_arrow_sprite.get_size().y * 0.5f)).floor());
const bool mouse_inside_up_arrow = mgl::FloatRect(up_arrow_sprite.get_position(), up_arrow_sprite.get_size()).contains(window.get_mouse_position().to_vec2f()) && !has_parent_with_selected_child_widget();
up_arrow_sprite.set_color(mouse_inside_up_arrow ? get_theme().tint_color : mgl::Color(255, 255, 255));
window.draw(up_arrow_sprite);
- current_directory_background_size.x -= (up_arrow_sprite.get_size().x + up_button_spacing_scale * get_theme().window_height);
+ current_directory_background_size.x = file_chooser_body_ptr->get_size().x - up_arrow_sprite.get_size().x - up_button_spacing_scale * get_theme().window_height;
mgl::Rectangle current_directory_background(current_directory_background_size.floor());
current_directory_background.set_color(mgl::Color(0, 0, 0, 120));
current_directory_background.set_position(draw_pos.floor());
@@ -240,18 +261,6 @@ namespace gsr {
current_directory_text.set_color(get_theme().text_color);
current_directory_text.set_position((draw_pos + mgl::vec2f(current_directory_padding.x, current_directory_background_size.y * 0.5f - current_directory_text.get_bounds().size.y * 0.5f)).floor());
window.draw(current_directory_text);
-
- draw_pos += mgl::vec2f(0.0f, current_directory_background_size.y + spacing_between_current_directory_and_content * get_theme().window_height);
- const mgl::vec2f body_size = mgl::vec2f(size.x, size.y - (draw_pos.y - draw_pos_start.y)).floor();
- scrollable_page.set_size(body_size);
- file_chooser_body_ptr->set_size(scrollable_page.get_inner_size());
-
- mgl::Rectangle content_background(scrollable_page.get_inner_size().floor());
- content_background.set_position(draw_pos.floor());
- content_background.set_color(mgl::Color(0, 0, 0, 120));
- window.draw(content_background);
-
- scrollable_page.draw(window, draw_pos.floor());
}
mgl::vec2f FileChooser::get_size() {