mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-13 20:04:01 +02:00
Text alignment for dropdown, make sign UI nice
This commit is contained in:
@@ -48,7 +48,7 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi
|
|||||||
sim(sim_),
|
sim(sim_),
|
||||||
signPosition(position_)
|
signPosition(position_)
|
||||||
{
|
{
|
||||||
ui::Label * messageLabel = new ui::Label(ui::Point(4, 18), ui::Point(Size.X-8, 60), "New sign");
|
ui::Label * messageLabel = new ui::Label(ui::Point(4, 2), ui::Point(Size.X-8, 14), "New sign");
|
||||||
messageLabel->SetAlignment(AlignLeft, AlignTop);
|
messageLabel->SetAlignment(AlignLeft, AlignTop);
|
||||||
AddComponent(messageLabel);
|
AddComponent(messageLabel);
|
||||||
|
|
||||||
@@ -58,14 +58,14 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi
|
|||||||
okayButton->SetActionCallback(new OkayAction(this));
|
okayButton->SetActionCallback(new OkayAction(this));
|
||||||
AddComponent(okayButton);
|
AddComponent(okayButton);
|
||||||
|
|
||||||
justification = new ui::DropDown(ui::Point(4, 18), ui::Point(50, 16));
|
justification = new ui::DropDown(ui::Point(8, 38), ui::Point(50, 16));
|
||||||
AddComponent(justification);
|
AddComponent(justification);
|
||||||
justification->AddOption(std::pair<std::string, int>("Left", (int)sign::Left));
|
justification->AddOption(std::pair<std::string, int>("Left", (int)sign::Left));
|
||||||
justification->AddOption(std::pair<std::string, int>("Centre", (int)sign::Centre));
|
justification->AddOption(std::pair<std::string, int>("Centre", (int)sign::Centre));
|
||||||
justification->AddOption(std::pair<std::string, int>("Right", (int)sign::Right));
|
justification->AddOption(std::pair<std::string, int>("Right", (int)sign::Right));
|
||||||
justification->SetOption(0);
|
justification->SetOption(0);
|
||||||
|
|
||||||
textField = new ui::Textbox(ui::Point(4, 32), ui::Point(Size.X-8, 16), "");
|
textField = new ui::Textbox(ui::Point(8, 17), ui::Point(Size.X-16, 16), "");
|
||||||
textField->SetAlignment(AlignLeft, AlignBottom);
|
textField->SetAlignment(AlignLeft, AlignBottom);
|
||||||
AddComponent(textField);
|
AddComponent(textField);
|
||||||
|
|
||||||
|
@@ -80,6 +80,9 @@ DropDown::DropDown(Point position, Point size):
|
|||||||
Component(position, size),
|
Component(position, size),
|
||||||
isMouseInside(false),
|
isMouseInside(false),
|
||||||
optionIndex(-1),
|
optionIndex(-1),
|
||||||
|
textPosition(ui::Point(0, 0)),
|
||||||
|
textVAlign(AlignMiddle),
|
||||||
|
textHAlign(AlignLeft),
|
||||||
callback(NULL)
|
callback(NULL)
|
||||||
{
|
{
|
||||||
background = activeBackground = Colour(0, 0, 0);
|
background = activeBackground = Colour(0, 0, 0);
|
||||||
@@ -101,20 +104,52 @@ void DropDown::Draw(const Point& screenPos)
|
|||||||
g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, activeBackground.Red, activeBackground.Green, activeBackground.Blue, 255);
|
g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, activeBackground.Red, activeBackground.Green, activeBackground.Blue, 255);
|
||||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, activeBorder.Red, activeBorder.Green, activeBorder.Blue, 255);
|
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, activeBorder.Red, activeBorder.Green, activeBorder.Blue, 255);
|
||||||
if(optionIndex!=-1)
|
if(optionIndex!=-1)
|
||||||
g->drawtext(Position.X, Position.Y+1, options[optionIndex].first, activeText.Red, activeText.Green, activeText.Blue, 255);
|
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, activeText.Red, activeText.Green, activeText.Blue, 255);
|
||||||
//g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, displayText, activeText.Red, activeText.Green, activeText.Blue, 255);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, background.Red, background.Green, background.Blue, 255);
|
g->fillrect(Position.X, Position.Y, Size.X, Size.Y, background.Red, background.Green, background.Blue, 255);
|
||||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, border.Red, border.Green, border.Blue, 255);
|
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, border.Red, border.Green, border.Blue, 255);
|
||||||
if(optionIndex!=-1)
|
if(optionIndex!=-1)
|
||||||
g->drawtext(Position.X, Position.Y+1, options[optionIndex].first, text.Red, text.Green, text.Blue, 255);
|
g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y, options[optionIndex].first, text.Red, text.Green, text.Blue, 255);
|
||||||
//g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, displayText, text.Red, text.Green, text.Blue, 255);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DropDown::TextPosition()
|
||||||
|
{
|
||||||
|
std::string displayText;
|
||||||
|
if(optionIndex!=-1)
|
||||||
|
displayText = options[optionIndex].first;
|
||||||
|
|
||||||
|
// Values 3 and 10 are for vertical padding of 3 pixels, middle uses 7 as that's the height of a capital
|
||||||
|
switch(textVAlign)
|
||||||
|
{
|
||||||
|
case AlignTop:
|
||||||
|
textPosition.Y = 3;
|
||||||
|
break;
|
||||||
|
case AlignMiddle:
|
||||||
|
textPosition.Y = (Size.Y-10)/2;
|
||||||
|
break;
|
||||||
|
case AlignBottom:
|
||||||
|
textPosition.Y = Size.Y-10;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(textHAlign)
|
||||||
|
{
|
||||||
|
case AlignLeft:
|
||||||
|
textPosition.X = 3;
|
||||||
|
break;
|
||||||
|
case AlignCentre:
|
||||||
|
textPosition.X = (Size.X-Graphics::textwidth((char *)displayText.c_str()))/2;
|
||||||
|
break;
|
||||||
|
case AlignRight:
|
||||||
|
textPosition.X = (Size.X-Graphics::textwidth((char *)displayText.c_str()))-2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<std::string, int> DropDown::GetOption()
|
std::pair<std::string, int> DropDown::GetOption()
|
||||||
{
|
{
|
||||||
if(optionIndex!=-1)
|
if(optionIndex!=-1)
|
||||||
@@ -131,6 +166,7 @@ void DropDown::Draw(const Point& screenPos)
|
|||||||
if(options[i].first == option)
|
if(options[i].first == option)
|
||||||
{
|
{
|
||||||
optionIndex = i;
|
optionIndex = i;
|
||||||
|
TextPosition();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,6 +178,7 @@ void DropDown::Draw(const Point& screenPos)
|
|||||||
if(options[i].second == option)
|
if(options[i].second == option)
|
||||||
{
|
{
|
||||||
optionIndex = i;
|
optionIndex = i;
|
||||||
|
TextPosition();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,6 +199,8 @@ void DropDown::Draw(const Point& screenPos)
|
|||||||
{
|
{
|
||||||
if(options[i].first == option)
|
if(options[i].first == option)
|
||||||
{
|
{
|
||||||
|
if(i == optionIndex)
|
||||||
|
optionIndex = -1;
|
||||||
options.erase(options.begin()+i);
|
options.erase(options.begin()+i);
|
||||||
goto start;
|
goto start;
|
||||||
}
|
}
|
||||||
|
@@ -27,13 +27,17 @@ class DropDown: public ui::Component {
|
|||||||
Colour background, activeBackground;
|
Colour background, activeBackground;
|
||||||
Colour border, activeBorder;
|
Colour border, activeBorder;
|
||||||
Colour text, activeText;
|
Colour text, activeText;
|
||||||
|
Point textPosition;
|
||||||
bool isMouseInside;
|
bool isMouseInside;
|
||||||
int optionIndex;
|
int optionIndex;
|
||||||
DropDownAction * callback;
|
DropDownAction * callback;
|
||||||
std::vector<std::pair<std::string, int> > options;
|
std::vector<std::pair<std::string, int> > options;
|
||||||
|
HorizontalAlignment textHAlign;
|
||||||
|
VerticalAlignment textVAlign;
|
||||||
public:
|
public:
|
||||||
DropDown(Point position, Point size);
|
DropDown(Point position, Point size);
|
||||||
std::pair<std::string, int> GetOption();
|
std::pair<std::string, int> GetOption();
|
||||||
|
void TextPosition();
|
||||||
void SetOption(int option);
|
void SetOption(int option);
|
||||||
void SetOption(std::string option);
|
void SetOption(std::string option);
|
||||||
void AddOption(std::pair<std::string, int> option);
|
void AddOption(std::pair<std::string, int> option);
|
||||||
|
Reference in New Issue
Block a user