Skip to content

Commit

Permalink
Merge pull request GLVis#299 from GLVis/style
Browse files Browse the repository at this point in the history
retroactive styling for GLVis#288
  • Loading branch information
tzanio authored Jul 25, 2024
2 parents 3713964 + fa1869f commit 53353c1
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 62 deletions.
20 changes: 11 additions & 9 deletions lib/aux_vis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1785,24 +1785,26 @@ void SetFont(const std::string& fn)
#endif
}

function<string(double)> NumberFormatter(int precision, char format, bool showsign)
function<string(double)> NumberFormatter(int precision, char format,
bool showsign)
{
return [precision, format, showsign](double x) -> string
{
ostringstream oss;
switch (format) {
switch (format)
{
case 'f':
oss << fixed;
break;
oss << fixed;
break;
case 's':
oss << scientific;
break;
oss << scientific;
break;
case 'd':
oss << defaultfloat;
break;
oss << defaultfloat;
break;
default:
MFEM_WARNING("Unknown formatting type. Using default. "
<< "Valid options include: ['f', 's', 'd']" << endl);
<< "Valid options include: ['f', 's', 'd']" << endl);
oss << defaultfloat;
break;
};
Expand Down
69 changes: 35 additions & 34 deletions lib/aux_vis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ bool SetFont(const vector<std::string>& patterns, int height);
void SetFont(const std::string& fn);

void SetUseHiDPI(bool status);
function<string(double)> NumberFormatter(int precision=4, char format='d', bool showsign=false);
function<string(double)> NumberFormatter(int precision=4, char format='d',
bool showsign=false);
function<string(double)> NumberFormatter(string formatting);
bool isValidNumberFormatting(const string& formatting);

Expand All @@ -148,40 +149,40 @@ bool isValidNumberFormatting(const string& formatting);
template <typename T>
T prompt(const string question,
const T* default_value = nullptr,
function<bool(T)> validator = [](T) { return true; })
function<bool(T)> validator = [](T) { return true; })
{
T input;
string strInput;

while (true)
{
cout << question << " ";
getline(cin, strInput);
stringstream buf(strInput);

if (strInput.empty() && default_value != nullptr)
{
cout << "Input empty. Using default value: " << *default_value << endl;
return *default_value;
}

if (buf >> input)
{
if (validator(input))
{
return input;
}
else
{
cout << "Input is not valid. Please try again." << endl;
}
}
else
{
cout << "Input can not be casted to expected type. Please try again." << endl;
}
}
return input;
T input;
string strInput;

while (true)
{
cout << question << " ";
getline(cin, strInput);
stringstream buf(strInput);

if (strInput.empty() && default_value != nullptr)
{
cout << "Input empty. Using default value: " << *default_value << endl;
return *default_value;
}

if (buf >> input)
{
if (validator(input))
{
return input;
}
else
{
cout << "Input is not valid. Please try again." << endl;
}
}
else
{
cout << "Input can not be casted to expected type. Please try again." << endl;
}
}
return input;
}

#endif
4 changes: 2 additions & 2 deletions lib/sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ void SdlWindow::mainIter()
keep_going = true;
break;
case SDL_KEYDOWN:
// For debugging: uncomment the next line to track key events.
// #define TRACK_KEY_EVENTS
// For debugging: uncomment the next line to track key events.
// #define TRACK_KEY_EVENTS
#ifdef TRACK_KEY_EVENTS
cout << "Event: SDL_KEYDOWN sym=" << e.key.keysym.sym
<< " mod=" << e.key.keysym.mod << endl;
Expand Down
21 changes: 14 additions & 7 deletions lib/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,8 @@ void communication_thread::execute()
char c;
string title;

*is[0] >> ws >> c; // read the opening char
// read the opening char
*is[0] >> ws >> c;
// use the opening char as termination as well
getline(*is[0], title, c);

Expand All @@ -1097,7 +1098,8 @@ void communication_thread::execute()
char c;
string caption;

*is[0] >> ws >> c; // read the opening char
// read the opening char
*is[0] >> ws >> c;
// use the opening char as termination as well
getline(*is[0], caption, c);

Expand All @@ -1119,7 +1121,8 @@ void communication_thread::execute()
char c;
string label_x, label_y, label_z;

*is[0] >> ws >> c; // read the opening char
// read the opening char
*is[0] >> ws >> c;
// use the opening char as termination as well
getline(*is[0], label_x, c);
*is[0] >> ws >> c;
Expand Down Expand Up @@ -1255,8 +1258,10 @@ void communication_thread::execute()
char c;
string formatting;

*is[0] >> ws >> c; // read the opening char
getline(*is[0], formatting, c); // read formatting string & use c for termination
// read the opening char
*is[0] >> ws >> c;
// read formatting string & use c for termination
getline(*is[0], formatting, c);

// all processors sent the command
for (size_t i = 1; i < is.size(); i++)
Expand All @@ -1276,8 +1281,10 @@ void communication_thread::execute()
char c;
string formatting;

*is[0] >> ws >> c; // read the opening char
getline(*is[0], formatting, c); // read formatting string & use c for termination
// read the opening char
*is[0] >> ws >> c;
// read formatting string & use c for termination
getline(*is[0], formatting, c);

// all processors sent the command
for (size_t i = 1; i < is.size(); i++)
Expand Down
20 changes: 10 additions & 10 deletions lib/vsdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,10 @@ void KeycPressed(GLenum state)
bool default_showsign = false;

int precision = prompt<int>("Enter precision (4): ",
&default_precision,
[](int p){ return p>=0; });
char format = prompt<char>("Enter format [(d)efault, (f)ixed, (s)cientific] (d): ",
&default_format,
[](char c){ return c=='d' || c=='f' || c=='s'; });
&default_precision, [](int p) { return p>=0; });
char format =
prompt<char>("Enter format [(d)efault, (f)ixed, (s)cientific] (d): ",
&default_format, [](char c) { return c=='d' || c=='f' || c=='s'; });
bool showsign = prompt<bool>("Show sign? [(1)true, (0)false] (0): ",
&default_showsign);
vsdata->SetColorbarNumberFormat(precision, format, showsign);
Expand Down Expand Up @@ -627,11 +626,12 @@ void Key_Mod_a_Pressed(GLenum state)
bool default_showsign = false;

int precision = prompt<int>("Enter precision (4): ",
&default_precision,
[](int p){ return p>=0; });
char format = prompt<char>("Enter format [(d)efault, (f)ixed, (s)cientific] (d): ",
&default_format,
[](char c){ return c=='d' || c=='f' || c=='s'; });
&default_precision, [](int p) { return p>=0; });

char format =
prompt<char>("Enter format [(d)efault, (f)ixed, (s)cientific] (d): ",
&default_format, [](char c) { return c=='d' || c=='f' || c=='s'; });

bool showsign = prompt<bool>("Show sign? [(1)true, (0)false] (0): ",
&default_showsign);
vsdata->SetAxisNumberFormat(precision, format, showsign);
Expand Down

0 comments on commit 53353c1

Please sign in to comment.