mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-06-04 20:46:29 +03:00
Small fix in the syntax tokenizer.
Fix in the key events received by the UICodeEditor. Reimplemented TextDocument::insert to improve performance. Dragged Tab relative position fix. Removed incorrect KeyDown event. Minor UI tweaks.
This commit is contained in:
@@ -607,7 +607,7 @@ Menu::CheckBox,
|
||||
Menu::Separator,
|
||||
Menu::SubMenu,
|
||||
Menu::RadioButton {
|
||||
padding-left: 4dp;
|
||||
padding-left: 6dp;
|
||||
padding-top: 2dp;
|
||||
padding-bottom: 2dp;
|
||||
background-color: transparent;
|
||||
@@ -631,7 +631,7 @@ Menu::RadioButton::text {
|
||||
Menu::Item::shortcut,
|
||||
Menu::CheckBox::shortcut,
|
||||
Menu::RadioButton::shortcut {
|
||||
padding-left: 8dp;
|
||||
padding-left: 48dp;
|
||||
padding-right: 8dp;
|
||||
color: var(--menu-font);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ class EE_API String {
|
||||
static bool isHexNotation( const std::string& value, const std::string& withPrefix = "" );
|
||||
|
||||
/** Split a String and hold it on a vector */
|
||||
static std::vector<String> split( const String& str, const Uint32& delim = '\n',
|
||||
static std::vector<String> split( const String& str, const StringBaseType& delim = '\n',
|
||||
const bool& pushEmptyString = false );
|
||||
|
||||
/** Split a string and hold it on a vector */
|
||||
@@ -761,6 +761,9 @@ class EE_API String {
|
||||
|
||||
StringBaseType lastChar() const;
|
||||
|
||||
std::vector<String> split( const StringBaseType& delim = '\n',
|
||||
const bool& pushEmptyString = false ) const;
|
||||
|
||||
private:
|
||||
friend EE_API bool operator==( const String& left, const String& right );
|
||||
friend EE_API bool operator<( const String& left, const String& right );
|
||||
|
||||
@@ -34,8 +34,12 @@ class EE_API StyleSheetLength {
|
||||
|
||||
static Unit unitFromString( std::string unitStr );
|
||||
|
||||
static std::string unitToString( const Unit& unit );
|
||||
|
||||
StyleSheetLength();
|
||||
|
||||
StyleSheetLength( const Float& val, const Unit& unit );
|
||||
|
||||
StyleSheetLength( std::string val, const Float& defaultValue = 0 );
|
||||
|
||||
StyleSheetLength( const StyleSheetLength& val );
|
||||
@@ -60,6 +64,8 @@ class EE_API StyleSheetLength {
|
||||
|
||||
static StyleSheetLength fromString( std::string str, const Float& defaultValue = 0 );
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
protected:
|
||||
Unit mUnit;
|
||||
Float mValue;
|
||||
|
||||
@@ -369,10 +369,8 @@ class EE_API TextDocument {
|
||||
|
||||
void remove( TextRange range, UndoStackContainer& undoStack, const Time& time );
|
||||
|
||||
TextPosition insert( const TextPosition& position, const String& text,
|
||||
UndoStackContainer& undoStack, const Time& time );
|
||||
|
||||
TextPosition insert( TextPosition position, const String::StringBaseType& text );
|
||||
TextPosition insert( TextPosition position, const String& text, UndoStackContainer& undoStack,
|
||||
const Time& time );
|
||||
|
||||
void appendLineIfLastLine( Int64 line );
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class EE_API UICodeEditorSplitter {
|
||||
|
||||
struct CodeEditorConfig {
|
||||
std::string colorScheme{"lite"};
|
||||
Float fontSize{11};
|
||||
StyleSheetLength fontSize{12, StyleSheetLength::Dp};
|
||||
bool showLineNumbers{true};
|
||||
bool showWhiteSpaces{true};
|
||||
bool highlightMatchingBracket{true};
|
||||
|
||||
@@ -52,7 +52,7 @@ bool String::isHexNotation( const std::string& value, const std::string& withPre
|
||||
std::string::npos;
|
||||
}
|
||||
|
||||
std::vector<String> String::split( const String& str, const Uint32& delim,
|
||||
std::vector<String> String::split( const String& str, const StringBaseType& delim,
|
||||
const bool& pushEmptyString ) {
|
||||
std::vector<String> cont;
|
||||
std::size_t current, previous = 0;
|
||||
@@ -264,6 +264,11 @@ String::StringBaseType String::lastChar() const {
|
||||
: mString[mString.size() - 1];
|
||||
}
|
||||
|
||||
std::vector<String> String::split( const StringBaseType& delim,
|
||||
const bool& pushEmptyString ) const {
|
||||
return String::split( *this, delim, pushEmptyString );
|
||||
}
|
||||
|
||||
std::vector<Uint8> String::stringToUint8( const std::string& str ) {
|
||||
return std::vector<Uint8>( str.begin(), str.end() );
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@ StyleSheetLength::Unit StyleSheetLength::unitFromString( std::string unitStr ) {
|
||||
return Unit::Pt;
|
||||
else if ( "pc" == unitStr )
|
||||
return Unit::Pc;
|
||||
else if ( "px" == unitStr )
|
||||
return Unit::Px;
|
||||
else if ( "dpi" == unitStr )
|
||||
return Unit::Dpi;
|
||||
else if ( "dpcm" == unitStr )
|
||||
@@ -44,12 +42,54 @@ StyleSheetLength::Unit StyleSheetLength::unitFromString( std::string unitStr ) {
|
||||
else if ( "vmax" == unitStr )
|
||||
return Unit::Vmax;
|
||||
else if ( "rem" == unitStr )
|
||||
return Unit::Dp;
|
||||
return Unit::Rem;
|
||||
return Unit::Px;
|
||||
}
|
||||
|
||||
std::string StyleSheetLength::unitToString( const StyleSheetLength::Unit& unit ) {
|
||||
switch ( unit ) {
|
||||
case Unit::Percentage:
|
||||
return "%";
|
||||
case Unit::Dp:
|
||||
return "dp";
|
||||
case Unit::Px:
|
||||
return "px";
|
||||
case Unit::In:
|
||||
return "in";
|
||||
case Unit::Cm:
|
||||
return "cm";
|
||||
case Unit::Mm:
|
||||
return "mm";
|
||||
case Unit::Em:
|
||||
return "em";
|
||||
case Unit::Ex:
|
||||
return "ex";
|
||||
case Unit::Pt:
|
||||
return "pt";
|
||||
case Unit::Pc:
|
||||
return "pc";
|
||||
case Unit::Dpi:
|
||||
return "dpi";
|
||||
case Unit::Dpcm:
|
||||
return "dpcm";
|
||||
case Unit::Vw:
|
||||
return "vw";
|
||||
case Unit::Vh:
|
||||
return "vh";
|
||||
case Unit::Vmin:
|
||||
return "vmin";
|
||||
case Unit::Vmax:
|
||||
return "vmax";
|
||||
case Unit::Rem:
|
||||
return "rem";
|
||||
}
|
||||
}
|
||||
|
||||
StyleSheetLength::StyleSheetLength() : mUnit( Px ), mValue( 0 ) {}
|
||||
|
||||
StyleSheetLength::StyleSheetLength( const Float& val, const StyleSheetLength::Unit& unit ) :
|
||||
mUnit( unit ), mValue( val ) {}
|
||||
|
||||
StyleSheetLength::StyleSheetLength( std::string val, const Float& defaultValue ) :
|
||||
StyleSheetLength( fromString( val, defaultValue ) ) {}
|
||||
|
||||
@@ -184,4 +224,10 @@ StyleSheetLength StyleSheetLength::fromString( std::string str, const Float& def
|
||||
return length;
|
||||
}
|
||||
|
||||
std::string StyleSheetLength::toString() const {
|
||||
if ( (Int64)mValue == mValue )
|
||||
return String::format( "%lld%s", (Int64)mValue, unitToString( mUnit ).c_str() );
|
||||
return String::format( "%.2f%s", mValue, unitToString( mUnit ).c_str() );
|
||||
}
|
||||
|
||||
}}} // namespace EE::UI::CSS
|
||||
|
||||
@@ -96,6 +96,9 @@ std::pair<std::vector<SyntaxToken>, int> SyntaxTokenizer::tokenize( const Syntax
|
||||
LuaPattern words( patternStr );
|
||||
int start, end = 0;
|
||||
if ( words.find( text, start, end, i ) && start != end ) {
|
||||
if ( pattern.patterns.size() >= 3 && i > 0 &&
|
||||
text[i - 1] == pattern.patterns[2][0] )
|
||||
continue;
|
||||
std::string patternText( text.substr( start, end - start ) );
|
||||
std::string type = syntax.getSymbol( patternText );
|
||||
pushToken( tokens, type.empty() ? pattern.type : type, patternText );
|
||||
|
||||
@@ -431,15 +431,33 @@ TextPosition TextDocument::insert( const TextPosition& position, const String& t
|
||||
return insert( position, text, mUndoStack.getUndoStackContainer(), mTimer.getElapsedTime() );
|
||||
}
|
||||
|
||||
TextPosition TextDocument::insert( const TextPosition& position, const String& text,
|
||||
TextPosition TextDocument::insert( TextPosition position, const String& text,
|
||||
UndoStackContainer& undoStack, const Time& time ) {
|
||||
TextPosition cursor = position;
|
||||
if ( text.empty() )
|
||||
return position;
|
||||
|
||||
position = sanitizePosition( position );
|
||||
size_t lineCount = mLines.size();
|
||||
|
||||
for ( size_t i = 0; i < text.length(); ++i ) {
|
||||
cursor = insert( cursor, text[i] );
|
||||
String before = mLines[position.line()].substr( 0, position.column() );
|
||||
String after = mLines[position.line()].substr( position.column() );
|
||||
std::vector<String> lines = text.split( '\n', true );
|
||||
Int64 linesAdd = eemax<Int64>( 0, static_cast<Int64>( lines.size() ) - 1 );
|
||||
for ( auto i = 0; i < linesAdd; i++ )
|
||||
lines[i] = lines[i] + "\n";
|
||||
lines[0] = before + lines[0];
|
||||
lines[lines.size() - 1] = lines[lines.size() - 1] + after;
|
||||
|
||||
mLines[position.line()] = TextDocumentLine( lines[0] );
|
||||
notifyLineChanged( position.line() );
|
||||
|
||||
for ( Int64 i = 1; i < (Int64)lines.size(); i++ ) {
|
||||
mLines.insert( mLines.begin() + position.line() + i, TextDocumentLine( lines[i] ) );
|
||||
notifyLineChanged( position.line() + i );
|
||||
}
|
||||
|
||||
TextPosition cursor = positionOffset( position, text.size() );
|
||||
|
||||
mUndoStack.pushSelection( undoStack, getSelection(), time );
|
||||
mUndoStack.pushRemove( undoStack, {position, cursor}, time );
|
||||
|
||||
@@ -452,44 +470,6 @@ TextPosition TextDocument::insert( const TextPosition& position, const String& t
|
||||
return cursor;
|
||||
}
|
||||
|
||||
TextPosition TextDocument::insert( TextPosition position, const String::StringBaseType& ch ) {
|
||||
position = sanitizePosition( position );
|
||||
bool atHead = position.column() == 0;
|
||||
bool atTail = position.column() == (Int64)line( position.line() ).length() - 1;
|
||||
if ( ch == '\n' ) {
|
||||
if ( atTail || atHead ) {
|
||||
size_t row = position.line();
|
||||
String line_content;
|
||||
for ( size_t i = position.column(); i < line( row ).length(); i++ )
|
||||
line_content.append( line( row )[i] );
|
||||
mLines.insert( mLines.begin() + position.line() + ( atTail ? 1 : 0 ), String( "\n" ) );
|
||||
notifyLineChanged( position.line() );
|
||||
return atTail
|
||||
? TextPosition( position.line() + 1, line( position.line() + 1 ).length() )
|
||||
: TextPosition( position.line() + 1, 0 );
|
||||
}
|
||||
TextDocumentLine newLine( line( position.line() )
|
||||
.substr( position.column(), line( position.line() ).length() -
|
||||
position.column() ) );
|
||||
TextDocumentLine& oldLine = line( position.line() );
|
||||
oldLine.setText( line( position.line() ).substr( 0, position.column() ) );
|
||||
// TODO: Investigate why this is needed when undo is used.
|
||||
// This fixes the case when a line ends up without an \n at the end of it.
|
||||
if ( oldLine.empty() || oldLine[oldLine.size() - 1] != '\n' ) {
|
||||
oldLine.append( '\n' );
|
||||
}
|
||||
if ( newLine.empty() || newLine[newLine.size() - 1] != '\n' ) {
|
||||
newLine.append( '\n' );
|
||||
}
|
||||
mLines.insert( mLines.begin() + position.line() + 1, std::move( newLine ) );
|
||||
notifyLineChanged( position.line() );
|
||||
return {position.line() + 1, 0};
|
||||
}
|
||||
line( position.line() ).insertChar( position.column(), ch );
|
||||
notifyLineChanged( position.line() );
|
||||
return {position.line(), position.column() + 1};
|
||||
}
|
||||
|
||||
void TextDocument::remove( TextPosition position ) {
|
||||
remove( TextRange( position, position ) );
|
||||
}
|
||||
@@ -577,7 +557,7 @@ TextPosition TextDocument::positionOffset( TextPosition position, int columnOffs
|
||||
}
|
||||
while ( position.line() < (Int64)mLines.size() - 1 &&
|
||||
position.column() > (Int64)eemax<Int64>( 0, mLines[position.line()].size() - 1 ) ) {
|
||||
position.setColumn( position.column() - mLines[position.line()].size() - 1 );
|
||||
position.setColumn( position.column() - mLines[position.line()].size() );
|
||||
position.setLine( position.line() + 1 );
|
||||
}
|
||||
return sanitizePosition( position );
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include <eepp/system/filesystem.hpp>
|
||||
#include <eepp/ui/tools/uicodeeditorsplitter.hpp>
|
||||
#include <eepp/ui/uimessagebox.hpp>
|
||||
#include <eepp/window/displaymanager.hpp>
|
||||
#include <eepp/window/engine.hpp>
|
||||
|
||||
using namespace EE::System;
|
||||
|
||||
@@ -97,7 +99,9 @@ UICodeEditor* UICodeEditorSplitter::createCodeEditor() {
|
||||
UICodeEditor* codeEditor = UICodeEditor::NewOpt( false, true );
|
||||
TextDocument& doc = codeEditor->getDocument();
|
||||
const CodeEditorConfig& editorConfig = mClient->getCodeEditorConfig();
|
||||
codeEditor->setFontSize( editorConfig.fontSize );
|
||||
DisplayManager* displayManager = Engine::instance()->getDisplayManager();
|
||||
codeEditor->setFontSize(
|
||||
editorConfig.fontSize.asDp( 0, Sizef(), displayManager->getDisplayIndex( 0 )->getDPI() ) );
|
||||
codeEditor->setEnableColorPickerOnSelection( true );
|
||||
codeEditor->setColorScheme( mColorSchemes[mCurrentColorScheme] );
|
||||
codeEditor->setShowLineNumber( editorConfig.showLineNumbers );
|
||||
|
||||
@@ -609,12 +609,11 @@ Uint32 UICodeEditor::onTextInput( const TextInputEvent& event ) {
|
||||
return 1;
|
||||
Input* input = getUISceneNode()->getWindow()->getInput();
|
||||
|
||||
if ( !input->isControlPressed() && !( input->isAltPressed() && input->isShiftPressed() ) ) {
|
||||
if ( input->isAltPressed() && !event.getText().empty() && event.getText()[0] == '\t' )
|
||||
return 1;
|
||||
if ( ( input->isLeftAltPressed() && !event.getText().empty() && event.getText()[0] == '\t' ) ||
|
||||
( input->isLeftAltPressed() && input->isShiftPressed() ) || input->isControlPressed() )
|
||||
return 1;
|
||||
|
||||
mDoc->textInput( event.getText() );
|
||||
}
|
||||
mDoc->textInput( event.getText() );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,23 +49,19 @@ Uint32 UITab::onDrag( const Vector2f& pos, const Uint32&, const Sizef& dragDiff
|
||||
if ( !tabW )
|
||||
return 0;
|
||||
Vector2f newPos( mPosition - dragDiff );
|
||||
if ( mFlags & UI_DRAG_VERTICAL )
|
||||
newPos = tabW->convertToNodeSpace( newPos );
|
||||
Uint32 index = tabW->getTabIndex( this );
|
||||
if ( index > 0 ) {
|
||||
UITab* tab = tabW->getTab( index - 1 );
|
||||
if ( tab ) {
|
||||
if ( newPos.x < tab->getPixelsPosition().x + tab->getPixelsSize().getWidth() * 0.5f ) {
|
||||
tabW->swapTabs( this, tab );
|
||||
}
|
||||
}
|
||||
if ( tab && newPos.x < tab->getPixelsPosition().x + tab->getPixelsSize().getWidth() * 0.5f )
|
||||
tabW->swapTabs( this, tab );
|
||||
}
|
||||
if ( index + 1 < tabW->getTabCount() ) {
|
||||
UITab* tab = tabW->getTab( index + 1 );
|
||||
if ( tab ) {
|
||||
if ( newPos.x + mSize.getWidth() >
|
||||
tab->getPixelsPosition().x + tab->getPixelsSize().getWidth() * 0.5f ) {
|
||||
tabW->swapTabs( tab, this );
|
||||
}
|
||||
}
|
||||
if ( tab && newPos.x + mSize.getWidth() >
|
||||
tab->getPixelsPosition().x + tab->getPixelsSize().getWidth() * 0.5f )
|
||||
tabW->swapTabs( tab, this );
|
||||
}
|
||||
if ( tabW->getAllowDragAndDropTabs() && !( mFlags & UI_DRAG_VERTICAL ) ) {
|
||||
mDragTotalDiff += ( Float )( mDragPoint.y - pos.y );
|
||||
|
||||
@@ -128,19 +128,9 @@ void InputSDL::update() {
|
||||
}
|
||||
case SDL_TEXTINPUT: {
|
||||
String txt = String::fromUtf8( SDLEvent.text.text );
|
||||
|
||||
EEEvent.Type = InputEvent::TextInput;
|
||||
EEEvent.text.timestamp = SDLEvent.text.timestamp;
|
||||
EEEvent.text.text = txt[0];
|
||||
|
||||
processEvent( &EEEvent );
|
||||
|
||||
EEEvent.Type = InputEvent::KeyDown;
|
||||
EEEvent.key.state = SDLEvent.key.state;
|
||||
EEEvent.key.which = SDLEvent.key.windowID;
|
||||
EEEvent.key.keysym.sym = KEY_UNKNOWN;
|
||||
EEEvent.key.keysym.mod = eeINDEX_NOT_FOUND;
|
||||
EEEvent.key.keysym.unicode = txt[0];
|
||||
break;
|
||||
}
|
||||
case SDL_KEYDOWN: {
|
||||
|
||||
@@ -247,11 +247,12 @@ void App::loadConfig() {
|
||||
mRecentFiles = String::split( recent, ';' );
|
||||
mInitColorScheme = mConfig.editor.colorScheme =
|
||||
mIni.getValue( "editor", "colorscheme", "lite" );
|
||||
mConfig.editor.fontSize = mIni.getValueF( "editor", "font_size", 11 );
|
||||
mConfig.editor.fontSize =
|
||||
mIni.getValue( "editor", "font_size", mDisplayDPI > 105 ? "11dp" : "14dp" );
|
||||
mConfig.window.size.setWidth(
|
||||
mIniState.getValueI( "window", "width", PixelDensity::dpToPxI( 1280 ) ) );
|
||||
mIniState.getValueI( "window", "width", mDisplayDPI > 105 ? 1920 : 1280 ) );
|
||||
mConfig.window.size.setHeight(
|
||||
mIniState.getValueI( "window", "height", PixelDensity::dpToPxI( 720 ) ) );
|
||||
mIniState.getValueI( "window", "height", mDisplayDPI > 105 ? 1080 : 720 ) );
|
||||
mConfig.window.maximized = mIniState.getValueB( "window", "maximized", false );
|
||||
mConfig.window.pixelDensity = mIniState.getValueF( "window", "pixeldensity" );
|
||||
mConfig.editor.showLineNumbers = mIni.getValueB( "editor", "show_line_numbers", true );
|
||||
@@ -261,7 +262,7 @@ void App::loadConfig() {
|
||||
mConfig.editor.highlightCurrentLine =
|
||||
mIni.getValueB( "editor", "highlight_current_line", true );
|
||||
mConfig.editor.horizontalScrollbar = mIni.getValueB( "editor", "horizontal_scrollbar", false );
|
||||
mConfig.ui.fontSize = mIni.getValueF( "ui", "font_size", 11 );
|
||||
mConfig.ui.fontSize = mIni.getValue( "ui", "font_size", mDisplayDPI > 105 ? "11dp" : "14dp" );
|
||||
mConfig.editor.trimTrailingWhitespaces =
|
||||
mIni.getValueB( "editor", "trim_trailing_whitespaces", false );
|
||||
mConfig.editor.forceNewLineAtEndOfFile =
|
||||
@@ -295,8 +296,8 @@ void App::saveConfig() {
|
||||
mConfig.editor.highlightMatchingBracket );
|
||||
mIni.setValueB( "editor", "highlight_current_line", mConfig.editor.highlightCurrentLine );
|
||||
mIni.setValueB( "editor", "horizontal_scrollbar", mConfig.editor.horizontalScrollbar );
|
||||
mIni.setValueF( "editor", "font_size", mConfig.editor.fontSize );
|
||||
mIni.setValueF( "ui", "font_size", mConfig.ui.fontSize );
|
||||
mIni.setValue( "editor", "font_size", mConfig.editor.fontSize.toString() );
|
||||
mIni.setValue( "ui", "font_size", mConfig.ui.fontSize.toString() );
|
||||
mIni.setValueB( "editor", "trim_trailing_whitespaces", mConfig.editor.trimTrailingWhitespaces );
|
||||
mIni.setValueB( "editor", "force_new_line_at_end_of_file",
|
||||
mConfig.editor.forceNewLineAtEndOfFile );
|
||||
@@ -616,18 +617,13 @@ UIMenu* App::createViewMenu() {
|
||||
UIMessageBox* msgBox =
|
||||
UIMessageBox::New( UIMessageBox::INPUT, "Set the editor font size:" );
|
||||
msgBox->setTitle( mWindowTitle );
|
||||
msgBox->getTextInput()->setAllowOnlyNumbers( true, true );
|
||||
msgBox->getTextInput()->setText( String::format(
|
||||
mConfig.editor.fontSize == (int)mConfig.editor.fontSize ? "%2.f" : "%2.1f",
|
||||
mConfig.editor.fontSize ) );
|
||||
msgBox->getTextInput()->setText( mConfig.editor.fontSize.toString() );
|
||||
msgBox->show();
|
||||
msgBox->addEventListener( Event::MsgBoxConfirmClick, [&, msgBox]( const Event* ) {
|
||||
Float val;
|
||||
if ( String::fromString( val, msgBox->getTextInput()->getText() ) ) {
|
||||
mConfig.editor.fontSize = val;
|
||||
mEditorSplitter->forEachEditor(
|
||||
[val]( UICodeEditor* editor ) { editor->setFontSize( val ); } );
|
||||
}
|
||||
mConfig.editor.fontSize = StyleSheetLength( msgBox->getTextInput()->getText() );
|
||||
mEditorSplitter->forEachEditor( [&]( UICodeEditor* editor ) {
|
||||
editor->setFontSize( mConfig.editor.fontSize.asDp( 0, Sizef(), mDisplayDPI ) );
|
||||
} );
|
||||
} );
|
||||
msgBox->addEventListener( Event::OnClose, [&]( const Event* ) {
|
||||
if ( mEditorSplitter->getCurEditor() )
|
||||
@@ -637,17 +633,11 @@ UIMenu* App::createViewMenu() {
|
||||
UIMessageBox* msgBox = UIMessageBox::New( UIMessageBox::INPUT,
|
||||
"Set the UI font size (requires restart):" );
|
||||
msgBox->setTitle( mWindowTitle );
|
||||
msgBox->getTextInput()->setAllowOnlyNumbers( true, true );
|
||||
msgBox->getTextInput()->setText(
|
||||
String::format( mConfig.ui.fontSize == (int)mConfig.ui.fontSize ? "%2.f" : "%2.1f",
|
||||
mConfig.ui.fontSize ) );
|
||||
msgBox->getTextInput()->setText( mConfig.ui.fontSize.toString() );
|
||||
msgBox->show();
|
||||
msgBox->addEventListener( Event::MsgBoxConfirmClick, [&, msgBox]( const Event* ) {
|
||||
Float val;
|
||||
if ( String::fromString( val, msgBox->getTextInput()->getText() ) ) {
|
||||
mConfig.ui.fontSize = val;
|
||||
msgBox->closeWindow();
|
||||
}
|
||||
mConfig.ui.fontSize = StyleSheetLength( msgBox->getTextInput()->getText() );
|
||||
msgBox->closeWindow();
|
||||
} );
|
||||
msgBox->addEventListener( Event::OnClose, [&]( const Event* ) {
|
||||
if ( mEditorSplitter->getCurEditor() )
|
||||
@@ -1150,10 +1140,12 @@ void App::updateEditorState() {
|
||||
}
|
||||
|
||||
void App::init( const std::string& file, const Float& pidelDensity ) {
|
||||
loadConfig();
|
||||
|
||||
DisplayManager* displayManager = Engine::instance()->getDisplayManager();
|
||||
Display* currentDisplay = displayManager->getDisplayIndex( 0 );
|
||||
mDisplayDPI = currentDisplay->getDPI();
|
||||
|
||||
loadConfig();
|
||||
|
||||
mConfig.window.pixelDensity =
|
||||
pidelDensity > 0 ? pidelDensity
|
||||
: ( mConfig.window.pixelDensity > 0 ? mConfig.window.pixelDensity
|
||||
@@ -1208,14 +1200,14 @@ void App::init( const std::string& file, const Float& pidelDensity ) {
|
||||
|
||||
UITheme* theme =
|
||||
UITheme::load( "uitheme", "uitheme", "", font, resPath + "assets/ui/breeze.css" );
|
||||
theme->setDefaultFontSize( mConfig.ui.fontSize );
|
||||
theme->setDefaultFontSize( mConfig.ui.fontSize.asDp( 0, Sizef(), mDisplayDPI ) );
|
||||
mUISceneNode->setStyleSheet( theme->getStyleSheet() );
|
||||
mUISceneNode
|
||||
->getUIThemeManager()
|
||||
//->setDefaultEffectsEnabled( true )
|
||||
->setDefaultTheme( theme )
|
||||
->setDefaultFont( font )
|
||||
->setDefaultFontSize( mConfig.ui.fontSize )
|
||||
->setDefaultFontSize( mConfig.ui.fontSize.asDp( 0, Sizef(), mDisplayDPI ) )
|
||||
->add( theme );
|
||||
|
||||
mUISceneNode->getRoot()->addClass( "appbackground" );
|
||||
@@ -1296,41 +1288,43 @@ void App::init( const std::string& file, const Float& pidelDensity ) {
|
||||
mUISceneNode->bind( "search_bar", mSearchBarLayout );
|
||||
mSearchBarLayout->setVisible( false )->setEnabled( false );
|
||||
UIIconTheme* iconTheme = UIIconTheme::New( "remixicon" );
|
||||
Float menuIconSize = mConfig.ui.fontSize.asPixels( 0, Sizef(), mDisplayDPI );
|
||||
Float buttonIconSize =
|
||||
StyleSheetLength::fromString( "16dp" ).asPixels( 0, Sizef(), mDisplayDPI );
|
||||
auto addIcon = [iconTheme, iconFont]( const std::string& name, const Uint32& codePoint,
|
||||
const Uint32& size ) {
|
||||
iconTheme->add( name,
|
||||
iconFont->getGlyphDrawable( codePoint, PixelDensity::dpToPx( size ) ) );
|
||||
iconTheme->add( name, iconFont->getGlyphDrawable( codePoint, size ) );
|
||||
};
|
||||
addIcon( "go-up", 0xea78, 16 );
|
||||
addIcon( "ok", 0xeb7a, 16 );
|
||||
addIcon( "cancel", 0xeb98, 16 );
|
||||
addIcon( "document-new", 0xecc3, 12 );
|
||||
addIcon( "document-open", 0xed70, 12 );
|
||||
addIcon( "document-save", 0xf0b3, 12 );
|
||||
addIcon( "document-save-as", 0xf0b3, 12 );
|
||||
addIcon( "document-close", 0xeb99, 12 );
|
||||
addIcon( "quit", 0xeb97, 12 );
|
||||
addIcon( "undo", 0xea58, 12 );
|
||||
addIcon( "redo", 0xea5a, 12 );
|
||||
addIcon( "redo", 0xea5a, 12 );
|
||||
addIcon( "cut", 0xf0c1, 12 );
|
||||
addIcon( "copy", 0xecd5, 12 );
|
||||
addIcon( "paste", 0xeb91, 12 );
|
||||
addIcon( "split-horizontal", 0xf17a, 12 );
|
||||
addIcon( "split-vertical", 0xf17b, 12 );
|
||||
addIcon( "find-replace", 0xed2b, 12 );
|
||||
addIcon( "folder", 0xed54, 12 );
|
||||
addIcon( "folder-add", 0xed5a, 12 );
|
||||
addIcon( "file", 0xecc3, 12 );
|
||||
addIcon( "file-code", 0xecd1, 12 );
|
||||
addIcon( "file-edit", 0xecdb, 12 );
|
||||
addIcon( "font-size", 0xed8d, 12 );
|
||||
addIcon( "color-picker", 0xf13d, 16 );
|
||||
addIcon( "zoom-in", 0xf2db, 12 );
|
||||
addIcon( "zoom-out", 0xf2dd, 12 );
|
||||
addIcon( "zoom-reset", 0xeb47, 12 );
|
||||
addIcon( "fullscreen", 0xed9c, 12 );
|
||||
addIcon( "keybindings", 0xee75, 12 );
|
||||
addIcon( "document-new", 0xecc3, menuIconSize );
|
||||
addIcon( "document-open", 0xed70, menuIconSize );
|
||||
addIcon( "document-save", 0xf0b3, menuIconSize );
|
||||
addIcon( "document-save-as", 0xf0b3, menuIconSize );
|
||||
addIcon( "document-close", 0xeb99, menuIconSize );
|
||||
addIcon( "quit", 0xeb97, menuIconSize );
|
||||
addIcon( "undo", 0xea58, menuIconSize );
|
||||
addIcon( "redo", 0xea5a, menuIconSize );
|
||||
addIcon( "redo", 0xea5a, menuIconSize );
|
||||
addIcon( "cut", 0xf0c1, menuIconSize );
|
||||
addIcon( "copy", 0xecd5, menuIconSize );
|
||||
addIcon( "paste", 0xeb91, menuIconSize );
|
||||
addIcon( "split-horizontal", 0xf17a, menuIconSize );
|
||||
addIcon( "split-vertical", 0xf17b, menuIconSize );
|
||||
addIcon( "find-replace", 0xed2b, menuIconSize );
|
||||
addIcon( "folder", 0xed54, menuIconSize );
|
||||
addIcon( "folder-add", 0xed5a, menuIconSize );
|
||||
addIcon( "file", 0xecc3, menuIconSize );
|
||||
addIcon( "file-code", 0xecd1, menuIconSize );
|
||||
addIcon( "file-edit", 0xecdb, menuIconSize );
|
||||
addIcon( "font-size", 0xed8d, menuIconSize );
|
||||
addIcon( "zoom-in", 0xf2db, menuIconSize );
|
||||
addIcon( "zoom-out", 0xf2dd, menuIconSize );
|
||||
addIcon( "zoom-reset", 0xeb47, menuIconSize );
|
||||
addIcon( "fullscreen", 0xed9c, menuIconSize );
|
||||
addIcon( "keybindings", 0xee75, menuIconSize );
|
||||
addIcon( "go-up", 0xea78, buttonIconSize );
|
||||
addIcon( "ok", 0xeb7a, buttonIconSize );
|
||||
addIcon( "cancel", 0xeb98, buttonIconSize );
|
||||
addIcon( "color-picker", 0xf13d, buttonIconSize );
|
||||
|
||||
mUISceneNode->getUIIconThemeManager()->setCurrentTheme( iconTheme );
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class UISearchBar : public UILinearLayout {
|
||||
};
|
||||
|
||||
struct UIConfig {
|
||||
Float fontSize{11};
|
||||
StyleSheetLength fontSize{12, StyleSheetLength::Dp};
|
||||
};
|
||||
|
||||
struct WindowConfig {
|
||||
@@ -126,6 +126,7 @@ class App : public UICodeEditorSplitter::Client {
|
||||
std::string mConfigPath;
|
||||
std::string mKeybindingsPath;
|
||||
SearchState mSearchState;
|
||||
Float mDisplayDPI;
|
||||
|
||||
void onFileDropped( String file );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user