Skip to content

Commit

Permalink
SimpleGUI::IMECandidateWindow()
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Sep 23, 2023
1 parent 4bd053f commit b8675ca
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Siv3D/include/Siv3D/SimpleGUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,17 @@ namespace s3d
/// @param enabled リストボックスの操作を有効にするか
/// @return リストボックスが操作された場合 true, それ以外の場合は false
bool ListBoxAt(ListBoxState& state, const Vec2& center, double width = 160.0, double height = 156.0, bool enabled = true);

/// @brief IME の候補ウィンドウの領域を返します。
/// @param pos 候補ウィンドウの左上の座標
/// @return 候補ウィンドウの領域
/// @remark この関数は Windows 版でのみ動作します。それ以外のプラットフォームでは常に `RectF{ pos, 0, 0 }` を返します。
[[nodiscard]]
RectF CandidateWindowRegion(const Vec2& pos);

/// @brief IME の候補ウィンドウを表示します。
/// @param pos 候補ウィンドウの左上の座標
/// @remark この関数は Windows 版でのみ動作します。それ以外のプラットフォームでは何もしません。
void CandidateWindow([[maybe_unused]] const Vec2& pos);
}
}
102 changes: 102 additions & 0 deletions Siv3D/src/Siv3D/SimpleGUI/SivSimpleGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ namespace s3d
constexpr double TextAreaScrollBarMinHeight = 16.0;
constexpr ColorF TextAreaEditingTextBackgroundColor{ 0.8 };
constexpr ColorF TextAreaScrollBarColor{ 0.67 };
constexpr ColorF CandidateWindowColor{ 0.98 };
constexpr ColorF CandidateWindowFrameColor{ 0.75 };
constexpr ColorF CandidateSelectedBackgroundColor{ 0.55, 0.85, 1.0 };
constexpr ColorF CandidateTextColor{ 0.11 };
constexpr double CandidateMargin = 4.0;
constexpr double CandidatePadding = 10.0;

[[nodiscard]]
inline constexpr ColorF GetTextColor(bool enabled) noexcept
Expand Down Expand Up @@ -2042,6 +2048,102 @@ namespace s3d
return (oldState != state.selectedItemIndex);
}

RectF IMECandidateWindowRegion(const Vec2& pos)
{
# if SIV3D_PLATFORM(WINDOWS)

const auto& cadidateState = Platform::Windows::TextInput::GetCandidateState();

if (not cadidateState.candidates)
{
return{ pos, 0 };
}

const Font& font = GetFont();

const double boxWidth = [&font, &cadidateState]()
{
double boxWidth = 0.0;

for (const auto& canditate : cadidateState.candidates)
{
boxWidth = Max<double>(boxWidth, font(canditate).region().w);
}

return boxWidth;
}() + (CandidatePadding * 2);

const double candidateItemHeight = (font.height() + CandidateMargin);

return{ pos, boxWidth, (candidateItemHeight * cadidateState.candidates.size()) };

# else

return{ pos, 0 };

# endif
}

void IMECandidateWindow([[maybe_unused]] const Vec2& pos)
{
# if SIV3D_PLATFORM(WINDOWS)

const auto& cadidateState = Platform::Windows::TextInput::GetCandidateState();

if (not cadidateState.candidates)
{
return;
}

const Font& font = GetFont();

const double boxWidth = [&font, &cadidateState]()
{
double boxWidth = 0.0;

for (const auto& canditate : cadidateState.candidates)
{
boxWidth = Max<double>(boxWidth, font(canditate).region().w);
}

return boxWidth;
}() + (CandidatePadding * 2);

const double candidateItemHeight = (font.height() + CandidateMargin);

RectF{ pos, boxWidth, (candidateItemHeight * cadidateState.candidates.size()) }
.drawShadow(Vec2{ 0, 2 }, 8)
.draw(CandidateWindowColor)
.drawFrame(1, 0, CandidateWindowFrameColor);

{
int32 currentIndex = cadidateState.pageStartIndex;

for (const auto& candidate : cadidateState.candidates)
{
const bool selected = (currentIndex == cadidateState.selectedIndex);

const Vec2 itemPos{ pos.x, (pos.y + (currentIndex - cadidateState.pageStartIndex) * candidateItemHeight) };

if (selected)
{
RectF{ itemPos, boxWidth, candidateItemHeight }
.stretched(-1, 0)
.draw(CandidateSelectedBackgroundColor);
}

if (candidate)
{
font(candidate).draw(itemPos.movedBy(CandidatePadding, (CandidateMargin * 0.5)), CandidateTextColor);
}

++currentIndex;
}
}

# endif
}

namespace detail
{
static void TextAreaDraw(const TextAreaEditState& text, const Font& font, const int32 fontHeight, const RectF& region,
Expand Down

0 comments on commit b8675ca

Please sign in to comment.