Skip to content

Commit

Permalink
feature: servers selectable with keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
stowmyy committed Oct 25, 2023
1 parent f30a196 commit 9b07e46
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 30 deletions.
Binary file added dropship/assets/icons/icon-heart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dropship/assets/icons/icon-skull.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dropship/dropship.rc
Binary file not shown.
52 changes: 35 additions & 17 deletions dropship/src/DashboardManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ DashboardManager::DashboardManager() :
},

{
.title = "Germany 2",
.title = "Germany",
._ping_ip = "",
.heading = "GEW3",
._firewall_rule_address = ips.at("gew3"),
Expand Down Expand Up @@ -352,6 +352,8 @@ void DashboardManager::loadAssets() {
"icon_maple_leaf.png",
"icon_chain_slash.png",
"icon_bolt.png",
"icon_skull.png",
"icon_heart.png",
"icon_outside_window.png",

"icon_wifi_slash.png",
Expand Down Expand Up @@ -431,6 +433,7 @@ void DashboardManager::RenderInline()

static auto &style = ImGui::GetStyle();
ImU32 const white = ImGui::ColorConvertFloat4ToU32({ 1, 1, 1, style.Alpha });
// static ImU32 const transparent = ImGui::ColorConvertFloat4ToU32({ 0, 0, 0, 0 });

ImVec2 const windowPos = ImGui::GetWindowPos();
ImVec2 const windowSize = ImGui::GetWindowSize();
Expand Down Expand Up @@ -463,7 +466,8 @@ void DashboardManager::RenderInline()
// dashboard copy
ImGui::BeginGroup();
{
list->AddText(font_title, font_title->FontSize, widgetPos - ImVec2(1, 0), color_text, appStore.dashboard.title.c_str());
//list->AddText(font_title, font_title->FontSize, widgetPos - ImVec2(1, 0), color_text, appStore.dashboard.title.c_str());
list->AddText(font_title, font_title->FontSize, widgetPos - ImVec2(1, 0), ImGui::ColorConvertFloat4ToU32(style.Colors[ImGuiCol_TextDisabled]), appStore.dashboard.title.c_str());
ImGui::Dummy({ 0, font_title->FontSize - 6 });

ImGui::TextWrapped(appStore.dashboard.heading.c_str());
Expand All @@ -483,13 +487,13 @@ void DashboardManager::RenderInline()
// socials
{
ImGui::Dummy({ size, size });
list->AddImage((void*)_get_texture("icon_bolt"), ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), ImVec2(0, 0), ImVec2(1, 1), ImGui::IsItemHovered() ? color_button_hover : color_button);
list->AddImage((void*)_get_texture("icon_heart"), ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), ImVec2(0, 0), ImVec2(1, 1), ImGui::IsItemHovered() ? color_button_hover : color_button);

if (ImGui::IsItemClicked())
ImGui::OpenPopup("socials");
}

ImGui::SameLine(NULL, 10);
ImGui::SameLine(NULL, 16);
ImGui::SetCursorPos(ImGui::GetCursorPos() + offset);

// options
Expand Down Expand Up @@ -560,6 +564,7 @@ void DashboardManager::RenderInline()

{
ImGui::BeginChild("endpoints_scrollable", ImVec2(ImGui::GetContentRegionAvail().x, 540), false);
ImGui::Spacing();
{
int i = 0;
for (auto& endpoint : this->endpoints)
Expand All @@ -581,21 +586,35 @@ void DashboardManager::RenderInline()

ImGui::Dummy({ 0 ,0 });
ImGui::SameLine(NULL, 16);
ImGui::Dummy({ ImGui::GetContentRegionAvail().x - 16, 73 });

bool highlighted = false;

// ImGui::Dummy({ ImGui::GetContentRegionAvail().x - 16, 73 });
ImGui::PushID(i);
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, selected ? color_secondary : color_secondary_faded);
ImGui::PushStyleColor(ImGuiCol_Header, color);
ImGui::PushStyleColor(ImGuiCol_HeaderActive, selected ? color_secondary : color_secondary_faded);
ImGui::PushStyleColor(ImGuiCol_NavHighlight, NULL);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 16.0f);
ImGui::Selectable("##end", &highlighted, 0, { ImGui::GetContentRegionAvail().x - 16, 73 });
ImGui::PopStyleColor(4);
ImGui::PopStyleVar();
ImGui::PopID();
ImGui::Spacing();

auto hovered = ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup);

