Improve spacing of multiline labels, multiline cursor for Textbox, autoresizing textbox for PreviewView comments
This commit is contained in:
parent
2479b8664d
commit
d91d4223b8
@ -79,7 +79,7 @@ void Component::TextPosition(std::string displayText)
|
|||||||
switch(Appearance.VerticalAlign)
|
switch(Appearance.VerticalAlign)
|
||||||
{
|
{
|
||||||
case ui::Appearance::AlignTop:
|
case ui::Appearance::AlignTop:
|
||||||
textPosition.Y = Appearance.Margin.Top;
|
textPosition.Y = Appearance.Margin.Top+2;
|
||||||
break;
|
break;
|
||||||
case ui::Appearance::AlignMiddle:
|
case ui::Appearance::AlignMiddle:
|
||||||
textPosition.Y = Appearance.Margin.Top+((textAreaHeight-textHeight)/2);
|
textPosition.Y = Appearance.Margin.Top+((textAreaHeight-textHeight)/2);
|
||||||
|
@ -42,11 +42,11 @@ void Textbox::SetText(std::string newText)
|
|||||||
|
|
||||||
if(cursor)
|
if(cursor)
|
||||||
{
|
{
|
||||||
cursorPosition = Graphics::textnwidth((char *)text.c_str(), cursor);
|
Graphics::PositionAtCharIndex(multiline?((char*)textLines.c_str()):((char*)text.c_str()), cursor, cursorPositionX, cursorPositionY);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cursorPosition = 0;
|
cursorPositionY = cursorPositionX = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,25 +175,25 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
|||||||
|
|
||||||
if(cursor)
|
if(cursor)
|
||||||
{
|
{
|
||||||
cursorPosition = Graphics::textnwidth((char *)text.c_str(), cursor);
|
Graphics::PositionAtCharIndex(multiline?((char*)textLines.c_str()):((char*)text.c_str()), cursor, cursorPositionX, cursorPositionY);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cursorPosition = 0;
|
cursorPositionY = cursorPositionX = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Textbox::OnMouseClick(int x, int y, unsigned button)
|
void Textbox::OnMouseClick(int x, int y, unsigned button)
|
||||||
{
|
{
|
||||||
mouseDown = true;
|
mouseDown = true;
|
||||||
cursor = Graphics::CharIndexAtPosition((char*)text.c_str(), x-textPosition.X, y-textPosition.Y);
|
cursor = Graphics::CharIndexAtPosition(multiline?((char*)textLines.c_str()):((char*)text.c_str()), x-textPosition.X, y-textPosition.Y);
|
||||||
if(cursor)
|
if(cursor)
|
||||||
{
|
{
|
||||||
cursorPosition = Graphics::textnwidth((char *)text.c_str(), cursor);
|
Graphics::PositionAtCharIndex(multiline?((char*)textLines.c_str()):((char*)text.c_str()), cursor, cursorPositionX, cursorPositionY);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cursorPosition = 0;
|
cursorPositionY = cursorPositionX = 0;
|
||||||
}
|
}
|
||||||
Label::OnMouseClick(x, y, button);
|
Label::OnMouseClick(x, y, button);
|
||||||
}
|
}
|
||||||
@ -208,14 +208,14 @@ void Textbox::OnMouseMoved(int localx, int localy, int dx, int dy)
|
|||||||
{
|
{
|
||||||
if(mouseDown)
|
if(mouseDown)
|
||||||
{
|
{
|
||||||
cursor = Graphics::CharIndexAtPosition((char*)text.c_str(), localx-textPosition.X, localy-textPosition.Y);
|
cursor = Graphics::CharIndexAtPosition(multiline?((char*)textLines.c_str()):((char*)text.c_str()), localx-textPosition.X, localy-textPosition.Y);
|
||||||
if(cursor)
|
if(cursor)
|
||||||
{
|
{
|
||||||
cursorPosition = Graphics::textnwidth((char *)text.c_str(), cursor);
|
Graphics::PositionAtCharIndex(multiline?((char*)textLines.c_str()):((char*)text.c_str()), cursor, cursorPositionX, cursorPositionY);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cursorPosition = 0;
|
cursorPositionY = cursorPositionX = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Label::OnMouseMoved(localx, localy, dx, dy);
|
Label::OnMouseMoved(localx, localy, dx, dy);
|
||||||
@ -229,7 +229,7 @@ void Textbox::Draw(const Point& screenPos)
|
|||||||
if(IsFocused())
|
if(IsFocused())
|
||||||
{
|
{
|
||||||
if(border) g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
if(border) g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
||||||
g->draw_line(screenPos.X+textPosition.X+cursorPosition, screenPos.Y+3, screenPos.X+textPosition.X+cursorPosition, screenPos.Y+12, 255, 255, 255, XRES+BARSIZE);
|
g->draw_line(screenPos.X+textPosition.X+cursorPositionX+1, screenPos.Y-2+textPosition.Y+cursorPositionY, screenPos.X+textPosition.X+cursorPositionX+1, screenPos.Y+10+textPosition.Y+cursorPositionY, 255, 255, 255, XRES+BARSIZE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@ class Textbox : public Label
|
|||||||
protected:
|
protected:
|
||||||
bool mouseDown;
|
bool mouseDown;
|
||||||
bool masked, border;
|
bool masked, border;
|
||||||
int cursor, cursorPosition;
|
int cursor, cursorPositionX, cursorPositionY;
|
||||||
TextboxAction *actionCallback;
|
TextboxAction *actionCallback;
|
||||||
std::string backingText;
|
std::string backingText;
|
||||||
std::string placeHolder;
|
std::string placeHolder;
|
||||||
|
@ -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():
|
PreviewView::PreviewView():
|
||||||
ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)),
|
ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)),
|
||||||
savePreview(NULL),
|
savePreview(NULL),
|
||||||
@ -139,6 +149,30 @@ PreviewView::PreviewView():
|
|||||||
AddComponent(pageInfo);
|
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()
|
void PreviewView::DoDraw()
|
||||||
{
|
{
|
||||||
Window::DoDraw();
|
Window::DoDraw();
|
||||||
@ -305,10 +339,10 @@ void PreviewView::displayComments(int yOffset)
|
|||||||
tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||||
currentY += 16;
|
currentY += 16;
|
||||||
|
|
||||||
if(currentY > Size.Y-commentBoxHeight || usernameY < 0)
|
if(currentY+5 > Size.Y-commentBoxHeight || usernameY < 0)
|
||||||
{
|
{
|
||||||
delete tempUsername;
|
delete tempUsername;
|
||||||
if(currentY > Size.Y)
|
if(currentY+5 > Size.Y-commentBoxHeight)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -324,10 +358,10 @@ void PreviewView::displayComments(int yOffset)
|
|||||||
tempComment->SetTextColour(ui::Colour(180, 180, 180));
|
tempComment->SetTextColour(ui::Colour(180, 180, 180));
|
||||||
currentY += tempComment->Size.Y+4;
|
currentY += tempComment->Size.Y+4;
|
||||||
|
|
||||||
if(currentY > Size.Y-commentBoxHeight || commentY < 0)
|
if(currentY+5 > Size.Y-commentBoxHeight || commentY < 0)
|
||||||
{
|
{
|
||||||
delete tempComment;
|
delete tempComment;
|
||||||
if(currentY > Size.Y)
|
if(currentY+5 > Size.Y-commentBoxHeight)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -356,6 +390,7 @@ void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender)
|
|||||||
if(sender->GetCommentBoxEnabled())
|
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 = 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;
|
addCommentBox->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
AddComponent(addCommentBox);
|
AddComponent(addCommentBox);
|
||||||
submitCommentButton = new ui::Button(ui::Point(Size.X-40, Size.Y-19), ui::Point(40, 19), "Submit");
|
submitCommentButton = new ui::Button(ui::Point(Size.X-40, Size.Y-19), ui::Point(40, 19), "Submit");
|
||||||
|
@ -22,6 +22,7 @@ class PreviewModel;
|
|||||||
class PreviewController;
|
class PreviewController;
|
||||||
class PreviewView: public ui::Window {
|
class PreviewView: public ui::Window {
|
||||||
class LoginAction;
|
class LoginAction;
|
||||||
|
class AutoCommentSizeAction;
|
||||||
PreviewController * c;
|
PreviewController * c;
|
||||||
Thumbnail * savePreview;
|
Thumbnail * savePreview;
|
||||||
ui::Button * openButton;
|
ui::Button * openButton;
|
||||||
@ -50,6 +51,7 @@ class PreviewView: public ui::Window {
|
|||||||
int commentBoxHeight;
|
int commentBoxHeight;
|
||||||
|
|
||||||
void displayComments(int yOffset);
|
void displayComments(int yOffset);
|
||||||
|
void commentBoxAutoHeight();
|
||||||
public:
|
public:
|
||||||
void AttachController(PreviewController * controller) { c = controller;}
|
void AttachController(PreviewController * controller) { c = controller;}
|
||||||
PreviewView();
|
PreviewView();
|
||||||
|
Reference in New Issue
Block a user