summaryrefslogtreecommitdiff
path: root/src/preview/PreviewView.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-07-17 21:21:20 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-07-17 21:21:20 (GMT)
commitd91d4223b8ada310dd9df5f9950c66f534b2f008 (patch)
tree44d9a4d1d724553085535a516231cc6ea9987c02 /src/preview/PreviewView.cpp
parent2479b8664d5c4cdd47208bdbca970828ba1a2520 (diff)
downloadpowder-d91d4223b8ada310dd9df5f9950c66f534b2f008.zip
powder-d91d4223b8ada310dd9df5f9950c66f534b2f008.tar.gz
Improve spacing of multiline labels, multiline cursor for Textbox, autoresizing textbox for PreviewView comments
Diffstat (limited to 'src/preview/PreviewView.cpp')
-rw-r--r--src/preview/PreviewView.cpp43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp
index 0eb29b6..417e258 100644
--- a/src/preview/PreviewView.cpp
+++ b/src/preview/PreviewView.cpp
@@ -28,6 +28,16 @@ public:
}
};
+class PreviewView::AutoCommentSizeAction: public ui::TextboxAction
+{
+ PreviewView * v;
+public:
+ AutoCommentSizeAction(PreviewView * v): v(v) {}
+ virtual void TextChangedCallback(ui::Textbox * sender) {
+ v->commentBoxAutoHeight();
+ }
+};
+
PreviewView::PreviewView():
ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)),
savePreview(NULL),
@@ -139,6 +149,30 @@ PreviewView::PreviewView():
AddComponent(pageInfo);
}
+void PreviewView::commentBoxAutoHeight()
+{
+ if(!addCommentBox)
+ return;
+ int textWidth = Graphics::textwidth(addCommentBox->GetText().c_str());
+ if(textWidth+5 > Size.X-(XRES/2)-48)
+ {
+ commentBoxHeight = 58;
+ addCommentBox->SetMultiline(true);
+ addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignTop;
+ addCommentBox->Position = ui::Point((XRES/2)+4, Size.Y-58);
+ addCommentBox->Size = ui::Point(Size.X-(XRES/2)-8, 37);
+ }
+ else
+ {
+ commentBoxHeight = 20;
+ addCommentBox->SetMultiline(false);
+ addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
+ addCommentBox->Position = ui::Point((XRES/2)+4, Size.Y-19);
+ addCommentBox->Size = ui::Point(Size.X-(XRES/2)-48, 17);
+ }
+ displayComments(commentsOffset);
+}
+
void PreviewView::DoDraw()
{
Window::DoDraw();
@@ -305,10 +339,10 @@ void PreviewView::displayComments(int yOffset)
tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
currentY += 16;
- if(currentY > Size.Y-commentBoxHeight || usernameY < 0)
+ if(currentY+5 > Size.Y-commentBoxHeight || usernameY < 0)
{
delete tempUsername;
- if(currentY > Size.Y)
+ if(currentY+5 > Size.Y-commentBoxHeight)
break;
}
else
@@ -324,10 +358,10 @@ void PreviewView::displayComments(int yOffset)
tempComment->SetTextColour(ui::Colour(180, 180, 180));
currentY += tempComment->Size.Y+4;
- if(currentY > Size.Y-commentBoxHeight || commentY < 0)
+ if(currentY+5 > Size.Y-commentBoxHeight || commentY < 0)
{
delete tempComment;
- if(currentY > Size.Y)
+ if(currentY+5 > Size.Y-commentBoxHeight)
break;
}
else
@@ -356,6 +390,7 @@ void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender)
if(sender->GetCommentBoxEnabled())
{
addCommentBox = new ui::Textbox(ui::Point((XRES/2)+4, Size.Y-19), ui::Point(Size.X-(XRES/2)-48, 17), "", "Add Comment");
+ addCommentBox->SetActionCallback(new AutoCommentSizeAction(this));
addCommentBox->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
AddComponent(addCommentBox);
submitCommentButton = new ui::Button(ui::Point(Size.X-40, Size.Y-19), ui::Point(40, 19), "Submit");