15#include <imgui_internal.h>
28 const char*
begin = str.data();
29 const char*
end =
begin + str.size();
34 const char*
begin = str.data();
35 const char*
end =
begin + str.size();
44template<
typename... Ts>
47 auto s =
tmpStrCat(std::forward<Ts>(ts)...);
51inline void RightAlignText(std::string_view text, std::string_view maxWidthText)
55 if (
auto spacing = maxWidth - actualWidth; spacing > 0.0f) {
56 auto pos = ImGui::GetCursorPosX();
57 ImGui::SetCursorPosX(pos + spacing);
71class VideoSourceSetting;
81 if (desc.empty())
return;
91 if (!ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip))
return;
92 auto desc = std::invoke(descFunc);
93 if (desc.empty())
return;
104 const char* label,
gl::vec2 size,
bool pressed,
105 std::invocable<gl::vec2 /*center*/, ImDrawList*>
auto render)
108 im::StyleColor(pressed, ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_ButtonActive), [&]{
109 gl::vec2 topLeft = ImGui::GetCursorScreenPos();
110 gl::vec2 center = topLeft + size * 0.5f;
111 result = ImGui::Button(label, size);
112 render(center, ImGui::GetWindowDrawList());
119 std::invocable<gl::vec2 /*center*/, ImDrawList*>
auto render)
126 std::array<char, 2 + 5> label = {
'#',
'#'};
129 const auto& style = ImGui::GetStyle();
130 auto buttonSize = maxGlyphSize + 2.0f*
gl::vec2(style.FramePadding);
133 const auto* font = ImGui::GetFont();
134 auto texId = font->ContainerAtlas->TexID;
135 const auto* g = font->FindGlyph(glyph);
136 auto halfSize = gl::vec2{g->X1 - g->X0, g->Y1 - g->Y0} * 0.5f;
137 drawList->AddImage(texId, center - halfSize, center + halfSize, {
g->U0,
g->V0}, {
g->U1,
g->V1});
143 static constexpr gl::vec2 center{0.5f, 0.5f};
144 gl::vec2 windowPos = ImGui::GetWindowPos();
145 gl::vec2 windowSize = ImGui::GetWindowSize();
146 auto windowCenter = windowPos + center * windowSize;
147 ImGui::SetNextWindowPos(windowCenter, ImGuiCond_Appearing, center);
156bool SliderInt(IntegerSetting&
setting, ImGuiSliderFlags flags = 0);
157bool SliderInt(
const char* label, IntegerSetting&
setting, ImGuiSliderFlags flags = 0);
158bool SliderFloat(FloatSetting&
setting,
const char* format =
"%.3f", ImGuiSliderFlags flags = 0);
159bool SliderFloat(
const char* label, FloatSetting&
setting,
const char* format =
"%.3f", ImGuiSliderFlags flags = 0);
160bool InputText(Setting&
setting);
161bool InputText(
const char* label, Setting&
setting);
162void ComboBox(Setting&
setting, EnumToolTips toolTips = {});
163void ComboBox(
const char* label, Setting&
setting, EnumToolTips toolTips = {});
164void ComboBox(
const char* label, Setting&
setting,
function_ref<std::string(
const std::string&)> displayValue, EnumToolTips toolTips = {});
168const char*
getComboString(
int item,
const char* itemsSeparatedByZeros);
170std::string
formatTime(std::optional<double> time);
171float calculateFade(
float current,
float target,
float period);
173template<
int HexDigits>
175 assert(offset < mult);
176 *value &= ~(mult - 1);
178 auto preview =
tmpStrCat(
"0x", hex_string<HexDigits>(*value | offset));
180 for (int addr = 0; addr < max; addr += mult) {
181 if (auto str = tmpStrCat(
"0x", hex_string<HexDigits>(addr | offset));
182 ImGui::Selectable(str.c_str(), *value == addr)) {
185 if (*value == addr) {
186 ImGui::SetItemDefaultFocus();
192template<
typename Range,
typename Projection>
193void sortUpDown_T(Range& range,
const ImGuiTableSortSpecs* sortSpecs, Projection proj) {
194 if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Descending) {
200template<
typename Range,
typename Projection>
202 if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Descending) {
211 const std::vector<std::pair<std::string, std::string>>& info,
212 std::string_view key)
214 auto it =
ranges::find_if(info, [&](
const auto& p) {
return p.first == key; });
215 if (it == info.end())
return {};
220[[nodiscard]] std::vector<std::string>
getAllValuesFor(std::string_view key,
const std::vector<T>& items)
222 std::vector<std::string> result;
223 for (
const auto& item : items) {
226 result.emplace_back(*value);
237 im::Combo(key.
c_str(), selection.empty() ?
"--all--" : selection.c_str(), [&]{
238 if (ImGui::Selectable(
"--all--")) {
242 if (ImGui::Selectable(type.c_str())) {
250void applyComboFilter(std::string_view key, std::string_view value,
const std::vector<T>& items, std::vector<size_t>& indices)
252 if (value.empty())
return;
253 std::erase_if(indices, [&](
auto idx) {
254 const auto& info = items[idx].configInfo;
256 if (!val)
return true;
257 return *val != value;
261template<std::invocable<
size_t> GetName>
262void filterIndices(std::string_view filterString, GetName getName, std::vector<size_t>& indices)
264 if (filterString.empty())
return;
265 std::erase_if(indices, [&](
auto idx) {
266 const auto& name = getName(idx);
267 return !
ranges::all_of(StringOp::split_view<StringOp::EmptyParts::REMOVE>(filterString,
' '),
275 filterIndices(filterString, [&](
size_t idx) {
return items[idx].displayName; }, indices);
281 if (
auto it =
ranges::find(recentItems, item); it != recentItems.
end()) {
283 std::rotate(recentItems.
begin(), it, it + 1);
292template<
typename Range,
typename BinaryPred,
typename Action>
293static void chunk_by(Range&& range, BinaryPred pred, Action action)
295 auto it = std::begin(range);
296 auto last = std::end(range);
300 while (it != last && pred(*prev, *it)) {
310std::optional<ImGuiKeyChord>
parseKeyChord(std::string_view name);
316 VramTable(std::span<const uint8_t> vram_,
bool planar_ =
false)
317 : vram(vram_), planar(planar_) {}
320 registerMask = (value << extraLsbBits) | ~(~0u << extraLsbBits);
323 indexMask = ~0u << bits;
327 return registerMask & (indexMask | index);
330 auto addr = getAddress(index);
332 addr = ((addr << 16) | (addr >> 1)) & 0x1'FFFF;
337 std::span<const uint8_t> vram;
338 unsigned registerMask = 0;
339 unsigned indexMask = 0;
369inline std::array<ImU32, size_t(imColor::NUM_COLORS)>
imColors;
374 assert(col < imColor::NUM_COLORS);
Circular buffer class, based on boost::circular_buffer/.
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 addRecentItem(circular_buffer< T > &recentItems, const T &item)
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)
auto find(InputRange &&range, const T &value)
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)