eepp: Fix UIScrollView size update.

ecode:More build settings WIP.
This commit is contained in:
Martín Lucas Golini
2023-05-31 00:14:31 -03:00
parent 64cf18d3bd
commit bd50db3cd8
8 changed files with 84 additions and 48 deletions

View File

@@ -43,6 +43,7 @@ void UIBorderDrawable::draw( const Vector2f& position, const Sizef& size ) {
}
// TODO: Implement color update.
// TODO: Optimize position update.
if ( mNeedsUpdate || mColorNeedsUpdate ) {
update();
}

View File

@@ -2550,7 +2550,7 @@ void UICodeEditor::updateHighlightWordCache() {
mHighlightWord.caseSensitive, mHighlightWord.wholeWord,
mHighlightWord.type, mHighlightWord.range );
Log::info( "Document search triggered in document: \"%s\", searched for "
"\"%s\" and took %2.f ms",
"\"%s\" and took %.2f ms",
mDoc->getFilename().c_str(),
mHighlightWord.text.toUtf8().c_str(),
docSearch.getElapsedTime().asMilliseconds() );

View File

@@ -179,7 +179,10 @@ void UIScrollView::containerUpdate() {
}
mContainer->setPosition( mPadding.Left, mPadding.Top );
mContainer->setSize( size );
// TODO: Fix layouting to avoid needing this hack.
if ( size != mContainer->getSize() )
runOnMainThread( [this, size]() { mContainer->setSize( size ); } );
mVScroll->setPosition( getSize().getWidth() - mVScroll->getSize().getWidth() - mPadding.Right,
mPadding.Top );

View File

