26 const char*
begin = str.data();
27 const char*
end =
begin + str.size();
32 const char*
begin = str.data();
33 const char*
end =
begin + str.size();
42template<
typename... Ts>
45 auto s =
tmpStrCat(std::forward<Ts>(ts)...);
49inline void RightAlignText(std::string_view text, std::string_view maxWidthText)
53 if (
auto spacing = maxWidth - actualWidth; spacing > 0.0f) {
54 auto pos = ImGui::GetCursorPosX();
55 ImGui::SetCursorPosX(pos + spacing);
69class VideoSourceSetting;
79 if (desc.empty())
return;
89 if (!ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip))
return;
90 auto desc = std::invoke(descFunc);
91 if (desc.empty())
return;
103 static constexpr gl::vec2 center{0.5f, 0.5f};
104 gl::vec2 windowPos = ImGui::GetWindowPos();
105 gl::vec2 windowSize = ImGui::GetWindowSize();
106 auto windowCenter = windowPos + center * windowSize;
107 ImGui::SetNextWindowPos(windowCenter, ImGuiCond_Appearing, center);
117bool SliderInt(
const char* label, IntegerSetting&
setting, ImGuiSliderFlags flags = 0);
118bool SliderFloat(FloatSetting&
setting,
const char* format =
"%.3f", ImGuiSliderFlags flags = 0);
119bool SliderFloat(
const char* label, FloatSetting&
setting,
const char* format =
"%.3f", ImGuiSliderFlags flags = 0);
128const char*
getComboString(
int item,
const char* itemsSeparatedByZeros);
130std::string
formatTime(std::optional<double> time);
131float calculateFade(
float current,
float target,
float period);
133template<
int HexDigits>
135 assert(offset < mult);
136 *value &= ~(mult - 1);
138 auto preview =
tmpStrCat(
"0x", hex_string<HexDigits>(*value | offset));
140 for (int addr = 0; addr < max; addr += mult) {
141 if (auto str = tmpStrCat(
"0x", hex_string<HexDigits>(addr | offset));
142 ImGui::Selectable(str.c_str(), *value == addr)) {
145 if (*value == addr) {
146 ImGui::SetItemDefaultFocus();
152template<
typename Range,
typename Projection>
153void sortUpDown_T(Range& range,
const ImGuiTableSortSpecs* sortSpecs, Projection proj) {
154 if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Descending) {
160template<
typename Range,
typename Projection>
162 if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Descending) {
171 const std::vector<std::pair<std::string, std::string>>& info,
172 std::string_view key)
174 auto it =
ranges::find_if(info, [&](
const auto& p) {
return p.first == key; });
175 if (it == info.end())
return {};
180[[nodiscard]] std::vector<std::string>
getAllValuesFor(std::string_view key,
const std::vector<T>& items)
182 std::vector<std::string> result;
183 for (
const auto& item : items) {
186 result.emplace_back(*value);
197 im::Combo(key.
c_str(), selection.empty() ?
"--all--" : selection.c_str(), [&]{
198 if (ImGui::Selectable(
"--all--")) {
202 if (ImGui::Selectable(type.c_str())) {
210void applyComboFilter(std::string_view key, std::string_view value,
const std::vector<T>& items, std::vector<size_t>& indices)
212 if (value.empty())
return;
213 std::erase_if(indices, [&](
auto idx) {
214 const auto& info = items[idx].configInfo;
216 if (!val)
return true;
217 return *val != value;
221template<std::invocable<
size_t> GetName>
222void filterIndices(std::string_view filterString, GetName getName, std::vector<size_t>& indices)
224 if (filterString.empty())
return;
225 std::erase_if(indices, [&](
auto idx) {
226 const auto& name = getName(idx);
227 return !
ranges::all_of(StringOp::split_view<StringOp::EmptyParts::REMOVE>(filterString,
' '),
235 filterIndices(filterString, [&](
size_t idx) {
return items[idx].displayName; }, indices);
239template<
typename Range,
typename BinaryPred,
typename Action>
240static void chunk_by(Range&& range, BinaryPred pred, Action action)
242 auto it = std::begin(range);
243 auto last = std::end(range);
247 while (it != last && pred(*prev, *it)) {
257std::optional<ImGuiKeyChord>
parseKeyChord(std::string_view name);
263 VramTable(std::span<const uint8_t> vram_,
bool planar_ =
false)
264 : vram(vram_), planar(planar_) {}
267 registerMask = (value << extraLsbBits) | ~(~0u << extraLsbBits);
270 indexMask = ~0u << bits;
274 auto addr = registerMask & (indexMask | index);
276 addr = ((addr << 16) | (addr >> 1)) & 0x1'FFFF;
281 std::span<const uint8_t> vram;
282 unsigned registerMask = 0;
283 unsigned indexMask = 0;
313inline std::array<ImU32, size_t(imColor::NUM_COLORS)>
imColors;
318 assert(col < imColor::NUM_COLORS);
void setRegister(unsigned value, unsigned extraLsbBits)
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
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 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)
bool SliderFloat(FloatSetting &setting, const char *format, ImGuiSliderFlags flags)
std::span< const EnumToolTip > EnumToolTips
void centerNextWindowOverCurrent()
bool SliderInt(IntegerSetting &setting, ImGuiSliderFlags flags)
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)
bool InputText(Setting &setting)
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)
std::string formatTime(std::optional< double > time)
float calculateFade(float current, float target, float period)
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)
std::string operator()(const Setting &setting) const
constexpr auto begin(const zstring_view &x)
constexpr auto end(const zstring_view &x)