// background
if (hovered)
if (hovered || highlighted)
{
if (selected)
{
w_list->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color_secondary, 5, 0, 8);
w_list->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color_secondary, 5, NULL);
//w_list->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color_secondary, 5, NULL);
}
else
{
w_list->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color_secondary_faded, 5, NULL);
//w_list->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), color_secondary_faded, 5, NULL);
}
}
else
Expand Down Expand Up @@ -640,13 +659,12 @@ void DashboardManager::RenderInline()
if (ImGui::BeginPopupContextItem(key.c_str()))
{
{
ImGui::MenuItem(endpoint->name.c_str(), NULL, false, false);
if (ImGui::MenuItem("disable")) {}
if (ImGui::MenuItem("block", "wip")) {}
//ImGui::SeparatorText("xx");
if (ImGui::MenuItem("all but this one")) {
}
}
if (!hovered && !ImGui::IsWindowHovered())
ImGui::CloseCurrentPopup();
Expand All @@ -657,7 +675,7 @@ void DashboardManager::RenderInline()
}*/

// action
if (ImGui::IsItemClicked())
if (ImGui::IsItemClicked() || (highlighted && (ImGui::IsKeyPressed(ImGuiKey_Space) || ImGui::IsKeyPressed(ImGuiKey_Enter))))
{
int total = 0;
for (auto &endpoint : this->endpoints)
Expand Down Expand Up @@ -735,8 +753,8 @@ void DashboardManager::RenderInline()
ImGui::Indent(style.FramePadding.x);
{
ImGui::Text("Unavailable in this version.");
static bool test;
ToggleButton("test", &test);
// static bool test;
// ToggleButton("test", &test);
}
ImGui::Unindent();
}
Expand Down
13 changes: 2 additions & 11 deletions dropship/src/_WindowsFirewallUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,10 @@ class _WindowsFirewallUtil : public failable
}
}

if (this->networkInfo.connected_networks == 0 && ImGui::GetCurrentContext() != nullptr)
/*if (this->networkInfo.connected_networks == 0 && ImGui::GetCurrentContext() != nullptr)
{
ImGui::OpenPopup("offline");
}
}*/

Cleanup:

Expand Down Expand Up @@ -884,15 +884,6 @@ class _WindowsFirewallUtil : public failable
ImGui::OpenPopup("warnings_fixed");
this->modal_warnings_fixed_time = ImGui::GetTime();
}


// TODO test
if (ImGui::BeginPopupModal("offline", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground))
{
ImGui::Text("test");
ImGui::EndPopup();
}



//ImGui::Text("debugging %c", "|/-\\"[(int)(ImGui::GetTime() / 0.05f) & 3]);
Expand Down
4 changes: 3 additions & 1 deletion dropship/src/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ void setTheme(THEME theme)
style.ItemSpacing = { 8.0f, 8.0f };
style.CellPadding = { 8.0f, 4.0f };

style.FrameRounding = 4.0f;
style.FrameRounding = 5.0f;
//style.FramePadding = { 4.0f, 4.0f };
style.FramePadding = { 10.0f, 8.0f };

style.SelectableRounding = 5.0f;

style.IndentSpacing = 20;

style.GrabMinSize = 8;
Expand Down
2 changes: 2 additions & 0 deletions dropship/src/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct Endpoint
bool _has_pinged = { false }; // if it has attempted a ping yet ((any point)).
bool _has_pinged_successfully = { false };

// bool highlighted = false; // tab index

