14#include <imgui_internal.h>
27 const char*
begin = str.data();
28 const char*
end =
begin + str.size();
33 const char*
begin = str.data();
34 const char*
end =
begin + str.size();
43template<
typename... Ts>
46 auto s =
tmpStrCat(std::forward<Ts>(ts)...);
50inline void RightAlignText(std::string_view text, std::string_view maxWidthText)
54 if (
auto spacing = maxWidth - actualWidth; spacing > 0.0f) {
55 auto pos = ImGui::GetCursorPosX();
56 ImGui::SetCursorPosX(pos + spacing);
70class VideoSourceSetting;
80 if (desc.empty())
return;
90 if (!ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip))
return;
91 auto desc = std::invoke(descFunc);
92 if (desc.empty())
return;
103 const char* label,
gl::vec2 size,
bool pressed,
104 std::invocable<gl::vec2 /*center*/, ImDrawList*>
auto render)
107 im::StyleColor(pressed, ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_ButtonActive), [&]{
108 gl::vec2 topLeft = ImGui::GetCursorScreenPos();
109 gl::vec2 center = topLeft + size * 0.5f;
110 result = ImGui::Button(label, size);
111 render(center, ImGui::GetWindowDrawList());
118 std::invocable<gl::vec2 /*center*/, ImDrawList*>
auto render)
125 std::array<char, 2 + 5> label = {
'#',
'#'};
128 const auto& style = ImGui::GetStyle();
129 auto buttonSize = maxGlyphSize + 2.0f*
gl::vec2(style.FramePadding);
132 const auto* font = ImGui::GetFont();
133 auto texId = font->ContainerAtlas->TexID;
134 const auto* g = font->FindGlyph(glyph);
135 auto halfSize = gl::vec2{g->X1 - g->X0, g->Y1 - g->Y0} * 0.5f;
136 drawList->AddImage(texId, center - halfSize, center + halfSize, {
g->U0,
g->V0}, {
g->U1,
g->V1});
142 static constexpr gl::vec2 center{0.5f, 0.5f};
143 gl::vec2 windowPos = ImGui::GetWindowPos();
144 gl::vec2 windowSize = ImGui::GetWindowSize();
145 auto windowCenter = windowPos + center * windowSize;
146 ImGui::SetNextWindowPos(windowCenter, ImGuiCond_Appearing, center);
155bool SliderInt(IntegerSetting&
setting, ImGuiSliderFlags flags = 0);
156bool SliderInt(
const char* label, IntegerSetting&
setting, ImGuiSliderFlags flags = 0);
157bool SliderFloat(FloatSetting&
setting,
const char* format =
"%.3f", ImGuiSliderFlags flags = 0);
158bool SliderFloat(
const char* label, FloatSetting&
setting,
const char* format =
"%.3f", ImGuiSliderFlags flags = 0);
159bool InputText(Setting&
setting);
160bool InputText(
const char* label, Setting&
setting);
161void ComboBox(Setting&
setting, EnumToolTips toolTips = {});
162void ComboBox(
const char* label, Setting&
setting, EnumToolTips toolTips = {});
163void ComboBox(
const char* label, Setting&
setting,
function_ref<std::string(
const std::string&)> displayValue, EnumToolTips toolTips = {});
167const char*
getComboString(
int item,
const char* itemsSeparatedByZeros);
169std::string
formatTime(std::optional<double> time);
170float calculateFade(
float current,
float target,
float period);
172template<
int HexDigits>
174 assert(offset < mult);
175 *value &= ~(mult - 1);
177 auto preview =
tmpStrCat(
"0x", hex_string<HexDigits>(*value | offset));
179 for (int addr = 0; addr < max; addr += mult) {
180 if (auto str = tmpStrCat(
"0x", hex_string<HexDigits>(addr | offset));
181 ImGui::Selectable(str.c_str(), *value == addr)) {
184 if (*value == addr) {
185 ImGui::SetItemDefaultFocus();
191template<
typename Range,
typename Projection>
192void sortUpDown_T(Range& range,
const ImGuiTableSortSpecs* sortSpecs, Projection proj) {
193 if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Descending) {
199template<
typename Range,
typename Projection>
201 if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Descending) {
210 const std::vector<std::pair<std::string, std::string>>& info,
211 std::string_view key)
213 auto it =
ranges::find_if(info, [&](
const auto& p) {
return p.first == key; });
214 if (it == info.end())
return {};
219[[nodiscard]] std::vector<std::string>
getAllValuesFor(std::string_view key,
const std::vector<T>& items)
221 std::vector<std::string> result;
222 for (
const auto& item : items) {
225 result.emplace_back(*value);
236 im::Combo(key.
c_str(), selection.empty() ?
"--all--" : selection.c_str(), [&]{
237 if (ImGui::Selectable(
"--all--")) {
241 if (ImGui::Selectable(type.c_str())) {
249void applyComboFilter(std::string_view key, std::string_view value,
const std::vector<T>& items, std::vector<size_t>& indices)
251 if (value.empty())
return;
252 std::erase_if(indices, [&](
auto idx) {
253 const auto& info = items[idx].configInfo;
255 if (!val)
return true;
256 return *val != value;
260template<std::invocable<
size_t> GetName>
261void filterIndices(std::string_view filterString, GetName getName, std::vector<size_t>& indices)
263 if (filterString.empty())
return;
264 std::erase_if(indices, [&](
auto idx) {
265 const auto& name = getName(idx);
266 return !
ranges::all_of(StringOp::split_view<StringOp::EmptyParts::REMOVE>(filterString,
' '),
274 filterIndices(filterString, [&](
size_t idx) {
return items[idx].displayName; }, indices);
278template<
typename Range,
typename BinaryPred,
typename Action>
279static void chunk_by(Range&& range, BinaryPred pred, Action action)
281 auto it = std::begin(range);
282 auto last = std::end(range);
286 while (it != last && pred(*prev, *it)) {
296std::optional<ImGuiKeyChord>
parseKeyChord(std::string_view name);
302 VramTable(std::span<const uint8_t> vram_,
bool planar_ =
false)
303 : vram(vram_), planar(planar_) {}
306 registerMask = (value << extraLsbBits) | ~(~0u << extraLsbBits);
309 indexMask = ~0u << bits;
313 return registerMask & (indexMask | index);
316 auto addr = getAddress(index);
318 addr = ((addr << 16) | (addr >> 1)) & 0x1'FFFF;
323 std::span<const uint8_t> vram;
324 unsigned registerMask = 0;
325 unsigned indexMask = 0;
355inline std::array<ImU32, size_t(imColor::NUM_COLORS)>
imColors;
360 assert(col < imColor::NUM_COLORS);
void setRegister(unsigned value, unsigned extraLsbBits)
auto getAddress(unsigned index) const
VramTable(std::span< const uint8_t > vram_, bool planar_=false)
uint8_t operator[](unsigned index) const
void setIndexSize(unsigned bits)
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
constexpr const char * c_str() const
const char * ImTextCharToUtf8(char out_buf[5], unsigned int c)
auto CalcTextSize(std::string_view str)
void TextUnformatted(const std::string &str)
void RightAlignText(std::string_view text, std::string_view maxWidthText)
bool containsCaseInsensitive(std::string_view haystack, std::string_view needle)
void Combo(const char *label, const char *preview_value, ImGuiComboFlags flags, std::invocable<> auto next)
void StyleColor(bool active, Args &&...args)
void TextWrapPos(float wrap_local_pos_x, std::invocable<> auto next)
void Tooltip(std::invocable<> auto next)
void ItemTooltip(std::invocable<> auto next)
This file implemented 3 utility functions:
bool Checkbox(const HotKey &hotKey, BooleanSetting &setting)
std::span< const EnumToolTip > EnumToolTips
void centerNextWindowOverCurrent()
void filterIndices(std::string_view filterString, GetName getName, std::vector< size_t > &indices)
void ComboBox(const char *label, Setting &setting, function_ref< std::string(const std::string &)> displayValue, EnumToolTips toolTips)
void applyComboFilter(std::string_view key, std::string_view value, const std::vector< T > &items, std::vector< size_t > &indices)
void sortUpDown_String(Range &range, const ImGuiTableSortSpecs *sortSpecs, Projection proj)
void simpleToolTip(std::string_view desc)
std::vector< std::string > getAllValuesFor(std::string_view key, const std::vector< T > &items)
std::string getShortCutForCommand(const HotKey &hotkey, std::string_view command)
std::array< ImU32, size_t(imColor::NUM_COLORS)> imColors
void sortUpDown_T(Range &range, const ImGuiTableSortSpecs *sortSpecs, Projection proj)
void displayFilterCombo(std::string &selection, zstring_view key, const std::vector< T > &items)
void HelpMarker(std::string_view desc)
const std::string * getOptionalDictValue(const std::vector< std::pair< std::string, std::string > > &info, std::string_view key)
ImU32 getColor(imColor col)
std::optional< ImGuiKeyChord > parseKeyChord(std::string_view name)
const char * getComboString(int item, const char *itemsSeparatedByZeros)
void setColors(int style)
std::string getKeyChordName(ImGuiKeyChord keyChord)
void comboHexSequence(const char *label, int *value, int mult, int max, int offset)
void applyDisplayNameFilter(std::string_view filterString, const std::vector< T > &items, std::vector< size_t > &indices)
bool ButtonWithCenteredGlyph(ImWchar glyph, gl::vec2 maxGlyphSize)
std::string formatTime(std::optional< double > time)
float calculateFade(float current, float target, float period)
bool ButtonWithCustomRendering(const char *label, gl::vec2 size, bool pressed, std::invocable< gl::vec2, ImDrawList * > auto render)
constexpr bool all_of(InputRange &&range, UnaryPredicate pred)
auto find_if(InputRange &&range, UnaryPredicate pred)
void stable_sort(RandomAccessRange &&range)
constexpr void sort(RandomAccessRange &&range)
constexpr bool contains(ITER first, ITER last, const VAL &val)
Check if a range contains a given value, using linear search.
TemporaryString tmpStrCat(Ts &&... ts)
constexpr auto begin(const zstring_view &x)
constexpr auto end(const zstring_view &x)