neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_mnemonic.hpp
Go to the documentation of this file.
1// i_mnemonic.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
24
25namespace neogfx
26{
27 class i_widget;
28
30 {
31 public:
32 virtual std::string mnemonic() const = 0;
33 virtual void mnemonic_execute() = 0;
34 virtual i_widget& mnemonic_widget() = 0;
35 };
36
37 inline std::string mnemonic_from_text(std::string const& aText, char aMnemonicPrefix = '&')
38 {
39 auto u = neolib::utf8_to_utf32(aText);
40 for (std::size_t i = 0; i < u.size(); ++i)
41 {
42 if (u[i] == static_cast<char32_t>(aMnemonicPrefix) && i < u.size() - 1 && u[i + 1] != static_cast<char32_t>(aMnemonicPrefix))
43 {
44 return neolib::utf32_to_utf8(u.substr(i + 1, 1));
45 }
46 }
47 return std::string{};
48 }
49}
virtual std::string mnemonic() const =0
virtual i_widget & mnemonic_widget()=0
virtual void mnemonic_execute()=0
std::string mnemonic_from_text(std::string const &aText, char aMnemonicPrefix='&')
std::string utf32_to_utf8(const std::u32string &aString)
std::u32string utf8_to_utf32(std::string_view const &aStringView, Callback aCallback, bool aCodePageFallback=false)