bool favorite = { false };
/*
0 (>) = fine
Expand Down
3 changes: 3 additions & 0 deletions dropship/vendor/imgui-docking/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,7 @@ ImGuiStyle::ImGuiStyle()
TabBarBorderSize = 1.0f; // Thickness of tab-bar separator, which takes on the tab active color to denote focus.
ColorButtonPosition = ImGuiDir_Right; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
ButtonTextAlign = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text.
SelectableRounding = 0.0f; // Radius of selectable/menuitem corners rounding. Set to 0.0f to have rectangular selection.
SelectableTextAlign = ImVec2(0.0f,0.0f);// Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line.
SeparatorTextBorderSize = 3.0f; // Thickkness of border in SeparatorText()
SeparatorTextAlign = ImVec2(0.0f,0.5f);// Alignment of text within the separator. Defaults to (0.0f, 0.5f) (left aligned, center).
Expand Down Expand Up @@ -1261,6 +1262,7 @@ void ImGuiStyle::ScaleAllSizes(float scale_factor)
GrabRounding = ImTrunc(GrabRounding * scale_factor);
LogSliderDeadzone = ImTrunc(LogSliderDeadzone * scale_factor);
TabRounding = ImTrunc(TabRounding * scale_factor);
SelectableRounding = ImTrunc(SelectableRounding * scale_factor);
TabMinWidthForCloseButton = (TabMinWidthForCloseButton != FLT_MAX) ? ImTrunc(TabMinWidthForCloseButton * scale_factor) : FLT_MAX;
SeparatorTextPadding = ImTrunc(SeparatorTextPadding * scale_factor);
DockingSeparatorSize = ImTrunc(DockingSeparatorSize * scale_factor);
Expand Down Expand Up @@ -3203,6 +3205,7 @@ static const ImGuiDataVarInfo GStyleVarInfo[] =
{ ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, GrabMinSize) }, // ImGuiStyleVar_GrabMinSize
{ ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, GrabRounding) }, // ImGuiStyleVar_GrabRounding
{ ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, TabRounding) }, // ImGuiStyleVar_TabRounding
{ ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, SelectableRounding) }, // ImGuiStyleVar_SelectableRounding
{ ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, TabBarBorderSize) }, // ImGuiStyleVar_TabBarBorderSize
{ ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ButtonTextAlign) }, // ImGuiStyleVar_ButtonTextAlign
{ ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, SelectableTextAlign) }, // ImGuiStyleVar_SelectableTextAlign
Expand Down
2 changes: 2 additions & 0 deletions dropship/vendor/imgui-docking/imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,7 @@ enum ImGuiStyleVar_
ImGuiStyleVar_TabRounding, // float TabRounding
ImGuiStyleVar_TabBarBorderSize, // float TabBarBorderSize
ImGuiStyleVar_ButtonTextAlign, // ImVec2 ButtonTextAlign
ImGuiStyleVar_SelectableRounding, // float SelectableRounding
ImGuiStyleVar_SelectableTextAlign, // ImVec2 SelectableTextAlign
ImGuiStyleVar_SeparatorTextBorderSize,// float SeparatorTextBorderSize
ImGuiStyleVar_SeparatorTextAlign, // ImVec2 SeparatorTextAlign
Expand Down Expand Up @@ -2002,6 +2003,7 @@ struct ImGuiStyle
float TabBarBorderSize; // Thickness of tab-bar separator, which takes on the tab active color to denote focus.
ImGuiDir ColorButtonPosition; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
ImVec2 ButtonTextAlign; // Alignment of button text when button is larger than text. Defaults to (0.5f, 0.5f) (centered).
float SelectableRounding; // Radius of selectable/menuitem corners rounding. Set to 0.0f to have rectangular selection.
ImVec2 SelectableTextAlign; // Alignment of selectable text. Defaults to (0.0f, 0.0f) (top-left aligned). It's generally important to keep this left-aligned if you want to lay multiple items on a same line.
float SeparatorTextBorderSize; // Thickkness of border in SeparatorText()
ImVec2 SeparatorTextAlign; // Alignment of text within the separator. Defaults to (0.0f, 0.5f) (left aligned, center).
Expand Down
1 change: 1 addition & 0 deletions dropship/vendor/imgui-docking/imgui_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6509,6 +6509,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
ImGui::SliderFloat("ScrollbarRounding", &style.ScrollbarRounding, 0.0f, 12.0f, "%.0f");
ImGui::SliderFloat("GrabRounding", &style.GrabRounding, 0.0f, 12.0f, "%.0f");
ImGui::SliderFloat("TabRounding", &style.TabRounding, 0.0f, 12.0f, "%.0f");
ImGui::SliderFloat("SelectableRounding", &style.SelectableRounding, 0.0f, 12.0f, "%.0f");

ImGui::SeparatorText("Widgets");
ImGui::SliderFloat2("WindowTitleAlign", (float*)&style.WindowTitleAlign, 0.0f, 1.0f, "%.2f");
Expand Down
2 changes: 1 addition & 1 deletion dropship/vendor/imgui-docking/imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6619,7 +6619,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
if (hovered || selected)
{
const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
RenderFrame(bb.Min, bb.Max, col, false, 0.0f);
RenderFrame(bb.Min, bb.Max, col, false, style.SelectableRounding);
}
if (g.NavId == id)
RenderNavHighlight(bb, id, ImGuiNavHighlightFlags_TypeThin | ImGuiNavHighlightFlags_NoRounding);
Expand Down

0 comments on commit 9b07e46

Please sign in to comment.