Skip to content

Commit

Permalink
Optimized the website code
Browse files Browse the repository at this point in the history
  • Loading branch information
roma160 committed Jul 11, 2023
1 parent 0605f05 commit d44f027
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions emscripten/include/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Field {
bool show_edge_weights = true;
bool show_only_selected_edges = false;
bool show_actual_distance = false;
bool is_dark_theme_selected;

string debug_message;

Expand Down
10 changes: 7 additions & 3 deletions emscripten/include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
#define FIXED_WINDOW_FLAGS ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBackground
#define FIXED_ALGORITHM_WINDOW_WIDTH 300

#ifdef EMSCRIPTEN_CODE
#define DELTA_TICKS 25
#else
#define DELTA_TICKS 29
#endif

namespace global {
static bool isDarkTheme = true;
static bool isDarkTheme;

void setDarkTheme();
void setLightTheme();
void setDarkTheme(bool ignore_current = false);
void setLightTheme(bool ignore_current = false);
};

//#define EMSCRIPTEN_CODE
20 changes: 13 additions & 7 deletions emscripten/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ static void MainLoopForEmscripten() { MainLoopForEmscriptenP(); }

ImVec4 clear_color;

void global::setDarkTheme() {
if(global::isDarkTheme) return;
void global::setDarkTheme(bool ignore_current) {
if(!ignore_current && global::isDarkTheme) return;

clear_color = ImVec4(0.45f, 0.55f, 0.60f, .00f);
ImGui::StyleColorsDark();
Expand All @@ -70,8 +70,8 @@ void global::setDarkTheme() {
global::isDarkTheme = true;
}

void global::setLightTheme() {
if(!global::isDarkTheme) return;
void global::setLightTheme(bool ignore_current) {
if(!ignore_current && !global::isDarkTheme) return;

clear_color = ImVec4(1.f, 1.f, 1.f, 1.f);
ImGui::StyleColorsLight();
Expand Down Expand Up @@ -216,9 +216,15 @@ int main(int argc, char* argv[])

// Styling the window
#ifndef EMSCRIPTEN_CODE
global::setDarkTheme();
if(args_set.count("--light"))
global::setLightTheme(true);
else
global::setDarkTheme(true);
#else
global::setLightTheme();
if(args_set.count("--dark"))
global::setDarkTheme(true);
else
global::setLightTheme(true);
#endif

// GRAPH DATA
Expand All @@ -233,7 +239,7 @@ int main(int argc, char* argv[])
#endif

// Main loop
#ifdef __EMSCRIPTEN__
#ifdef EMSCRIPTEN_CODE
emscripten_log(EM_LOG_CONSOLE, "The main loop definition begin!");
#endif

Expand Down
5 changes: 3 additions & 2 deletions emscripten/src/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ void Field::FGraph::clear_annotations() {
}


Field::Field(float cell_size, Vec2 bounds): cell_size(cell_size), bounds(bounds), graphs() {}
Field::Field(float cell_size, Vec2 bounds):
cell_size(cell_size), bounds(bounds), graphs(),
is_dark_theme_selected(global::isDarkTheme) {}

pair<int, int> Field::get_field_index(const Vec2& point) const {
return {
Expand Down Expand Up @@ -301,7 +303,6 @@ void Field::display_window(){
ImGui::SameLine();
ImGui::Checkbox("Bounds", &bound_forces);

static bool is_dark_theme_selected = global::isDarkTheme;
ImGui::SameLine();
if(ImGui::Checkbox("Use dark theme", &is_dark_theme_selected)) {
if (is_dark_theme_selected) {
Expand Down
1 change: 1 addition & 0 deletions svelte/src/lib/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#canvas {
left: 0;
top: 0;
width: 100%;
}

html, body {
Expand Down
2 changes: 1 addition & 1 deletion svelte/src/lib/main.js

Large diffs are not rendered by default.

Binary file modified svelte/src/lib/main.wasm
Binary file not shown.

0 comments on commit d44f027

Please sign in to comment.