mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-13 04:42:12 +03:00
Minor clean up and fixes.
This commit is contained in:
@@ -65,9 +65,13 @@
|
||||
<TextView layout_width="match_parent" layout_height="match_parent" font-size="24dp" text="Hello World!" gravity="center" />
|
||||
<Loader layout_width="350dp" layout_height="350dp" layout_gravity="center" padding="44dp" outline-thickness="8dp" />
|
||||
</RelativeLayout>
|
||||
<RelativeLayout id="test_3" layout_width="match_parent" layout_height="match_parent">
|
||||
<CodeEditor layout_width="match_parent" layout_height="match_parent" />
|
||||
</RelativeLayout>
|
||||
|
||||
<Tab text="Padding Test" owns="test_1" />
|
||||
<Tab text="Tabs Test" owns="test_2" />
|
||||
<Tab text="Code Editor Test" owns="test_3" />
|
||||
</TabWidget>
|
||||
</vbox>
|
||||
<window windowFlags="default|maximize|minimize|shadow" layout_width="300dp" layout_height="300dp" x="400dp" y="300dp" window-title="Test Window">
|
||||
|
||||
@@ -36,9 +36,35 @@
|
||||
--win-icon: #dbdbdd;
|
||||
}
|
||||
|
||||
* {
|
||||
CheckBox,
|
||||
ComboBox,
|
||||
ComboBox::DropDownList::ListBox::item,
|
||||
DropDownList,
|
||||
DropDownList::ListBox::item,
|
||||
ListBox::item,
|
||||
Menu::item,
|
||||
Menu::SubMenu,
|
||||
PushButton,
|
||||
RadioButton,
|
||||
SelectButton,
|
||||
SpinBox::input,
|
||||
Tab,
|
||||
TextEdit,
|
||||
TextInput,
|
||||
TextInputPassword,
|
||||
TextView,
|
||||
Tooltip,
|
||||
MenuBar::button {
|
||||
color: var(--font);
|
||||
font-size: 11dp;
|
||||
}
|
||||
|
||||
TextView,
|
||||
TextEdit,
|
||||
TextInput,
|
||||
TextInputPassword,
|
||||
ComboBox::DropDownList,
|
||||
SpinBox::input, {
|
||||
selection-back-color: var(--primary);
|
||||
}
|
||||
|
||||
|
||||
@@ -916,6 +916,16 @@ or one of the special constants.
|
||||
|
||||
---
|
||||
|
||||
### locked
|
||||
|
||||
Enable or disable editing on code editor elements.
|
||||
|
||||
* Applicable to: EE::UI::UICodeEditor (TextEdit)
|
||||
* Data Type: [boolean](#boolean-data-type)
|
||||
* Default value: `false`
|
||||
|
||||
---
|
||||
|
||||
### margin-bottom
|
||||
|
||||
Read [margin-bottom](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-bottom) documentation.
|
||||
|
||||
@@ -160,6 +160,8 @@ class EE_API Color : public tColor<Uint8> {
|
||||
|
||||
std::string toHexString( const bool& prependHash = true ) const;
|
||||
|
||||
Color& blendAlpha( const Uint8& alpha );
|
||||
|
||||
static Color fromHsl( const Colorf& hsl );
|
||||
|
||||
/** Blend a source color to destination color */
|
||||
|
||||
@@ -131,6 +131,7 @@ enum class PropertyId : Uint32 {
|
||||
HalfSlider = String::hash( "half-slider" ),
|
||||
Owns = String::hash( "owns" ),
|
||||
AllowEditing = String::hash( "allow-editing" ),
|
||||
Locked = String::hash( "locked" ),
|
||||
MaxLength = String::hash( "max-length" ),
|
||||
FreeEditing = String::hash( "free-editing" ),
|
||||
Numeric = String::hash( "numeric" ),
|
||||
|
||||
@@ -55,16 +55,40 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
|
||||
|
||||
UICodeEditor* setFontSize( Float dpSize );
|
||||
|
||||
const Float& getFontSize() const;
|
||||
|
||||
UICodeEditor* setFontColor( const Color& color );
|
||||
|
||||
const Color& getFontColor() const;
|
||||
|
||||
UICodeEditor* setFontSelectedColor( const Color& color );
|
||||
|
||||
const Color& getFontSelectedColor();
|
||||
|
||||
UICodeEditor* setFontSelectionBackColor( const Color& color );
|
||||
|
||||
const Color& getFontSelectionBackColor() const;
|
||||
|
||||
UICodeEditor* setFontShadowColor( const Color& color );
|
||||
|
||||
const Color& getFontShadowColor() const;
|
||||
|
||||
UICodeEditor* setFontStyle( const Uint32& fontStyle );
|
||||
|
||||
const Uint32& getTabWidth() const;
|
||||
|
||||
UICodeEditor* setTabWidth( const Uint32& tabWidth );
|
||||
|
||||
const Uint32& getFontStyle() const;
|
||||
|
||||
const Float& getOutlineThickness() const;
|
||||
|
||||
UICodeEditor* setOutlineThickness( const Float& outlineThickness );
|
||||
|
||||
const Color& getOutlineColor() const;
|
||||
|
||||
UICodeEditor* setOutlineColor( const Color& outlineColor );
|
||||
|
||||
const Float& getMouseWheelScroll() const;
|
||||
|
||||
void setMouseWheelScroll( const Float& mouseWheelScroll );
|
||||
@@ -125,6 +149,10 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
|
||||
|
||||
void setLineNumberActiveFontColor( const Color& lineNumberActiveFontColor );
|
||||
|
||||
bool isTextSelectionEnabled() const;
|
||||
|
||||
void setTextSelection( const bool& active );
|
||||
|
||||
KeyBindings& getKeyBindings();
|
||||
|
||||
void setKeyBindings( const KeyBindings& keyBindings );
|
||||
@@ -158,7 +186,11 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
|
||||
|
||||
void addUnlockedCommand( const std::string& command );
|
||||
|
||||
protected:
|
||||
virtual bool applyProperty( const StyleSheetProperty& attribute );
|
||||
|
||||
virtual std::string getPropertyString( const PropertyDefinition* propertyDef,
|
||||
const Uint32& propertyIndex = 0 );
|
||||
protected:
|
||||
struct LastXOffset {
|
||||
TextPosition position;
|
||||
Float offset;
|
||||
|
||||
@@ -15,7 +15,7 @@ class UIFontStyleConfig : public FontStyleConfig {
|
||||
public:
|
||||
const Color& getFontSelectedColor() const { return FontSelectedColor; }
|
||||
|
||||
Color getFontSelectionBackColor() const { return FontSelectionBackColor; }
|
||||
const Color& getFontSelectionBackColor() const { return FontSelectionBackColor; }
|
||||
|
||||
void setFontSelectedColor( const Color& color ) { FontSelectedColor = color; }
|
||||
|
||||
|
||||
@@ -232,6 +232,11 @@ std::string Color::toHexString( const bool& prependHashtag ) const {
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
Color& Color::blendAlpha( const Uint8& alpha ) {
|
||||
this->a = static_cast<Uint8>( ( alpha * this->a ) / 255.f );
|
||||
return *this;
|
||||
}
|
||||
|
||||
static Float hue2rgb( Float p, Float q, Float t ) {
|
||||
if ( t < 0.f )
|
||||
t += 1.f;
|
||||
|
||||
@@ -274,6 +274,7 @@ void StyleSheetSpecification::registerDefaultProperties() {
|
||||
registerProperty( "half-slider", "" ).setType( PropertyType::Bool );
|
||||
registerProperty( "owns", "" ).setType( PropertyType::String );
|
||||
registerProperty( "allow-editing", "" ).setType( PropertyType::Bool );
|
||||
registerProperty( "locked", "" ).setType( PropertyType::Bool );
|
||||
registerProperty( "max-length", "" ).setType( PropertyType::NumberInt );
|
||||
registerProperty( "free-editing", "" ).setType( PropertyType::Bool );
|
||||
registerProperty( "numeric", "" ).setType( PropertyType::Bool );
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <eepp/ui/uieventdispatcher.hpp>
|
||||
#include <eepp/ui/uiscenenode.hpp>
|
||||
#include <eepp/ui/uiscrollbar.hpp>
|
||||
#include <eepp/ui/uithememanager.hpp>
|
||||
#include <eepp/window/clipboard.hpp>
|
||||
#include <eepp/window/input.hpp>
|
||||
#include <eepp/window/window.hpp>
|
||||
@@ -36,6 +37,7 @@ UICodeEditor::UICodeEditor() :
|
||||
mHighlighter( &mDoc ),
|
||||
mKeyBindings( getUISceneNode()->getWindow()->getInput() ) {
|
||||
mFlags |= UI_TAB_STOP;
|
||||
setTextSelection( true );
|
||||
setColorScheme( SyntaxColorScheme::getDefault() );
|
||||
mVScrollBar = UIScrollBar::NewVertical();
|
||||
mVScrollBar->setParent( this );
|
||||
@@ -49,6 +51,8 @@ UICodeEditor::UICodeEditor() :
|
||||
eePRINTL( "A monospace font must be loaded to be able to use the code editor.\nTry loading "
|
||||
"a font with the name \"monospace\"" );
|
||||
|
||||
setFontSize( getUISceneNode()->getUIThemeManager()->getDefaultFontSize() );
|
||||
|
||||
clipEnable();
|
||||
mDoc.registerClient( *this );
|
||||
subscribeScheduledUpdate();
|
||||
@@ -84,19 +88,22 @@ void UICodeEditor::draw() {
|
||||
updateEditor();
|
||||
}
|
||||
|
||||
Color col;
|
||||
std::pair<int, int> lineRange = getVisibleLineRange();
|
||||
Float charSize = PixelDensity::pxToDp( getCharacterSize() );
|
||||
Float lineHeight = getLineHeight();
|
||||
int lineNumberDigits = getLineNumberDigits();
|
||||
Float lineNumberWidth = mShowLineNumber ? getLineNumberWidth() : 0.f;
|
||||
Vector2f screenStart( mScreenPos.x + mRealPadding.Left, mScreenPos.y + mRealPadding.Top );
|
||||
Vector2f screenStart( eefloor( mScreenPos.x + mRealPadding.Left ),
|
||||
eefloor( mScreenPos.y + mRealPadding.Top ) );
|
||||
Vector2f start( screenStart.x + lineNumberWidth, screenStart.y );
|
||||
Vector2f startScroll( start - mScroll );
|
||||
Primitives primitives;
|
||||
TextPosition cursor( mDoc.getSelection().start() );
|
||||
|
||||
if ( !mLocked && mHighlightCurrentLine ) {
|
||||
primitives.setColor( mCurrentLineBackgroundColor );
|
||||
|
||||
primitives.setColor( Color( mCurrentLineBackgroundColor ).blendAlpha( mAlpha ) );
|
||||
primitives.drawRectangle( Rectf(
|
||||
Vector2f( startScroll.x + mScroll.x, startScroll.y + cursor.line() * lineHeight ),
|
||||
Sizef( mSize.getWidth(), lineHeight ) ) );
|
||||
@@ -104,7 +111,7 @@ void UICodeEditor::draw() {
|
||||
|
||||
if ( mLineBreakingColumn ) {
|
||||
Float lineBreakingOffset = start.x + getGlyphWidth() * mLineBreakingColumn;
|
||||
primitives.setColor( mLineBreakColumnColor );
|
||||
primitives.setColor( Color( mLineBreakColumnColor ).blendAlpha( mAlpha ) );
|
||||
primitives.drawLine(
|
||||
{{lineBreakingOffset, start.y}, {lineBreakingOffset, start.y + mSize.getHeight()}} );
|
||||
}
|
||||
@@ -122,11 +129,11 @@ void UICodeEditor::draw() {
|
||||
drawLineText( i, {startScroll.x, startScroll.y + lineHeight * i}, charSize );
|
||||
}
|
||||
|
||||
if ( mCursorVisible && !mLocked ) {
|
||||
if ( mCursorVisible && !mLocked && isTextSelectionEnabled() ) {
|
||||
Vector2f cursorPos( startScroll.x + getXOffsetCol( cursor ),
|
||||
startScroll.y + cursor.line() * lineHeight );
|
||||
|
||||
primitives.setColor( mCaretColor );
|
||||
primitives.setColor( Color( mCaretColor ).blendAlpha( mAlpha ) );
|
||||
primitives.drawRectangle(
|
||||
Rectf( cursorPos, Sizef( PixelDensity::dpToPx( 2 ), lineHeight ) ) );
|
||||
}
|
||||
@@ -205,6 +212,10 @@ UICodeEditor* UICodeEditor::setFontSize( Float dpSize ) {
|
||||
return this;
|
||||
}
|
||||
|
||||
const Float& UICodeEditor::getFontSize() const {
|
||||
return mFontStyleConfig.getFontCharacterSize();
|
||||
}
|
||||
|
||||
UICodeEditor* UICodeEditor::setFontColor( const Color& color ) {
|
||||
if ( mFontStyleConfig.getFontColor() != color ) {
|
||||
mFontStyleConfig.FontColor = color;
|
||||
@@ -213,6 +224,14 @@ UICodeEditor* UICodeEditor::setFontColor( const Color& color ) {
|
||||
return this;
|
||||
}
|
||||
|
||||
const Color& UICodeEditor::getFontColor() const {
|
||||
return mFontStyleConfig.getFontColor();
|
||||
}
|
||||
|
||||
const Color& UICodeEditor::getFontSelectedColor() {
|
||||
return mFontStyleConfig.getFontSelectedColor();
|
||||
}
|
||||
|
||||
UICodeEditor* UICodeEditor::setFontSelectedColor( const Color& color ) {
|
||||
if ( mFontStyleConfig.getFontSelectedColor() != color ) {
|
||||
mFontStyleConfig.FontSelectedColor = color;
|
||||
@@ -229,6 +248,10 @@ UICodeEditor* UICodeEditor::setFontSelectionBackColor( const Color& color ) {
|
||||
return this;
|
||||
}
|
||||
|
||||
const Color& UICodeEditor::getFontSelectionBackColor() const {
|
||||
return mFontStyleConfig.getFontSelectionBackColor();
|
||||
}
|
||||
|
||||
const Uint32& UICodeEditor::getTabWidth() const {
|
||||
return mTabWidth;
|
||||
}
|
||||
@@ -281,8 +304,8 @@ size_t UICodeEditor::getLineNumberDigits() const {
|
||||
}
|
||||
|
||||
Float UICodeEditor::getLineNumberWidth() const {
|
||||
return getLineNumberDigits() * getGlyphWidth() + getLineNumberPaddingLeft() +
|
||||
getLineNumberPaddingRight();
|
||||
return eeceil( getLineNumberDigits() * getGlyphWidth() + getLineNumberPaddingLeft() +
|
||||
getLineNumberPaddingRight() );
|
||||
}
|
||||
|
||||
const bool& UICodeEditor::getShowLineNumber() const {
|
||||
@@ -447,8 +470,8 @@ Sizef UICodeEditor::getMaxScroll() const {
|
||||
}
|
||||
|
||||
Uint32 UICodeEditor::onMouseDown( const Vector2i& position, const Uint32& flags ) {
|
||||
if ( !getUISceneNode()->getEventDispatcher()->isNodeDragging() && NULL != mFont &&
|
||||
!mMouseDown && ( flags & EE_BUTTON_LMASK ) ) {
|
||||
if ( isTextSelectionEnabled() && !getUISceneNode()->getEventDispatcher()->isNodeDragging() &&
|
||||
NULL != mFont && !mMouseDown && ( flags & EE_BUTTON_LMASK ) ) {
|
||||
mMouseDown = true;
|
||||
Input* input = getUISceneNode()->getWindow()->getInput();
|
||||
input->captureMouse( true );
|
||||
@@ -462,8 +485,8 @@ Uint32 UICodeEditor::onMouseDown( const Vector2i& position, const Uint32& flags
|
||||
}
|
||||
|
||||
Uint32 UICodeEditor::onMouseMove( const Vector2i& position, const Uint32& flags ) {
|
||||
if ( !getUISceneNode()->getEventDispatcher()->isNodeDragging() && NULL != mFont && mMouseDown &&
|
||||
( flags & EE_BUTTON_LMASK ) ) {
|
||||
if ( isTextSelectionEnabled() && !getUISceneNode()->getEventDispatcher()->isNodeDragging() &&
|
||||
NULL != mFont && mMouseDown && ( flags & EE_BUTTON_LMASK ) ) {
|
||||
TextRange selection = mDoc.getSelection();
|
||||
selection.setStart( resolveScreenPosition( position.asFloat() ) );
|
||||
mDoc.setSelection( selection );
|
||||
@@ -476,8 +499,10 @@ Uint32 UICodeEditor::onMouseUp( const Vector2i& position, const Uint32& flags )
|
||||
return UIWidget::onMouseUp( position, flags );
|
||||
|
||||
if ( flags & EE_BUTTON_LMASK ) {
|
||||
mMouseDown = false;
|
||||
getUISceneNode()->getWindow()->getInput()->captureMouse( false );
|
||||
if ( mMouseDown ) {
|
||||
mMouseDown = false;
|
||||
getUISceneNode()->getWindow()->getInput()->captureMouse( false );
|
||||
}
|
||||
} else if ( flags & EE_BUTTON_WDMASK ) {
|
||||
if ( getUISceneNode()->getWindow()->getInput()->isControlPressed() ) {
|
||||
mFontStyleConfig.CharacterSize = eemax<Float>( 4, mFontStyleConfig.CharacterSize - 1 );
|
||||
@@ -536,7 +561,7 @@ void UICodeEditor::onPaddingChange() {
|
||||
}
|
||||
|
||||
void UICodeEditor::updateScrollBar() {
|
||||
mVScrollBar->setPixelsSize( 0, mSize.getHeight() );
|
||||
mVScrollBar->setPixelsSize( mVScrollBar->getPixelsSize().getWidth(), mSize.getHeight() );
|
||||
mVScrollBar->setPixelsPosition( mSize.getWidth() - mVScrollBar->getPixelsSize().getWidth(), 0 );
|
||||
int notVisibleLineCount = (int)mDoc.linesCount() - (int)getViewPortLineCount().y;
|
||||
mVScrollBar->setPageStep( getViewPortLineCount().y / (float)mDoc.linesCount() );
|
||||
@@ -592,17 +617,16 @@ int UICodeEditor::getVisibleLinesCount() {
|
||||
void UICodeEditor::scrollToMakeVisible( const TextPosition& position ) {
|
||||
auto lineRange = getVisibleLineRange();
|
||||
|
||||
if ( position.line() >= lineRange.first && position.line() <= lineRange.second )
|
||||
return;
|
||||
|
||||
// Vertical Scroll
|
||||
Float lineHeight = getLineHeight();
|
||||
Float min = eefloor( lineHeight * ( eemax<Float>( 0, position.line() - 1 ) ) );
|
||||
Float max = eefloor( lineHeight * ( position.line() + 2 ) - mSize.getHeight() );
|
||||
if ( min < mScroll.y )
|
||||
setScrollY( min );
|
||||
else if ( max > mScroll.y )
|
||||
setScrollY( max );
|
||||
if ( position.line() < lineRange.first || position.line() > lineRange.second ) {
|
||||
// Vertical Scroll
|
||||
Float lineHeight = getLineHeight();
|
||||
Float min = eefloor( lineHeight * ( eemax<Float>( 0, position.line() - 1 ) ) );
|
||||
Float max = eefloor( lineHeight * ( position.line() + 2 ) - mSize.getHeight() );
|
||||
if ( min < mScroll.y )
|
||||
setScrollY( min );
|
||||
else if ( max > mScroll.y )
|
||||
setScrollY( max );
|
||||
}
|
||||
|
||||
// Horizontal Scroll
|
||||
Float offsetX = getXOffsetCol( position );
|
||||
@@ -773,6 +797,153 @@ void UICodeEditor::addUnlockedCommand( const std::string& command ) {
|
||||
mUnlockedCmd.insert( command );
|
||||
}
|
||||
|
||||
UICodeEditor* UICodeEditor::setFontShadowColor( const Color& color ) {
|
||||
if ( mFontStyleConfig.ShadowColor != color ) {
|
||||
mFontStyleConfig.ShadowColor = color;
|
||||
invalidateDraw();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
UICodeEditor* UICodeEditor::setFontStyle( const Uint32& fontStyle ) {
|
||||
if ( mFontStyleConfig.Style != fontStyle ) {
|
||||
mFontStyleConfig.Style = fontStyle;
|
||||
invalidateDraw();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
const Color& UICodeEditor::getFontShadowColor() const {
|
||||
return mFontStyleConfig.getFontShadowColor();
|
||||
}
|
||||
|
||||
const Uint32& UICodeEditor::getFontStyle() const {
|
||||
return mFontStyleConfig.getFontStyle();
|
||||
}
|
||||
|
||||
const Float& UICodeEditor::getOutlineThickness() const {
|
||||
return mFontStyleConfig.OutlineThickness;
|
||||
}
|
||||
|
||||
UICodeEditor* UICodeEditor::setOutlineThickness( const Float& outlineThickness ) {
|
||||
if ( mFontStyleConfig.OutlineThickness != outlineThickness ) {
|
||||
mFontStyleConfig.OutlineThickness = outlineThickness;
|
||||
invalidateDraw();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
const Color& UICodeEditor::getOutlineColor() const {
|
||||
return mFontStyleConfig.OutlineColor;
|
||||
}
|
||||
|
||||
UICodeEditor* UICodeEditor::setOutlineColor( const Color& outlineColor ) {
|
||||
if ( mFontStyleConfig.OutlineColor != outlineColor ) {
|
||||
mFontStyleConfig.OutlineColor = outlineColor;
|
||||
invalidateDraw();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
bool UICodeEditor::isTextSelectionEnabled() const {
|
||||
return 0 != ( mFlags & UI_TEXT_SELECTION_ENABLED );
|
||||
}
|
||||
|
||||
void UICodeEditor::setTextSelection( const bool& active ) {
|
||||
if ( active ) {
|
||||
mFlags |= UI_TEXT_SELECTION_ENABLED;
|
||||
} else {
|
||||
mFlags &= ~UI_TEXT_SELECTION_ENABLED;
|
||||
}
|
||||
}
|
||||
|
||||
bool UICodeEditor::applyProperty( const StyleSheetProperty& attribute ) {
|
||||
if ( !checkPropertyDefinition( attribute ) )
|
||||
return false;
|
||||
|
||||
switch ( attribute.getPropertyDefinition()->getPropertyId() ) {
|
||||
case PropertyId::Locked:
|
||||
setLocked( attribute.asBool() );
|
||||
break;
|
||||
case PropertyId::Color:
|
||||
setFontColor( attribute.asColor() );
|
||||
break;
|
||||
case PropertyId::ShadowColor:
|
||||
setFontShadowColor( attribute.asColor() );
|
||||
break;
|
||||
case PropertyId::SelectionColor:
|
||||
setFontSelectedColor( attribute.asColor() );
|
||||
break;
|
||||
case PropertyId::SelectionBackColor:
|
||||
setFontSelectionBackColor( attribute.asColor() );
|
||||
break;
|
||||
case PropertyId::FontFamily: {
|
||||
Font* font = FontManager::instance()->getByName( attribute.asString() );
|
||||
if ( NULL != font && font->loaded() ) {
|
||||
setFont( font );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PropertyId::FontSize:
|
||||
setFontSize( lengthFromValueAsDp( attribute ) );
|
||||
break;
|
||||
case PropertyId::FontStyle: {
|
||||
setFontStyle( attribute.asFontStyle() );
|
||||
break;
|
||||
}
|
||||
case PropertyId::TextStrokeWidth:
|
||||
setOutlineThickness( lengthFromValue( attribute ) );
|
||||
break;
|
||||
case PropertyId::TextStrokeColor:
|
||||
setOutlineColor( attribute.asColor() );
|
||||
break;
|
||||
case PropertyId::TextSelection:
|
||||
setTextSelection( attribute.asBool() );
|
||||
break;
|
||||
default:
|
||||
return UIWidget::applyProperty( attribute );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string UICodeEditor::getPropertyString( const PropertyDefinition* propertyDef,
|
||||
const Uint32& propertyIndex ) {
|
||||
if ( NULL == propertyDef )
|
||||
return "";
|
||||
|
||||
switch ( propertyDef->getPropertyId() ) {
|
||||
case PropertyId::Locked:
|
||||
return isLocked() ? "true" : "false";
|
||||
case PropertyId::Color:
|
||||
return getFontColor().toHexString();
|
||||
case PropertyId::ShadowColor:
|
||||
return getFontShadowColor().toHexString();
|
||||
case PropertyId::SelectionColor:
|
||||
return getFontSelectedColor().toHexString();
|
||||
case PropertyId::SelectionBackColor:
|
||||
return getFontSelectionBackColor().toHexString();
|
||||
case PropertyId::FontFamily:
|
||||
return NULL != getFont() ? getFont()->getName() : "";
|
||||
case PropertyId::FontSize:
|
||||
return String::format( "%.2fdp", getFontSize() );
|
||||
case PropertyId::FontStyle:
|
||||
return Text::styleFlagToString( getFontStyle() );
|
||||
case PropertyId::TextStrokeWidth:
|
||||
return String::toStr( PixelDensity::dpToPx( getOutlineThickness() ) );
|
||||
case PropertyId::TextStrokeColor:
|
||||
return getOutlineColor().toHexString();
|
||||
case PropertyId::TextSelection:
|
||||
return isTextSelectionEnabled() ? "true" : "false";
|
||||
default:
|
||||
return UIWidget::getPropertyString( propertyDef, propertyIndex );
|
||||
}
|
||||
}
|
||||
|
||||
Int64 UICodeEditor::getColFromXOffset( Int64 lineNumber, const Float& x ) const {
|
||||
if ( x <= 0 )
|
||||
return 0;
|
||||
@@ -902,9 +1073,10 @@ void UICodeEditor::drawLineText( const Int64& index, Vector2f position, const Fl
|
||||
if ( position.x + textWidth >= mScreenPos.x &&
|
||||
position.x <= mScreenPos.x + mSize.getWidth() ) {
|
||||
Text line( "", mFont, fontSize );
|
||||
Color color( mColorScheme.getSyntaxColor( token.type ), mAlpha );
|
||||
line.setStyleConfig( mFontStyleConfig );
|
||||
line.setString( token.text );
|
||||
line.setColor( mColorScheme.getSyntaxColor( token.type ) );
|
||||
line.setColor( color );
|
||||
line.draw( position.x, position.y );
|
||||
} else if ( position.x > mScreenPos.x + mSize.getWidth() ) {
|
||||
break;
|
||||
@@ -917,7 +1089,8 @@ void UICodeEditor::drawSelection( const std::pair<int, int>& lineRange, const Ve
|
||||
const Float& lineHeight ) {
|
||||
Primitives primitives;
|
||||
primitives.setForceDraw( false );
|
||||
primitives.setColor( mFontStyleConfig.getFontSelectionBackColor() );
|
||||
primitives.setColor(
|
||||
Color( mFontStyleConfig.getFontSelectionBackColor() ).blendAlpha( mAlpha ) );
|
||||
|
||||
TextRange selection = mDoc.getSelection( true );
|
||||
|
||||
@@ -956,7 +1129,7 @@ void UICodeEditor::drawLineNumbers( const std::pair<int, int>& lineRange,
|
||||
const Float& lineHeight, const Float& lineNumberWidth,
|
||||
const int& lineNumberDigits, const Float& fontSize ) {
|
||||
Primitives primitives;
|
||||
primitives.setColor( mLineNumberBackgroundColor );
|
||||
primitives.setColor( Color( mLineNumberBackgroundColor ).blendAlpha( mAlpha ) );
|
||||
primitives.drawRectangle( Rectf( screenStart, Sizef( lineNumberWidth, mSize.getHeight() ) ) );
|
||||
TextRange selection = mDoc.getSelection( true );
|
||||
for ( int i = lineRange.first; i <= lineRange.second; i++ ) {
|
||||
@@ -974,7 +1147,7 @@ void UICodeEditor::drawIndentationGuide( const std::pair<int, int>& lineRange,
|
||||
const Vector2f& startScroll, const Float& lineHeight ) {
|
||||
Primitives primitives;
|
||||
primitives.setForceDraw( false );
|
||||
primitives.setColor( mIndentationGuideColor );
|
||||
primitives.setColor( Color( mIndentationGuideColor ).blendAlpha( mAlpha ) );
|
||||
primitives.setLineWidth( 1 );
|
||||
for ( int i = lineRange.first; i <= lineRange.second; i++ ) {
|
||||
Float charWidth = getGlyphWidth();
|
||||
|
||||
@@ -18,14 +18,13 @@ UIComboBox::UIComboBox() : UIWidget( "combobox" ), mDropDownList( NULL ), mButto
|
||||
mDropDownList->setTextSelection( true );
|
||||
mDropDownList->addEventListener( Event::OnPaddingChange,
|
||||
[this]( const Event* ) { onPaddingChange(); } );
|
||||
mDropDownList->addEventListener( Event::OnSizeChange,
|
||||
[&]( const Event* event ) { onSizeChange(); } );
|
||||
mDropDownList->addEventListener( Event::OnSizeChange, [&]( const Event* ) { onSizeChange(); } );
|
||||
|
||||
mButton = UIWidget::NewWithTag( "combobox::button" );
|
||||
mButton->setParent( this );
|
||||
mButton->setVisible( true );
|
||||
mButton->setEnabled( true );
|
||||
mButton->addEventListener( Event::OnSizeChange, [&]( const Event* event ) { onSizeChange(); } );
|
||||
mButton->addEventListener( Event::OnSizeChange, [&]( const Event* ) { onSizeChange(); } );
|
||||
|
||||
applyDefaultTheme();
|
||||
}
|
||||
|
||||
@@ -21,9 +21,7 @@ UISpinBox::UISpinBox() :
|
||||
mInput->setEnabled( true );
|
||||
mInput->setParent( this );
|
||||
|
||||
auto cb = [&]( const Event* event ) {
|
||||
adjustChilds();
|
||||
};
|
||||
auto cb = [&]( const Event* ) { adjustChilds(); };
|
||||
|
||||
mPushUp = UIWidget::NewWithTag( "spinbox::btnup" );
|
||||
mPushUp->setVisible( true );
|
||||
@@ -223,7 +221,7 @@ const Float& UISpinBox::getMaxValue() const {
|
||||
return mMaxValue;
|
||||
}
|
||||
|
||||
void UISpinBox::onBufferChange( const Event* event ) {
|
||||
void UISpinBox::onBufferChange( const Event* ) {
|
||||
if ( !mInput->getText().size() ) {
|
||||
setValue( 0 );
|
||||
} else {
|
||||
|
||||
@@ -248,21 +248,21 @@ void EETest::loadFonts() {
|
||||
mFTE.restart();
|
||||
|
||||
FontTrueType::New( "NotoSans-Regular", MyPath + "fonts/NotoSans-Regular.ttf" );
|
||||
FontTrueType::New( "DejaVuSansMono", MyPath + "fonts/DejaVuSansMono.ttf" );
|
||||
FontTrueType::New( "monospace", MyPath + "fonts/DejaVuSansMono.ttf" );
|
||||
|
||||
onFontLoaded();
|
||||
}
|
||||
|
||||
void EETest::onFontLoaded() {
|
||||
TTF = FontManager::instance()->getByName( "NotoSans-Regular" );
|
||||
Font* DBSM = FontManager::instance()->getByName( "DejaVuSansMono" );
|
||||
Font* monospace = FontManager::instance()->getByName( "monospace" );
|
||||
|
||||
eePRINTL( "Fonts loading time: %4.3f ms.", mFTE.getElapsed().asMilliseconds() );
|
||||
|
||||
eeASSERT( TTF != NULL );
|
||||
eeASSERT( DBSM != NULL );
|
||||
eeASSERT( monospace != NULL );
|
||||
|
||||
Con.create( DBSM, true );
|
||||
Con.create( monospace, true );
|
||||
Con.ignoreCharOnPrompt( 186 ); // 'º'
|
||||
|
||||
mBuda = String::fromUtf8(
|
||||
@@ -282,7 +282,7 @@ void EETest::onFontLoaded() {
|
||||
mFBOText.setOutlineThickness( 1 );
|
||||
mFBOText.setOutlineColor( Color( 0, 0, 0, 255 ) );
|
||||
|
||||
mInfoText.create( DBSM, "", Color( 100, 100, 100, 255 ) );
|
||||
mInfoText.create( monospace, "", Color( 100, 100, 100, 255 ) );
|
||||
mInfoText.setOutlineThickness( 1 );
|
||||
}
|
||||
|
||||
@@ -1160,8 +1160,12 @@ void EETest::createDecoratedWindow() {
|
||||
UI_TEXT_SELECTION_ENABLED );
|
||||
txtBox->setParent( TabWidget );
|
||||
txtBox->setText( mBuda );
|
||||
|
||||
TabWidget->add( "TextBox", txtBox );
|
||||
|
||||
UICodeEditor* codeEditor = UICodeEditor::New();
|
||||
codeEditor->setParent( TabWidget );
|
||||
codeEditor->getDocument().textInput( mBuda );
|
||||
TabWidget->add( "CodeEditor", codeEditor );
|
||||
}
|
||||
|
||||
void EETest::onCloseClick( const Event* ) {
|
||||
|
||||
@@ -999,7 +999,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) {
|
||||
FontTrueType* font =
|
||||
FontTrueType::New( "NotoSans-Regular", resPath + "assets/fonts/NotoSans-Regular.ttf" );
|
||||
FontTrueType* fontMono =
|
||||
FontTrueType::New( "DejaVuSansMono", resPath + "assets/fonts/DejaVuSansMono.ttf" );
|
||||
FontTrueType::New( "monospace", resPath + "assets/fonts/DejaVuSansMono.ttf" );
|
||||
|
||||
console = eeNew( Console, ( fontMono, true, true, 1024 * 1000, 0, window ) );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user