Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Sep 23, 2023
1 parent 6716758 commit 4bd053f
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 59 deletions.
44 changes: 27 additions & 17 deletions Siv3D/include/Siv3D/TextInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# include "Common.hpp"
# include "String.hpp"
# include "Array.hpp"
# include "Optional.hpp"
# include "PointVector.hpp"
# include "ColorHSV.hpp"
# include "UnderlineStyle.hpp"
Expand All @@ -22,6 +23,28 @@ namespace s3d
{
namespace TextInput
{
struct CandidateState
{
Array<String> candidates;

Optional<int32> selectedIndex;

int32 count = 0;

int32 pageStartIndex = 0;

int32 pageSize = 0;

void reset() noexcept
{
candidates.clear();
selectedIndex.reset();
count = 0;
pageStartIndex = 0;
pageSize = 0;
}
};

/// @brief キーボードからのテキスト入力を生の状態で返します。
/// @return キーボードからのテキスト入力
[[nodiscard]]
Expand Down Expand Up @@ -56,10 +79,13 @@ namespace s3d
/// @brief IME を無効化します。
void DisableIME();

[[nodiscard]]
/// @brief 入力中のテキストの変換候補一覧を取得します。
/// @return 入力中のテキストの変換候補一覧
[[nodiscard]]
const Array<String>& GetCandidates();

[[nodiscard]]
const s3d::TextInput::CandidateState& GetCandidateState();

/// @brief 変換待ちのテキストの範囲を返します。
/// @return 変換待ちのテキストの範囲
Expand All @@ -79,22 +105,6 @@ namespace s3d
const ColorF& selectedBackgroundColor = ColorF{ 0.55, 0.85, 1.0 },
const ColorF& frameColor = ColorF{ 0.75 },
const ColorF& textColor = ColorF{ 0.11 });

/// @brief テキストの変換候補を描画します。
/// @param font フォント
/// @param fontSize フォントサイズ
/// @param basePos 基準座標
/// @param boxColor 背景色
/// @param selectedBackgroundColor 選択されているアイテムの背景色
/// @param frameColor 枠の色
/// @param textColor テキストの色
void DrawCandidateWindow(const Font& font,
double fontSize,
const Vec2& basePos,
const ColorF& boxColor = ColorF{ 0.96 },
const ColorF& selectedBackgroundColor = ColorF{ 0.55, 0.85, 1.0 },
const ColorF& frameColor = ColorF{ 0.75 },
const ColorF& textColor = ColorF{ 0.11 });
}

# elif SIV3D_PLATFORM(LINUX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace s3d

m_targetLength = m_internalTargetLength;

m_candidates = m_internalCandidates;
m_candidateState = m_internalCandidateState;

m_chars = m_internalChars;

Expand Down Expand Up @@ -129,7 +129,12 @@ namespace s3d

const Array<String>& CTextInput::getCandidates() const
{
return m_candidates;
return m_candidateState.candidates;
}

const TextInput::CandidateState& CTextInput::getCandidateState() const
{
return m_candidateState;
}

bool CTextInput::process(UINT msg, WPARAM wParam, LPARAM* lParam)
Expand All @@ -148,11 +153,11 @@ namespace s3d
m_internalTargetLength = targetLength;
}

void CTextInput::sendCandidates(const Array<String>& candidates)
void CTextInput::sendCandidateState(const TextInput::CandidateState& state)
{
std::lock_guard lock{ m_mutex };

m_internalCandidates = candidates;
m_internalCandidateState = state;
}

void CTextInput::sendInputText(const String& text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ namespace s3d

std::pair<int32, int32> getCursorIndex() const override;

const Array<String>& getCandidates() const override;

const TextInput::CandidateState& getCandidateState() const override;

//
// Windows
//

const Array<String>& getCandidates() const;

bool process(UINT msg, WPARAM wParam, LPARAM* lParam);

void sendEditingText(const String& text, int32 cursorPos, int32 targetLength);

void sendCandidates(const Array<String>& list);
void sendCandidateState(const TextInput::CandidateState& state);

void sendInputText(const String& text);

Expand All @@ -70,7 +72,7 @@ namespace s3d

int32 m_internalTargetLength = 0;

Array<String> m_internalCandidates;
TextInput::CandidateState m_internalCandidateState;

String m_internalChars;
//
Expand All @@ -82,7 +84,7 @@ namespace s3d

int32 m_targetLength = 0;

Array<String> m_candidates;
TextInput::CandidateState m_candidateState;

String m_chars;

Expand Down
Loading

0 comments on commit 4bd053f

Please sign in to comment.