Size SettingsView::RenderContent(Renderer* renderer)
{
    DestroyChildViews();

    RenderPosition renderPosition = RenderPosition(PaddingX, PaddingY);

    renderPosition = CreateSettingsGroups(RenderDescriptor(renderer, renderPosition));

    renderPosition = renderPosition.MoveY(LineHeight / 2).SetX(PaddingX);

    CreateControls(RenderDescriptor(renderer, renderPosition));

    SetButtonsState();

    return renderer->GetSize();
}
Exemple #2
0
Size DictionaryWindow::RenderContent(Renderer* renderer)
{
    DestroyChildWindows();

    RenderPosition renderPosition = RenderPosition(
        paddingX,
        paddingY / 2 + fontNormal->GetAscent());

    size_t countToShow = min(200, model.size());

    wstring title = L"Showing " + to_wstring(countToShow) + L" out of " + to_wstring(model.size());
    renderer->PrintText(title, fontItalic, Colors::Gray, renderPosition);

    for (size_t i = 0; i < countToShow; ++i)
    {
        renderPosition = renderPosition.MoveY(lineHeight);

        DictionaryRecord record = model[i];

        renderPosition = renderer->PrintText(
            record.GetWord(),
            fontNormal,
            Colors::Black,
            renderPosition.MoveX(paddingX));

        renderer->PrintText(L" (" + to_wstring(record.GetCount()) + L")", fontNormal, Colors::Gray, renderPosition);

        renderPosition = renderPosition.SetX(paddingX);

        HoverIconButtonWindow* translateButton = new HoverIconButtonWindow(context, this);
        translateButton->SetDimensions(
            renderPosition.MoveY(-fontNormal->GetAscent() + 1).GetPosition(),
            Size(iconSize, iconSize));
        translateButton->SetNormalIconResource(IDR_TRANSLATE_INACTIVE);
        translateButton->SetHoverIconResource(IDR_TRANSLATE);
        translateButton->OnClick.Subscribe([i, this]()
        {
            return OnShowTranslation.Notify(i);
        });
        translateButton->InitializeAndRender();
    }

    renderer->IncreaseWidth(paddingX);

    return renderer->GetSize();
}
void SettingsView::CreateControls(RenderDescriptor renderDescriptor)
{
    RenderPosition renderPosition = CreateSaveButtonControl(renderDescriptor);

    cancelButton = CreateTextButtonControl(
        RenderDescriptor(renderDescriptor.GetRenderer(), renderPosition.MoveX(7, ScaleProvider)),
        L"Cancel",
        &OnCancelChanges);

    wstring resetButtonText = L"Reset";
    int resetButtonTextWidth = RenderingProvider->GetTextSize(resetButtonText, FontSmallUnderscored).GetWidth();

    int maxRightPosition = 0;
    for(size_t i = 0; i < settingsGroups.size(); ++i)
    {
        maxRightPosition = max(maxRightPosition, settingsGroups[i]->GetBoundingRect().GetRight());
    }
    int resetButtonPositionX = maxRightPosition - resetButtonTextWidth;

    resetButton = CreateTextButtonControl(RenderDescriptor(renderDescriptor.GetRenderer(), Point(resetButtonPositionX, renderPosition.GetY())), resetButtonText, &OnResetSettings);

    SetButtonsState();
}
Size HeaderView::RenderTranslationResult(Renderer* renderer, TranslateResult translateResult)
{
    RenderPosition renderPosition = RenderPosition(PaddingX, LineHeight);

    TranslateResultSentence sentence = translateResult.GetSentence();
    renderer->PrintText(sentence.GetTranslation(), FontHeader, Colors::Black, renderPosition);

    renderPosition = renderPosition.MoveY(LineHeight);

    int imageSize = FontSmall->GetAscent();
    HoverIconButtonControl* audioButton = new HoverIconButtonControl(Context, this);
    audioButton->SetDimensions(
        renderPosition.MoveY(-imageSize).MoveY(2, ScaleProvider).GetPosition(),
        Size(imageSize, imageSize));
    audioButton->SetHoverIconResource(IDR_AUDIO);
    audioButton->SetNormalIconResource(IDR_AUDIO_INACTIVE);
    audioButton->OnClick.Subscribe(&OnPlayText);
    audioButton->InitializeAndRender();

    renderPosition = renderPosition.MoveX(imageSize).MoveX(2, ScaleProvider);
    renderPosition = renderer->PrintText(sentence.GetOrigin(), FontSmall, Colors::Gray, renderPosition);

    RenderDescriptor actionRenderDescriptor = RenderDescriptor(renderer, renderPosition.MoveX(1));
    if (translateResult.IsInputCorrected())
    {
        PrintInputCorrectionWarning(actionRenderDescriptor, sentence.GetInput());
    }
    else if (!sentence.GetSuggestion().empty())
    {
        PrintSuggestion(actionRenderDescriptor, sentence.GetSuggestion());
    }

    renderer->IncreaseWidth(PaddingX);

    return renderer->GetSize();
}