Skip to content

Commit

Permalink
Fixed scroll bars not appearning, and removed compiler warnings for s…
Browse files Browse the repository at this point in the history
…etting pages.
  • Loading branch information
123jimin committed Mar 24, 2021
1 parent 5926b17 commit 45d6038
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
8 changes: 5 additions & 3 deletions Main/include/SettingsPage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ class SettingsPage
};

// Useful elements
inline void LayoutRowDynamic(int num_columns) { LayoutRowDynamic(num_columns, m_buttonHeight); }
inline void LayoutRowDynamic(int num_columns) { LayoutRowDynamic(num_columns, static_cast<float>(m_buttonHeight)); }
void LayoutRowDynamic(int num_columns, float height);

void Separator();
void Label(const std::string_view& label);
inline void Separator() { Separator(static_cast<float>(m_buttonHeight)); }
void Separator(float height);

void Label(const std::string_view& label, enum nk_text_alignment alignment = nk_text_alignment::NK_TEXT_LEFT);

bool ToggleInput(bool val, const std::string_view& label);
bool ToggleSetting(GameConfigKeys key, const std::string_view& label);
Expand Down
23 changes: 18 additions & 5 deletions Main/src/SettingsPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ void SettingsPage::LayoutRowDynamic(int num_columns, float height)
nk_layout_row_dynamic(m_nctx, height, num_columns);
}

void SettingsPage::Separator()
void SettingsPage::Separator(float height)
{
nk_labelf(m_nctx, nk_text_alignment::NK_TEXT_CENTERED, "_______________________");
LayoutRowDynamic(1, height);
Label(" ", nk_text_alignment::NK_TEXT_CENTERED);
}

void SettingsPage::Label(const std::string_view& label)
void SettingsPage::Label(const std::string_view& label, enum nk_text_alignment alignment)
{
nk_label(m_nctx, label.data(), nk_text_alignment::NK_TEXT_LEFT);
nk_label(m_nctx, label.data(), alignment);
}

bool SettingsPage::ToggleInput(bool val, const std::string_view& label)
Expand Down Expand Up @@ -330,8 +331,14 @@ void SettingsPage::Render(const struct nk_rect& rect)
{
m_comboBoxSize.x = rect.x - 30;

if (nk_begin(m_nctx, m_name.data(), rect, NK_WINDOW_NO_SCROLLBAR))
m_nctx->style.window.padding.x = 6.0f;
m_nctx->style.window.padding.y = 0.0f;

if (nk_begin(m_nctx, m_name.data(), rect, 0))
{
LayoutRowDynamic(1, 60);
nk_labelf(m_nctx, nk_text_alignment::NK_TEXT_CENTERED, "%s Settings", m_name.data());

RenderContents();
nk_end(m_nctx);
}
Expand Down Expand Up @@ -486,6 +493,9 @@ void SettingsPageCollection::RenderPages()

void SettingsPageCollection::RenderPageHeaders()
{
m_nctx->style.window.padding.x = 0.0f;
m_nctx->style.window.padding.y = 0.0f;

if (nk_begin(m_nctx, "Pages", m_pageHeaderRegion, NK_WINDOW_NO_SCROLLBAR))
{
nk_layout_row_dynamic(m_nctx, 50, 1);
Expand All @@ -501,6 +511,9 @@ void SettingsPageCollection::RenderPageHeaders()
}
}

nk_layout_row_dynamic(m_nctx, 25, 1);
nk_layout_row_dynamic(m_nctx, 50, 1);

if (nk_button_label(m_nctx, "Exit")) Exit();
nk_end(m_nctx);
}
Expand Down
33 changes: 18 additions & 15 deletions Main/src/SettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,9 @@ class SettingsPage_Input : public SettingsPage

RenderKeyBindings();

Separator(m_buttonHeight * 2);
LayoutRowDynamic(1);

nk_labelf(m_nctx, nk_text_alignment::NK_TEXT_CENTERED, "_______________________");
nk_labelf(m_nctx, nk_text_alignment::NK_TEXT_CENTERED, " ");

if (nk_button_label(m_nctx, "Calibrate Laser Sensitivity")) OpenCalibrateSensitivity();

GameConfigKeys laserSensKey;
Expand Down Expand Up @@ -719,8 +717,11 @@ class SettingsPage_Skin : public SettingsPage
return;
}

