mirror of
https://gitlab.com/square-game-liberation-front/F.E.I.S.git
synced 2025-02-28 23:41:33 +01:00
Replace preview music Play/Stop buttons with an icon button
This commit is contained in:
parent
da7bbaaeec
commit
46575cebdf
@ -682,11 +682,11 @@ void EditorState::display_file_properties() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (music_preview_is_playing()) {
|
if (music_preview_is_playing()) {
|
||||||
if (ImGui::Button("Stop##Mucic Preview")) {
|
if (feis::StopButton("##Stop Mucic Preview")) {
|
||||||
stop_music_preview();
|
stop_music_preview();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ImGui::Button("Play##Music Preview")) {
|
if (ImGui::ArrowButton("##Play Music Preview", ImGuiDir_Right)) {
|
||||||
play_music_preview();
|
play_music_preview();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
#include "imgui_extras.hpp"
|
#include "imgui_extras.hpp"
|
||||||
|
|
||||||
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
#include <imgui_stdlib.h>
|
#include <imgui_stdlib.h>
|
||||||
#include "imgui.h"
|
#include "imgui_internal.h"
|
||||||
|
|
||||||
bool feis::ColorEdit4(const char* label, sf::Color& col, ImGuiColorEditFlags flags) {
|
bool feis::ColorEdit4(const char* label, sf::Color& col, ImGuiColorEditFlags flags) {
|
||||||
float array_col[4] = {
|
float array_col[4] = {
|
||||||
@ -87,3 +90,14 @@ void feis::HelpMarker(const char* desc) {
|
|||||||
ImGui::EndTooltip();
|
ImGui::EndTooltip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool feis::StopButton(const char* str_id) {
|
||||||
|
return IconButton(str_id, [](const ImRect& bb, const ImU32& color){
|
||||||
|
const auto size = sf::Vector2f{bb.GetSize()};
|
||||||
|
ImGui::GetWindowDrawList()->AddRectFilled(
|
||||||
|
sf::Vector2f{bb.Min} + size / 4.f,
|
||||||
|
sf::Vector2f{bb.Max} - size / 4.f + sf::Vector2f{1.f, 1.f},
|
||||||
|
color
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <SFML/System/Vector2.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <SFML/Graphics/Color.hpp>
|
#include <SFML/Graphics/Color.hpp>
|
||||||
#include <imgui-SFML_export.h>
|
#include <imgui-SFML_export.h>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
#include <imgui_internal.h>
|
||||||
|
|
||||||
#include "special_numeric_types.hpp"
|
#include "special_numeric_types.hpp"
|
||||||
|
|
||||||
@ -23,6 +25,40 @@ namespace feis {
|
|||||||
const ImGuiInputTextFlags flags = ImGuiInputTextFlags_None
|
const ImGuiInputTextFlags flags = ImGuiInputTextFlags_None
|
||||||
);
|
);
|
||||||
void HelpMarker(const char* desc);
|
void HelpMarker(const char* desc);
|
||||||
|
bool StopButton(const char* str_id);
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
bool IconButton(const char* str_id, const T& draw_icon) {
|
||||||
|
float sz = ImGui::GetFrameHeight();
|
||||||
|
sf::Vector2f size{sz, sz};
|
||||||
|
ImGuiButtonFlags flags = ImGuiButtonFlags_None;
|
||||||
|
auto window = ImGui::GetCurrentWindow();
|
||||||
|
if (window->SkipItems) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGuiContext& g = *GImGui;
|
||||||
|
const ImGuiID id = window->GetID(str_id);
|
||||||
|
const ImRect bb(window->DC.CursorPos, sf::Vector2f(window->DC.CursorPos) + size);
|
||||||
|
const float default_size = ImGui::GetFrameHeight();
|
||||||
|
ImGui::ItemSize(size, (size.y >= default_size) ? g.Style.FramePadding.y : -1.0f);
|
||||||
|
if (!ImGui::ItemAdd(bb, id))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (g.LastItemData.InFlags & ImGuiItemFlags_ButtonRepeat)
|
||||||
|
flags |= ImGuiButtonFlags_Repeat;
|
||||||
|
|
||||||
|
bool hovered, held;
|
||||||
|
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held, flags);
|
||||||
|
|
||||||
|
// Render
|
||||||
|
const ImU32 bg_col = ImGui::GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
|
||||||
|
const ImU32 text_col = ImGui::GetColorU32(ImGuiCol_Text);
|
||||||
|
ImGui::RenderNavHighlight(bb, id);
|
||||||
|
ImGui::RenderFrame(bb.Min, bb.Max, bg_col, true, g.Style.FrameRounding);
|
||||||
|
draw_icon(bb, text_col);
|
||||||
|
return pressed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace colors {
|
namespace colors {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user