Skip to content

Commit

Permalink
Fix some display issues on phones.
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohns committed Jun 26, 2023
1 parent 1367ff7 commit 2e4bbb2
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 82 deletions.
3 changes: 2 additions & 1 deletion InterSpec/TerminalWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class InterSpec;
namespace Wt
{
class WLineEdit;
class WMenuItem;
}


Expand All @@ -61,7 +62,7 @@ class TerminalWidget : public Wt::WContainerWidget
protected:
void handleEnterKey(); //an example function that gets called when user pressed the enter key
void handleButtonClickedSignal( std::string argument ); //example function that gets called via m_buttonClickedSignal with the psosible JS filtered input text
void commandMenuItemSelected();
void commandMenuItemSelected( Wt::WMenuItem *item );
void commandMenuSearchInput();
void handleTextInput();
void textAdded();
Expand Down
3 changes: 1 addition & 2 deletions InterSpec_resources/InterSpecMobileCommon.css
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@
}



.ReferencePhotopeakDisplayMobile
.ReferencePhotopeakDisplay .ReferencePhotopeakDisplayMobile
{
padding-top: 0px;
padding-left: 2px;
Expand Down
22 changes: 11 additions & 11 deletions InterSpec_resources/ReferencePhotopeakDisplay.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@
flex-direction: column;
}

.ReferencePhotopeakDisplay .OtherNucs .OtherNucsHeader {
flex: 0 0 content;
}
.ReferencePhotopeakDisplay .OtherNucs .OtherNucsHeader {
flex: 0 0 content;
}

.ReferencePhotopeakDisplay .OtherNucs .OtherNucsContent {
margin-top: 0px;
flex: 1 0;
overflow-y: auto;
overflow-x: hidden;
display: flex;
flex-direction: column;
}
.ReferencePhotopeakDisplay .OtherNucs .OtherNucsContent {
margin-top: 0px;
flex: 1 0;
overflow-y: auto;
overflow-x: hidden;
display: flex;
flex-direction: column;
}

