Skip to content

Commit

Permalink
Refactor|Client: LogWidget derived from ScrollAreaWidget
Browse files Browse the repository at this point in the history
LogWidget now uses the rules-based ScrollAreaWidget for event handling,
positioning  the scrollable content and drawing the scroll indicator.
  • Loading branch information
skyjake committed Jun 11, 2013
1 parent fadc08b commit 6de6321
Show file tree
Hide file tree
Showing 6 changed files with 402 additions and 253 deletions.
8 changes: 1 addition & 7 deletions doomsday/client/data/defaultstyle.pack/rules.dei
Expand Up @@ -7,14 +7,8 @@ script {
rule unit { constant $= UNIT }
rule gap { constant $= UNIT * 3 }

#group taskbar {
# rule height { constant = 40 }
#}

group console {
rule width { constant = 500 }
}

group log {
rule scrollbar { constant $= UNIT }
}
rule scrollarea.bar { constant $= UNIT }
56 changes: 6 additions & 50 deletions doomsday/client/include/ui/widgets/logwidget.h
@@ -1,4 +1,4 @@
/** @file logwidget.h Widget for output message log.
/** @file logwidget.h Scrollable widget for log message history.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand All @@ -23,14 +23,14 @@
#include <de/LogSink>
#include <de/Animation>

#include "guiwidget.h"
#include "scrollareawidget.h"

/**
* Widget for output message log.
* Scrollable widget for log message history.
*
* @ingroup gui
*/
class LogWidget : public GuiWidget
class LogWidget : public ScrollAreaWidget
{
Q_OBJECT

Expand All @@ -48,63 +48,19 @@ class LogWidget : public GuiWidget
*/
void clear();

/**
* Returns the current scroll position, with 0 being the bottom of the
* history (present time) and maximumScroll() being the top of the history
* (most distant past).
*/
int scrollPosition() const;

int scrollPageSize() const;

/**
* Returns the maximum scroll position. The scrollMaxChanged() signal
* is emitted whenever the maximum changes.
*/
int maximumScroll() const;

/**
* Returns the amount of space between the top edge of the widget and the
* topmost content line.
*/
int topMargin() const;

/**
* Scrolls the view to a specified position. Position 0 means the bottom of
* the log entry buffer, while maximumScroll() is the top of the buffer
* (the oldest entry).
*
* @param to Scroll position.
*/
void scroll(int to);

void setContentYOffset(de::Animation const &anim);

/**
* Enables or disables scrolling with Page Up/Down keys.
*
* @param enabled @c true to enable Page Up/Down.
*/
void enablePageKeys(bool enabled);

// Events.
void viewResized();
void update();
void drawContent();
bool handleEvent(de::Event const &event);

public slots:
/**
* Moves the scroll offset of the widget to the bottom of the history.
*/
void scrollToBottom();

protected slots:
void pruneExcessEntries();

signals:
void scrollPositionChanged(int pos);
void scrollMaxChanged(int maximum);
//void scrollPositionChanged(int pos);
//void scrollMaxChanged(int maximum);
void contentHeightIncreased(int delta);

protected:
Expand Down
45 changes: 41 additions & 4 deletions doomsday/client/include/ui/widgets/scrollareawidget.h
@@ -1,4 +1,4 @@
/** @file scrollareawidget.h
/** @file scrollareawidget.h Scrollable area.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
Expand Down Expand Up @@ -28,27 +28,56 @@ class ScrollAreaWidget : public GuiWidget
{
Q_OBJECT

public:
enum Origin {
Top, ///< Scroll position 0 is at the top.
Bottom ///< Scroll position 0 is at the bottom.
};

public:
ScrollAreaWidget(de::String const &name = "");

void setOrigin(Origin origin);
Origin origin() const;

void setIndicatorUv(de::Rectanglef const &uv);
void setIndicatorUv(de::Vector2f const &uvPoint);

void setContentWidth(int width);
void setContentHeight(int height);
void setContentSize(de::Vector2i const &size);

void modifyContentWidth(int delta);
void modifyContentHeight(int delta);

int contentWidth() const;
int contentHeight() const;

de::RuleRectangle const &contentRule() const;

de::Rule const &scrollPositionX() const;
de::Rule const &scrollPositionY() const;
de::ScalarRule &scrollPositionX() const;
de::ScalarRule &scrollPositionY() const;
de::Rule const &maximumScrollX() const;
de::Rule const &maximumScrollY() const;

de::Rectanglei viewport() const;
de::Vector2i viewportSize() const;

/**
* Returns the amount of space between the top edge of the widget and the
* top edge of the content.
*/
int topMargin() const;

int rightMargin() const;

/**
* Returns the current scroll XY position, with 0 being the top/left corner
* and maximumScroll() being the bottom right position.
*/
de::Vector2i scrollPosition() const;

de::Vector2i scrollPageSize() const;
virtual de::Vector2i scrollPageSize() const;

/**
* Returns the maximum scroll position. The scrollMaxChanged() signal
Expand All @@ -67,14 +96,22 @@ class ScrollAreaWidget : public GuiWidget
void scrollX(int to, de::TimeDelta span = 0);
void scrollY(int to, de::TimeDelta span = 0);

/**
* Determines if the history view is at the bottom, showing the latest entry.
*/
bool isAtBottom() const;

/**
* Enables or disables scrolling with Page Up/Down keys.
*
* @param enabled @c true to enable Page Up/Down.
*/
void enablePageKeys(bool enabled);

void glMakeScrollIndicatorGeometry(DefaultVertexBuf::Builder &verts);

// Events.
void update();
bool handleEvent(de::Event const &event);

public slots:
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/widgets/consolewidget.cpp
Expand Up @@ -79,12 +79,12 @@ DENG2_PIMPL(ConsoleWidget)

void expandLog(int delta, bool useOffsetAnimation)
{
if(height->scalar().target() == 0)
if(height->animation().target() == 0)
{
// On the first expansion make sure the margins are taken into account.
delta += 2 * log->topMargin();
}
height->set(height->scalar().target() + delta, .25f);
height->set(height->animation().target() + delta, .25f);

if(useOffsetAnimation)
{
Expand Down

0 comments on commit 6de6321

Please sign in to comment.