nk_labelf(m_nctx, nk_text_alignment::NK_TEXT_CENTERED, "%s Skin Settings", m_skin.data());
nk_labelf(m_nctx, nk_text_alignment::NK_TEXT_CENTERED, "_______________________");

Separator(m_buttonHeight * 2);

LayoutRowDynamic(1);
nk_labelf(m_nctx, nk_text_alignment::NK_TEXT_CENTERED, "Settings for [%s] Skin", m_skin.data());

for (const SkinSetting& setting : m_skinConfig->GetSettings())
{
Expand Down Expand Up @@ -978,7 +979,7 @@ class ButtonBindingScreen_Impl : public ButtonBindingScreen
}
if (m_knobs)
{
for (size_t i = 0; i < m_gamepad->NumAxes(); i++)
for (uint8 i = 0; i < m_gamepad->NumAxes(); i++)
{
m_gamepadAxes.Add(m_gamepad->GetAxis(i));
}
Expand Down Expand Up @@ -1042,14 +1043,14 @@ class ButtonBindingScreen_Impl : public ButtonBindingScreen
if (m_knobs)
{
prompt = "Turn Knob";
for (size_t i = 0; i < m_gamepad->NumAxes(); i++)
for (uint8 i = 0; i < m_gamepad->NumAxes(); i++)
{
m_gamepadAxes.Add(m_gamepad->GetAxis(i));
}
}
}

g_application->FastText(prompt, g_resolution.x / 2, g_resolution.y / 2, 40, NVGalign::NVG_ALIGN_CENTER | NVGalign::NVG_ALIGN_MIDDLE);
g_application->FastText(prompt, static_cast<float>(g_resolution.x / 2), static_cast<float>(g_resolution.y / 2), 40, NVGalign::NVG_ALIGN_CENTER | NVGalign::NVG_ALIGN_MIDDLE);
}

void OnButtonPressed(uint8 key)
Expand Down Expand Up @@ -1157,19 +1158,21 @@ class LaserSensCalibrationScreen_Impl : public LaserSensCalibrationScreen

void Render(float deltatime)
{
const Vector2 center = { static_cast<float>(g_resolution.x / 2), static_cast<float>(g_resolution.y / 2) };

if (m_state)
{
float sens = 6.0 / m_delta;
const float sens = 6.0f / m_delta;

g_application->FastText("Turn left knob one revolution clockwise", g_resolution.x / 2, g_resolution.y / 2, 40, NVGalign::NVG_ALIGN_CENTER | NVGalign::NVG_ALIGN_MIDDLE);
g_application->FastText("then press start.", g_resolution.x / 2, g_resolution.y / 2 + 45, 40, NVGalign::NVG_ALIGN_CENTER | NVGalign::NVG_ALIGN_MIDDLE);
g_application->FastText(Utility::Sprintf("Current Sens: %.2f", sens), g_resolution.x / 2, g_resolution.y / 2 + 90, 40, NVGalign::NVG_ALIGN_CENTER | NVGalign::NVG_ALIGN_MIDDLE);
g_application->FastText("Turn left knob one revolution clockwise", center.x, center.y, 40, NVGalign::NVG_ALIGN_CENTER | NVGalign::NVG_ALIGN_MIDDLE);
g_application->FastText("then press start.", center.x, center.y + 45, 40, NVGalign::NVG_ALIGN_CENTER | NVGalign::NVG_ALIGN_MIDDLE);
g_application->FastText(Utility::Sprintf("Current Sens: %.2f", sens), center.x, center.y + 90, 40, NVGalign::NVG_ALIGN_CENTER | NVGalign::NVG_ALIGN_MIDDLE);

}
else
{
m_delta = 0;
g_application->FastText("Press start twice", g_resolution.x / 2, g_resolution.y / 2, 40, NVGalign::NVG_ALIGN_CENTER | NVGalign::NVG_ALIGN_MIDDLE);
g_application->FastText("Press start twice", center.x, center.y, 40, NVGalign::NVG_ALIGN_CENTER | NVGalign::NVG_ALIGN_MIDDLE);
}
}

Expand All @@ -1181,8 +1184,8 @@ class LaserSensCalibrationScreen_Impl : public LaserSensCalibrationScreen
{
if (m_state)
{
// calc sens and then call delagate
SensSet.Call(6.0 / m_delta);
// calc sens and then call delegate
SensSet.Call(6.0f / m_delta);
g_application->RemoveTickable(this);
}
else
Expand Down

0 comments on commit 45d6038

Please sign in to comment.