.ReferencePhotopeakDisplay .OtherNucs .OtherNucTypeHeader {
margin-top: 5px;
Expand Down
4 changes: 3 additions & 1 deletion js/TerminalWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ WT_DECLARE_WT_MEMBER
function( edit, command ){
edit.focus();

if( $(edit).hasClass("Wt-edit-emptyText") ) {
if( $(edit).hasClass("Wt-edit-emptyText")
|| command.toUpperCase().startsWith(edit.value.toUpperCase()) )
{
edit.value = command;
return;
}
Expand Down
7 changes: 6 additions & 1 deletion src/AuxWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,12 @@ AuxWindow::AuxWindow(const Wt::WString& windowTitle, Wt::WFlags<AuxWindowPropert
m_closedSignal->connect(boost::bind(&AuxWindow::setHidden, this, true, WAnimation()));
m_openedSignal->connect(boost::bind(&AuxWindow::setHidden, this, false, WAnimation()));

const string bringToFront = "function(){Wt.WT.AuxWindowBringToFront('" + id() + "');}";
// We wont bring dialog to top, if the user clicked a button on the title (primarily
// for mobile, where we might have buttons in the title)
const string bringToFront = "function(el){"
"if( el && el.target && !$(el.target).hasClass('Wt-btn') && !$(el.target).hasClass('FooterHelpBtn'))"
"Wt.WT.AuxWindowBringToFront('" + id() + "');"
"}";
title->clicked().connect(bringToFront);
title->mouseWentDown().connect(bringToFront); //XXX - doesnt seem to work
doJavaScript("$('#" + title->id() + "').mousedown(" + bringToFront + ");");
Expand Down
9 changes: 8 additions & 1 deletion src/ColorThemeWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,15 @@ m_apply( nullptr )
WContainerWidget *foot = footer();
AuxWindow::addHelpInFooter( foot, "color-theme-dialog" );

WCheckBox *autoDarkCb = new WCheckBox( "Auto apply \"Dark\" from OS", foot );
const bool phone = isPhone();
WCheckBox *autoDarkCb = new WCheckBox( "Auto apply \"Dark\" from OS" );
autoDarkCb->setFloatSide( Wt::Side::Left );
autoDarkCb->setToolTip( "Apply the \"Dark\" color theme automatically according to"
" the operating systems current value, or when it transisitions." );

if( !phone )
foot->addWidget( autoDarkCb );

InterSpecUser::associateWidget(m_interspec->m_user, "AutoDarkFromOs", autoDarkCb, m_interspec);

m_save = new WPushButton( "Save", foot );
Expand All @@ -274,6 +278,9 @@ m_apply( nullptr )
m_close = AuxWindow::addCloseButtonToFooter( "Close", true, foot );
m_close->clicked().connect( boost::bind( &AuxWindow::hide, this ) );

if( phone ) //Keep "Close" the left most item
foot->addWidget( autoDarkCb );

//To the menu add
vector<unique_ptr<ColorTheme>> defaultThemes = ColorTheme::predefinedThemes();

Expand Down
2 changes: 1 addition & 1 deletion src/DecayWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ DecayWindow::DecayWindow( InterSpec *viewer )
qr_btn->setText( "QR Code" );
qr_btn->setIcon( "InterSpec_resources/images/qr-code.svg" );
qr_btn->setStyleClass( "LinkBtn DownloadBtn DecayToolQrBtn" );

qr_btn->clicked().preventPropagation();
qr_btn->clicked().connect( std::bind( [this](){
try
{
Expand Down
40 changes: 23 additions & 17 deletions src/InterSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,18 +478,6 @@ InterSpec::InterSpec( WContainerWidget *parent )
assert( app );
//make it so InterSpec::instance() wont return nullptr for calls from within this constructor
app->m_viewer = this;


// We wont enable undo/redo when we are using mobile-menu (i.e., phones, or tablets that dont
// have desktop interface enabled).
std::unique_ptr<UndoRedoManager::BlockUndoRedoInserts> undo_blocker;
if( (UndoRedoManager::maxUndoRedoSteps() >= 0)
&& !app->isPhone()
&& (!app->isTablet() || InterSpecUser::preferenceValue<bool>("TabletUseDesktopMenus", this)) )
{
m_undo = new UndoRedoManager( this );
undo_blocker = std::unique_ptr<UndoRedoManager::BlockUndoRedoInserts>();
}//if( desktop interface )

//for notification div
m_notificationDiv = new WContainerWidget();
Expand Down Expand Up @@ -567,6 +555,21 @@ InterSpec::InterSpec( WContainerWidget *parent )

detectClientDeviceType();


// Now that we have m_sql and m_user setup, we can create the undo/redo manager, if we
// are using the desktop interface. We will create this manager before any our widgets
//
// We wont enable undo/redo when we are using mobile-menu (i.e., phones, or tablets that dont
// have desktop interface enabled).
std::unique_ptr<UndoRedoManager::BlockUndoRedoInserts> undo_blocker;
if( (UndoRedoManager::maxUndoRedoSteps() >= 0)
/* && !app->isPhone()
&& (!app->isTablet() || InterSpecUser::preferenceValue<bool>("TabletUseDesktopMenus", this)) */ )
{
m_undo = new UndoRedoManager( this );
undo_blocker = std::unique_ptr<UndoRedoManager::BlockUndoRedoInserts>();
}//if( desktop interface )

m_peakModel = new PeakModel( this );
m_spectrum = new D3SpectrumDisplayDiv();
m_timeSeries = new D3TimeChart();
Expand Down Expand Up @@ -5938,17 +5941,18 @@ void InterSpec::addEditMenu( Wt::WWidget *parent )

#if( !ANDROID )
// TODO: On Android we dont currently catch the download for these downloads with the content encoded in the URI, so we will just disable these for now there.
m_editMenuPopup->addSeparatorAt( 2 );
auto saveitem = m_editMenuPopup->insertMenuItem( 3, "Save Spectrum as PNG", "", true );
m_editMenuPopup->addSeparatorAt( (m_undo ? 2 : -1) );

auto saveitem = m_editMenuPopup->insertMenuItem( (m_undo ? 3 : -1), "Save Spectrum as PNG", "", true );
saveitem->triggered().connect( boost::bind(&InterSpec::saveChartToImg, this, true, true) );
saveitem = m_editMenuPopup->insertMenuItem( 4, "Save Spectrum as SVG", "", true );
saveitem = m_editMenuPopup->insertMenuItem( (m_undo ? 4 : -1), "Save Spectrum as SVG", "", true );
saveitem->triggered().connect( boost::bind(&InterSpec::saveChartToImg, this, true, false) );
#endif

#if( BUILD_AS_OSX_APP )
// All the macOS native menu stuff (copy/paste/select/etc) will be below our stuff
if( InterSpecApp::isPrimaryWindowInstance() )
m_editMenuPopup->addSeparatorAt( 5 );
m_editMenuPopup->addSeparatorAt( (m_undo ? 5 : -1) );
#endif
}//void addEditMenu( Wt::WWidget *menuDiv )

Expand Down Expand Up @@ -6013,7 +6017,7 @@ void InterSpec::addToolsTabToMenuItems()
m_tabToolsMenuItems[static_cast<int>(ToolTabMenuItems::NuclideSearch)] = item;


icon = "InterSpec_resources/images/auto_peak_search.svg";
icon = "InterSpec_resources/images/auto_peak_search.png";
item = m_toolsMenuPopup->insertMenuItem( index_offest + 4, "Auto Peak Search", icon, true );
item->triggered().connect( boost::bind( &PeakSearchGuiUtils::automated_search_for_peaks, this, true ) );
m_tabToolsMenuItems[static_cast<int>(ToolTabMenuItems::AutoPeakSearch)] = item;
Expand Down Expand Up @@ -8473,6 +8477,8 @@ void InterSpec::createRemoteRidWindow()

m_remoteRidMenuItem->disable();

// Need to add undo/redo here, and for RemoteRid

RemoteRid::startRemoteRidDialog( this, [this](AuxWindow *window, RemoteRid *rid ){
assert( (!window) == (!rid) );

Expand Down
11 changes: 2 additions & 9 deletions src/InterSpecApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,6 @@ InterSpecApp::InterSpecApp( const WEnvironment &env )
#endif

enableUpdates( true );

// Lets get a jump on initializing DecayDataBaseServer.
// Note however, in InterSpecServer::startServer and InterSpecServer::startWebServer we have
// already called DecayDataBaseServer::initialize() as soon as the thread pool was available, so
// this call will be a waste.
// TODO: once the localhost server is converted to using InterSpecServer, remove this next line
WServer::instance()->ioService().boost::asio::io_service::post( &DecayDataBaseServer::initialize );

setupDomEnvironment();
setupWidgets( true );

Expand Down Expand Up @@ -541,10 +533,11 @@ void InterSpecApp::setupWidgets( const bool attemptStateLoad )
}catch( std::exception &e )
{
#if( BUILD_AS_UNIT_TEST_SUITE )
cerr << "There was an exception initializing a InterSpec: " << e.what() << endl;
throw e;
#endif //#if( BUILD_AS_UNIT_TEST_SUITE )

Wt::log("error") << "There was an exception initializing a InterSpec: " << e.what();

string msg = "There was a problem initializing a necessary resource for InterSpec";
WText *errorText = new WText( msg, root() );
errorText->setInline( false );
Expand Down
9 changes: 7 additions & 2 deletions src/OneOverR2Calc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,16 @@ OneOverR2Calc::OneOverR2Calc()
InterSpecApp::DeviceOrientation orientation = InterSpecApp::DeviceOrientation::Unknown;
app->getSafeAreaInsets( orientation, safeAreas[0], safeAreas[1], safeAreas[2], safeAreas[3] );
#endif
repositionWindow( -32768, static_cast<int>(std::max(3.0f,0.5f*safeAreas[0])) );
setMaximumSize( WLength::Auto, viewer->renderedHeight() - std::max(0.5f*(safeAreas[0]+safeAreas[2]),6.0f) );
//repositionWindow( -32768, static_cast<int>(std::max(3.0f,0.5f*safeAreas[0])) );

// TODO: right now hardcoding width because otherwise width will go to like full-screen
const double width = 325;
const double height = viewer->renderedHeight() - std::max(0.5f*(safeAreas[0]+safeAreas[2]),6.0f);
setMaximumSize( width, height );

/* ToDo: get safe offsets in c++ land, and then also convert other AuxWindows that are modal on phone to resize correctly. */
/* Do same for Gamma XS Calc. And Energy Range Sum*/
centerWindowHeavyHanded();
}
}else
{
Expand Down
5 changes: 2 additions & 3 deletions src/PeakEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,8 @@ void PeakEdit::apply()
if( !isDirty() )
return;

UndoRedoManager::PeakModelChange peak_undo_creator;

const PeakDef revertPeak = *m_peakModel->peak( m_peakIndex ); //used to restore peak if catches an exception.

// Grab a few things for undo/redo
Expand Down Expand Up @@ -2193,9 +2195,6 @@ void PeakEdit::apply()
if( peakindex.isValid() )
{
Wt::WModelIndex index = m_peakModel->index( peakindex.row(), PeakModel::kPeakLineColor );

//blah blah blah, need to make undo/redo work with this

m_peakModel->setData( index, WString(newColor.isDefault() ? "none" : newColor.cssText(false)) );
}
}//if( this is the same nuclide/element/reaction )
Expand Down
10 changes: 2 additions & 8 deletions src/ReferencePhotopeakDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,17 +858,11 @@ ReferencePhotopeakDisplay::ReferencePhotopeakDisplay(
inputDiv->setLayout( inputLayout );


addStyleClass( "ReferencePhotopeakDisplay" );

const bool isPhone = m_spectrumViewer->isPhone();

if( isPhone )
{
addStyleClass( "ReferencePhotopeakDisplayMobile" );
//m_layout->setHorizontalSpacing( 5 );
}else
{
addStyleClass( "ReferencePhotopeakDisplay" );
}//if( specViewer->isPhone() ) / else


const WLength labelWidth(3.5,WLength::FontEm), fieldWidth(4,WLength::FontEm);
const WLength optionWidth(5.25,WLength::FontEm), buttonWidth(5.25,WLength::FontEm);
Expand Down
4 changes: 2 additions & 2 deletions src/RemoteRid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ void RestRidInterface::startRestAnalysis( const string ana_service_url )

WStringStream js;
js <<
"\n"
"\n(function(){"
"let sendAnaRequest = function(formData){\n"
" fetch('" << ana_service_url << "/analysis', {method: 'POST', body: formData})\n"
" .then(response => response.json() )\n"
Expand Down Expand Up @@ -1718,7 +1718,7 @@ void RestRidInterface::startRestAnalysis( const string ana_service_url )
" console.error( 'Error getting analysis input:', error);\n"
" const error_str = 'Error getting analysis input:' + error.toString();\n"
" " << m_analysis_error_signal.createCall( "error_str" ) << ";\n"
"});\n";
"});\n})();";

doJavaScript( js.str() );
}//void startRestAnalysis()
Expand Down
24 changes: 17 additions & 7 deletions src/SimpleDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ using namespace Wt;

#define INLINE_JAVASCRIPT(...) #__VA_ARGS__

/*
WT_DECLARE_WT_MEMBER
(SimpleDialogBringToFront, Wt::JavaScriptFunction, "SimpleDialogBringToFront",
function( id )
Expand All @@ -56,13 +55,13 @@ WT_DECLARE_WT_MEMBER

const z = parseInt( $('#'+id).css('z-index') );

if( isNaN(z) || maxz > z )
if( isNaN(z) || maxz >= z )
$('#'+id).css('z-index', maxz+1);
$('.window-controls-container').css('z-index', maxz + 2); //for wxWidgets and Electron builds
$('.suggestion').css('z-index', maxz+2);
}
);
*/


SimpleDialog::SimpleDialog()
: Wt::WDialog( InterSpec::instance() ), //for lifetime purposes
Expand Down Expand Up @@ -127,8 +126,6 @@ void SimpleDialog::init( const Wt::WString &title, const Wt::WString &content )
{
wApp->useStyleSheet( "InterSpec_resources/SimpleDialog.css" );

//LOAD_JAVASCRIPT(wApp, "SimpleDialog.cpp", "SimpleDialog", wtjsSimpleDialogBringToFront);

addStyleClass( "simple-dialog" );

setModal( true );
Expand Down Expand Up @@ -165,9 +162,22 @@ void SimpleDialog::init( const Wt::WString &title, const Wt::WString &content )
#if( WT_VERSION > 0x3040000 )
// I havent checked version of Wt that does include `raiseToFront()`, but 3.3.4 doesnt.
raiseToFront();

//This didnt appear to always work, at least on iOS. See SimpleDialogBringToFront
#endif

InterSpec *viewer = InterSpec::instance();
const bool isPhone = viewer && viewer->isPhone();

if( isPhone )
{
// On mobile, it seems Wt.WT.AuxWindowBringToFront(...) may get called after this window is
// created (happens on the "QR code" link on Nuclide Decay Tool - since the user clicks
// a button in the titlebar), which will bring that dialog above this one - which isnt wanted,
// so we'll manually bring this dialog to the top on a delay
LOAD_JAVASCRIPT(wApp, "SimpleDialog.cpp", "SimpleDialog", wtjsSimpleDialogBringToFront);
doJavaScript( "for( const d of [5,100,500]){"
"setTimeout( function(){ Wt.WT.SimpleDialogBringToFront('" + id() + "');}, d);"
"}");
}//if( isPhone )
}//init(...)


Expand Down
7 changes: 6 additions & 1 deletion src/SpecMeasManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,13 @@ class MultiUrlSpectrumDialog : public SimpleDialog
{
assert( manager );
assert( viewer );


#if( IOS || ANDROID )
WPushButton *btn = addButton( "Cancel" );
#else
addButton( "Cancel" );
#endif

finished().connect( m_manager, &SpecMeasManager::multiSpectrumDialogDone );

#if( IOS || ANDROID )
Expand Down
Loading

0 comments on commit 2e4bbb2

Please sign in to comment.