Navigation Menu

Skip to content

Commit

Permalink
UI|Widgets|libappfw: Change LineEditWidget colors and hint font
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 1, 2017
1 parent 8b8811f commit 3c8f6b9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
3 changes: 2 additions & 1 deletion doomsday/sdk/libappfw/include/de/widgets/lineeditwidget.h
Expand Up @@ -47,7 +47,7 @@ class LIBAPPFW_PUBLIC LineEditWidget : public GuiWidget, public shell::AbstractL
*
* @param hintText Hint text.
*/
void setEmptyContentHint(String const &hintText);
void setEmptyContentHint(String const &hintText, String const &hintFont = String());

/**
* Enables or disables the signal emitted when the edit widget receives an
Expand All @@ -64,6 +64,7 @@ class LIBAPPFW_PUBLIC LineEditWidget : public GuiWidget, public shell::AbstractL
*/
Rectanglei cursorRect() const;

void setColorTheme(ColorTheme theme);
void setUnfocusedBackgroundOpacity(float opacity);

// Events.
Expand Down
34 changes: 23 additions & 11 deletions doomsday/sdk/libappfw/src/widgets/lineeditwidget.cpp
Expand Up @@ -47,6 +47,8 @@ DENG_GUI_PIMPL(LineEditWidget)
bool firstUpdateAfterCreation;

// Style.
ColorTheme colorTheme = Normal;
Vector4f textColor;
Font const *font;
Time blinkTime;
Animation hovering;
Expand All @@ -73,12 +75,9 @@ DENG_GUI_PIMPL(LineEditWidget)
{
height = new AnimationRule(0);

self().set(Background(Vector4f(1, 1, 1, 1), Background::GradientFrame));
self().setFont("editor.plaintext");
updateStyle();

uCursorColor = Vector4f(1, 1, 1, 1);

self().set(Background(Vector4f(1, 1, 1, 1), Background::GradientFrame));
}

~Impl()
Expand All @@ -92,6 +91,8 @@ DENG_GUI_PIMPL(LineEditWidget)
void updateStyle()
{
font = &self().font();
textColor = style().colors().colorf(colorTheme == Normal? "text" : "inverted.text");
uCursorColor = style().colors().colorf(colorTheme == Normal? "text" : "inverted.text");

updateBackground();

Expand Down Expand Up @@ -120,19 +121,23 @@ DENG_GUI_PIMPL(LineEditWidget)
if (self().background().type == Background::GradientFrame)
{
Background bg;
Vector3f const frameColor = style().colors().colorf(colorTheme == Normal? "text" : "inverted.text");
if (!self().hasFocus())
{
bg = Background(Background::GradientFrame, Vector4f(1, 1, 1, .15f + hovering * .2f), 6);
bg = Background(Background::GradientFrame, Vector4f(frameColor, .15f + hovering * .2f), 6);
if (unfocusedBackgroundOpacity > 0.f)
{
bg.solidFill = Vector4f(style().colors().colorf("background").xyz(),
bg.solidFill = Vector4f(style().colors().colorf(colorTheme == Normal? "background"
: "inverted.background").xyz(),
unfocusedBackgroundOpacity);
}
}
else
{
bg = Background(style().colors().colorf("background"), Background::GradientFrame,
Vector4f(1, 1, 1, .25f + hovering * .3f), 6);
bg = Background(style().colors().colorf(colorTheme == Normal? "background"
: "inverted.background"),
Background::GradientFrame,
Vector4f(frameColor, .25f + hovering * .3f), 6);
}
self().set(bg);
}
Expand Down Expand Up @@ -259,20 +264,21 @@ void LineEditWidget::setText(String const &lineText)
}
}

void LineEditWidget::setEmptyContentHint(String const &hintText)
void LineEditWidget::setEmptyContentHint(String const &hintText,
String const &hintFont)
{
if (!d->hint)
{
// A child widget will show the hint text.
d->hint = new LabelWidget;
d->hint->setFont("editor.hint");
d->hint->setTextColor("editor.hint");
d->hint->setAlignment(ui::AlignLeft);
d->hint->setBehavior(Unhittable | ContentClipping);
d->hint->rule().setRect(rule());
d->hint->setOpacity(1);
add(d->hint);
}
d->hint->setFont(hintFont.isEmpty()? String("editor.hint.default") : hintFont);
d->hint->setText(hintText);
}

Expand All @@ -291,6 +297,12 @@ Rectanglei LineEditWidget::cursorRect() const
cp + Vector2i(toDevicePixels(1), d->font->height().valuei()));
}

void LineEditWidget::setColorTheme(ColorTheme theme)
{
d->colorTheme = theme;
d->updateStyle();
}

void LineEditWidget::setUnfocusedBackgroundOpacity(float opacity)
{
d->unfocusedBackgroundOpacity = opacity;
Expand Down Expand Up @@ -320,7 +332,7 @@ void LineEditWidget::glMakeGeometry(DefaultVertexBuf::Builder &verts)
Rectanglef const solidWhiteUv = d->atlas().imageRectf(root().solidWhitePixel());

// Text lines.
d->composer.makeVertices(verts, contentRect, AlignLeft, AlignLeft, textColorf());
d->composer.makeVertices(verts, contentRect, AlignLeft, AlignLeft, d->textColor);

// Underline the possible suggested completion.
if (isSuggestingCompletion())
Expand Down

0 comments on commit 3c8f6b9

Please sign in to comment.