@@ -3352,7 +3352,8 @@ TableView#locate_bar_table > tableview::row:selected > tableview::cell:nth-child
.settings_panel .span {
margin-top: 4dp;
}
.settings_panel #build_type_list {
.settings_panel #build_type_list,
.settings_panel #build_type_add {
margin-right: 4dp;
}
.settings_panel .build_types_cont {

View File

@@ -18,8 +18,8 @@ using json = nlohmann::json;
using namespace EE::Scene;
/** @return The process environment variables */
static std::unordered_map<std::string, std::string> getEnvironmentVariables() {
std::unordered_map<std::string, std::string> ret;
static ecode::ProjectBuildKeyVal getEnvironmentVariables() {
ecode::ProjectBuildKeyVal ret;
char** env;
#if defined( WIN ) && ( _MSC_VER >= 1900 )
env = *__p__environ();
@@ -32,12 +32,12 @@ static std::unordered_map<std::string, std::string> getEnvironmentVariables() {
auto var = String::split( *env, "=" );
if ( var.size() == 2 ) {
ret[var[0]] = var[1];
ret.push_back( std::make_pair( var[0], var[1] ) );
} else if ( var.size() > 2 ) {
auto val( var[1] );
for ( size_t i = 2; i < var.size(); ++i )
val += var[i];
ret[var[0]] = val;
ret.push_back( std::make_pair( var[0], val ) );
}
}
@@ -59,18 +59,18 @@ static void replaceVar( ProjectBuildStep& s, const std::string& var, const std::
String::replaceAll( s.workingDir, slashDup, FileSystem::getOSSlash() );
}
void ProjectBuild::replaceVars() {
const std::vector<ProjectBuildSteps*> steps{ &mBuild, &mClean };
for ( auto& step : steps ) {
for ( auto& s : *step ) {
replaceVar( s, VAR_PROJECT_ROOT, mProjectRoot );
for ( auto& var : mVars ) {
std::string varKey( "${" + var.first + "}" );
String::replaceAll( var.second, VAR_PROJECT_ROOT, mProjectRoot );
replaceVar( s, varKey, var.second );
}
ProjectBuildSteps ProjectBuild::replaceVars( const ProjectBuildSteps& steps ) const {
ProjectBuildSteps newSteps( steps );
for ( auto& s : newSteps ) {
replaceVar( s, VAR_PROJECT_ROOT, mProjectRoot );
for ( auto& var : mVars ) {
std::string varKey( "${" + var.first + "}" );
std::string varVal( var.second );
String::replaceAll( varVal, VAR_PROJECT_ROOT, mProjectRoot );
replaceVar( s, varKey, varVal );
}
}
return newSteps;
}
bool ProjectBuild::isOSSupported( const std::string& os ) const {
@@ -133,7 +133,9 @@ ProjectBuildCommandsRes ProjectBuildManager::generateBuildCommands( const std::s
std::string nproc = String::format( "%d", Sys::getCPUCount() );
ProjectBuildCommandsRes res;
for ( const auto& step : build.mBuild ) {
auto finalBuild( build.replaceVars( build.mBuild ) );
for ( const auto& step : finalBuild ) {
ProjectBuildCommand buildCmd( step, build.mEnvs );
replaceVar( buildCmd, VAR_OS, currentOS );
replaceVar( buildCmd, VAR_NPROC, nproc );
@@ -191,7 +193,9 @@ ProjectBuildCommandsRes ProjectBuildManager::generateCleanCommands( const std::s
std::string nproc = String::format( "%d", Sys::getCPUCount() );
ProjectBuildCommandsRes res;
for ( const auto& step : build.mClean ) {
auto finalBuild( build.replaceVars( build.mClean ) );
for ( const auto& step : finalBuild ) {
ProjectBuildCommand buildCmd( step, build.mEnvs );
replaceVar( buildCmd, VAR_OS, currentOS );
replaceVar( buildCmd, VAR_NPROC, nproc );
@@ -286,13 +290,13 @@ bool ProjectBuildManager::load() {
if ( buildObj.contains( "var" ) && buildObj["var"].is_object() ) {
const auto& vars = buildObj["var"];
for ( const auto& var : vars.items() )
b.mVars[var.key()] = var.value();
b.mVars.push_back( std::make_pair( var.key(), var.value() ) );
}
if ( buildObj.contains( "env" ) && buildObj["env"].is_object() ) {
const auto& vars = buildObj["env"];
for ( const auto& var : vars.items() )
b.mEnvs[var.key()] = var.value();
b.mEnvs.push_back( std::make_pair( var.key(), var.value() ) );
}
if ( buildObj.contains( "build" ) && buildObj["build"].is_array() ) {
@@ -374,8 +378,6 @@ bool ProjectBuildManager::load() {
b.mOutputParser = outputParser;
}
b.replaceVars();
mBuilds.insert( { build.key(), std::move( b ) } );
}
@@ -446,6 +448,14 @@ void ProjectBuildManager::cleanCurrentConfig( StatusBuildOutputController* sboc
}
}
static std::unordered_map<std::string, std::string>
toUnorderedMap( const ProjectBuildKeyVal& vec ) {
std::unordered_map<std::string, std::string> map;
for ( const auto& v : vec )
map[v.first] = v.second;
return map;
}
void ProjectBuildManager::runBuild( const std::string& buildName, const std::string& buildType,
const ProjectBuildi18nFn& i18n,
const ProjectBuildCommandsRes& res,
@@ -489,11 +499,11 @@ void ProjectBuildManager::runBuild( const std::string& buildName, const std::str
int progress = c > 0 ? c / (Float)totSteps : 0;
mProcess = std::make_unique<Process>();
auto options = Process::SearchUserPath | Process::NoWindow | Process::CombinedStdoutStderr;
std::unordered_map<std::string, std::string> env;
ProjectBuildKeyVal env;
if ( !cmd.config.clearSysEnv ) {
if ( !env.empty() ) {
env = getEnvironmentVariables();
env.insert( cmd.envs.begin(), cmd.envs.end() );
env.insert( env.begin(), cmd.envs.begin(), cmd.envs.end() );
} else {
options |= Process::InheritEnvironment;
}
@@ -506,7 +516,8 @@ void ProjectBuildManager::runBuild( const std::string& buildName, const std::str
continue;
}
if ( mProcess->create( cmd.cmd, cmd.args, options, env, cmd.workingDir ) ) {
if ( mProcess->create( cmd.cmd, cmd.args, options, toUnorderedMap( env ),
cmd.workingDir ) ) {
if ( progressFn )
progressFn( progress,
Sys::getDateTimeStr() + ": " +
@@ -644,12 +655,13 @@ void ProjectBuildManager::updateSidePanelTab() {
updateBuildType();
buildList->removeEventsOfType( Event::OnItemSelected );
buildList->addEventListener( Event::OnItemSelected, [this, buildEdit, buildList]( const Event* ) {
mConfig.buildName = buildList->getListBox()->getItemSelectedText();
mConfig.buildType = "";
buildEdit->setEnabled( true );
updateBuildType();
} );
buildList->addEventListener(
Event::OnItemSelected, [this, buildEdit, buildList]( const Event* ) {
mConfig.buildName = buildList->getListBox()->getItemSelectedText();
mConfig.buildType = "";
buildEdit->setEnabled( true );
updateBuildType();
} );
buildButton->setEnabled( !mConfig.buildName.empty() && hasBuild( mConfig.buildName ) &&
hasBuildCommands( mConfig.buildName ) );
@@ -681,7 +693,7 @@ void ProjectBuildManager::updateSidePanelTab() {
[this]( const Event* ) {
mNewBuild = ProjectBuild( mApp->i18n( "new_name", "new_name" ), mProjectRoot );
auto ret = mApp->getSplitter()->createWidget(
UIBuildSettings::New( mNewBuild ),
UIBuildSettings::New( mNewBuild, mConfig ),
mApp->i18n( "build_settings", "Build Settings" ) );
ret.first->setIcon( mApp->findIcon( "hammer" ) );
},
@@ -693,7 +705,7 @@ void ProjectBuildManager::updateSidePanelTab() {
auto build = mBuilds.find( mConfig.buildName );
if ( build != mBuilds.end() ) {
auto ret = mApp->getSplitter()->createWidget(
UIBuildSettings::New( build->second ),
UIBuildSettings::New( build->second, mConfig ),
mApp->i18n( "build_settings", "Build Settings" ) );
ret.first->setIcon( mApp->findIcon( "hammer" ) );
}

View File

@@ -87,7 +87,7 @@ struct ProjectBuildStep {
};
using ProjectBuildSteps = std::vector<ProjectBuildStep>;
using ProjectBuildKeyVal = std::unordered_map<std::string, std::string>;
using ProjectBuildKeyVal = std::vector<std::pair<std::string, std::string>>;
struct ProjectBuildConfig {
bool clearSysEnv{ false };
@@ -142,6 +142,8 @@ class ProjectBuild {
bool hasClean() const { return !mClean.empty(); }
ProjectBuildSteps replaceVars( const ProjectBuildSteps& steps ) const;
protected:
friend class ProjectBuildManager;
friend class UIBuildSettings;
@@ -156,8 +158,6 @@ class ProjectBuild {
ProjectBuildKeyVal mVars;
ProjectBuildConfig mConfig;
ProjectBuildOutputParser mOutputParser;
void replaceVars();
};
using ProjectBuildMap = std::unordered_map<std::string, ProjectBuild>;

View File

@@ -1,7 +1,11 @@
#include "uibuildsettings.hpp"
#include <eepp/ui/models/itemlistmodel.hpp>
#include <eepp/ui/uicheckbox.hpp>
#include <eepp/ui/uidropdownlist.hpp>
#include <eepp/ui/uilinearlayout.hpp>
#include <eepp/ui/uitableview.hpp>
using namespace EE::UI::Models;
namespace ecode {
@@ -115,9 +119,9 @@ static const auto SETTINGS_PANEL_XML = R"xml(
<TextView lw="mp" lh="wc" word-wrap="true" text="@string(build_types_desc, Build types can be used as a dynamic build option represented by the special key ${build_type}. The build type can be switch easily from the editor.)" />
<StackLayout class="build_types_cont span" lw="mp" lh="wc">
<DropDownList id="build_type_list" layout_width="200dp" layout_height="wc" />
<PushButton lh="mp" id="build_type_del" text="@string(delete_selected, Delete Selected)" text-as-fallback="true" icon="icon(delete-bin, 12dp)" tooltip="@string(delete_selected, Delete Selected)" />
<PushButton id="build_type_add" lh="mp" text="@string(add_build_type, Add Build Type)" tooltip="@string(add_build_type, Add Build Type)" text-as-fallback="true" icon="icon(add, 12dp)" />
<PushButton id="build_type_del" lh="mp" text="@string(delete_selected, Delete Selected)" text-as-fallback="true" icon="icon(delete-bin, 12dp)" tooltip="@string(delete_selected, Delete Selected)" />
</StackLayout>
<PushButton id="build_type_add" class="span" text="@string(add_build_type, Add Build Type)" />
</vbox>
<vbox class="advanced_options" lw="mp" lh="wc">
@@ -128,7 +132,7 @@ static const auto SETTINGS_PANEL_XML = R"xml(
<vbox class="inner_box" lw="mp" lh="wc">
<vbox lw="mp" lh="wc" class="build_environment">
<TextView class="subtitle" text="@string(build_environment, Build Environment)" />
<CheckBox text="@string(clear_system_enviroment, Clear System Environment)" />
<CheckBox id="clear_sys_env" text="@string(clear_system_enviroment, Clear System Environment)" />
</vbox>
<vbox lw="mp" lh="wc" class="output_parser">
@@ -151,7 +155,7 @@ static const auto SETTINGS_PANEL_XML = R"xml(
<TextView class="subtitle" text="@string(custom_variables, Custom Variables)" />
<TextView lw="mp" lh="wc" word-wrap="true" text='@string(custom_variables_desc, "Custom Variables allow to simplify the build commands steps adding custom variables that can be used over the build settings in commands, arguments, and working directories.")' />
<TextView lw="mp" lh="wc" word-wrap="true" text='@string(custom_variables_desc_2, "Custom Variables can be invoked using ${variable_name} in any of the commands.)' />
<TableView lw="mp" lh="150dp" />
<TableView id="table_vars" lw="mp" lh="150dp" />
<TextView class="span" lw="mp" lh="wc" word-wrap="true" text='@string(custom_variables_desc_3, There are predefined custom variables available to use:&#10;${project_root}: The folder / project root directory.&#10;${build_type}: The build type selected to build the project.&#10;${os}: The current operating system name.&#10;${nproc}: The number of logical processing units.)' />
</vbox>
</vbox>
@@ -163,11 +167,12 @@ static const auto SETTINGS_PANEL_XML = R"xml(
</ScrollView>
)xml";
UIBuildSettings* UIBuildSettings::New( ProjectBuild& build ) {
return eeNew( UIBuildSettings, ( build ) );
UIBuildSettings* UIBuildSettings::New( ProjectBuild& build, ProjectBuildConfiguration& config ) {
return eeNew( UIBuildSettings, ( build, config ) );
}
UIBuildSettings::UIBuildSettings( ProjectBuild& build ) : mBuild( build ) {
UIBuildSettings::UIBuildSettings( ProjectBuild& build, ProjectBuildConfiguration& config ) :
mBuild( build ), mConfig( config ) {
mUISceneNode->loadLayoutFromString( SETTINGS_PANEL_XML, this,
String::hash( "build_settings" ) );
mDataBindHolder += UIDataBindString::New( &mBuild.mName, find<UITextInput>( "build_name" ) );
@@ -202,7 +207,10 @@ UIBuildSettings::UIBuildSettings( ProjectBuild& build ) : mBuild( build ) {
for ( const auto& type : mBuild.mBuildTypes )
buildTypes.push_back( type );
buildTypeDropDown->getListBox()->addListBoxItems( buildTypes );
buildTypeDropDown->getListBox()->setSelected( 0 );
buildTypeDropDown->getListBox()->setSelected( mConfig.buildType );
buildTypeDropDown->on( Event::OnItemSelected, [this, buildTypeDropDown]( const Event* ) {
mConfig.buildType = buildTypeDropDown->getListBox()->getItemSelectedText().toUtf8();
} );
auto advTitle = querySelector( ".settings_panel > .advanced_options > .title" );
advTitle->addMouseClickListener(
@@ -212,6 +220,16 @@ UIBuildSettings::UIBuildSettings( ProjectBuild& build ) : mBuild( build ) {
img->toggleClass( "expanded" );
},
MouseButton::EE_BUTTON_LEFT );
mDataBindHolder +=
UIDataBindBool::New( &mBuild.mConfig.clearSysEnv, find<UIWidget>( "clear_sys_env" ) );
UITableView* tableVars = find<UITableView>( "table_vars" );
auto model = ItemPairListModel<std::string, std::string>::create( mBuild.mVars );
model->setColumnName( 0, getTranslatorString( "var_name", "Name" ) );
model->setColumnName( 1, getTranslatorString( "var_value", "Value" ) );
tableVars->setAutoColumnsWidth( true );
tableVars->setModel( model );
}
void UIBuildSettings::updateOS() {

View File

@@ -2,8 +2,8 @@
#define EE_UI_UIBUILDSETTINGS_HPP
#include "projectbuild.hpp"
#include <eepp/ui/uirelativelayout.hpp>
#include <eepp/ui/uidatabind.hpp>
#include <eepp/ui/uirelativelayout.hpp>
using namespace EE::UI;
@@ -11,13 +11,14 @@ namespace ecode {
class UIBuildSettings : public UIRelativeLayout {
public:
static UIBuildSettings* New( ProjectBuild& build );
static UIBuildSettings* New( ProjectBuild& build, ProjectBuildConfiguration& config );
protected:
ProjectBuild& mBuild;
ProjectBuildConfiguration& mConfig;
UIDataBindHolder mDataBindHolder;
explicit UIBuildSettings( ProjectBuild& build );
explicit UIBuildSettings( ProjectBuild& build, ProjectBuildConfiguration& config );
void updateOS();
};