mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 11:01:49 +00:00
minor refactor Button
This commit is contained in:
parent
ead46158d9
commit
f473df33fb
4 changed files with 29 additions and 17 deletions
|
|
@ -34,14 +34,12 @@ Button::Button(
|
|||
const onaction& action,
|
||||
glm::vec2 size
|
||||
)
|
||||
: Panel(gui, size, padding, 0) {
|
||||
if (size.y < 0.0f) {
|
||||
size = glm::vec2(
|
||||
glm::max(padding.x + padding.z + text.length() * 8, size.x),
|
||||
glm::max(padding.y + padding.w + 16, size.y)
|
||||
);
|
||||
: Panel(gui, size, padding, 0.0f) {
|
||||
if (size.x < 0.0f || size.y < 0.0f) {
|
||||
setContentSize({text.length() * 8, 16});
|
||||
} else {
|
||||
setSize(size);
|
||||
}
|
||||
setSize(size);
|
||||
|
||||
if (action) {
|
||||
listenAction(action);
|
||||
|
|
@ -50,13 +48,12 @@ Button::Button(
|
|||
|
||||
label = std::make_shared<Label>(gui, text);
|
||||
label->setAlign(Align::center);
|
||||
label->setSize(
|
||||
size - glm::vec2(padding.z + padding.x, padding.w + padding.y)
|
||||
);
|
||||
label->setInteractive(false);
|
||||
label->setSize(getContentSize());
|
||||
label->setInteractive(true);
|
||||
add(label);
|
||||
setHoverColor(glm::vec4(0.05f, 0.1f, 0.15f, 0.75f));
|
||||
setPressedColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.95f));
|
||||
|
||||
setHoverColor({0.05f, 0.1f, 0.15f, 0.75f});
|
||||
setPressedColor({0.0f, 0.0f, 0.0f, 0.95f});
|
||||
}
|
||||
|
||||
void Button::setText(std::wstring text) {
|
||||
|
|
@ -82,9 +79,7 @@ Button* Button::textSupplier(wstringsupplier supplier) {
|
|||
void Button::refresh() {
|
||||
Panel::refresh();
|
||||
if (label) {
|
||||
label->setSize(
|
||||
size - glm::vec2(padding.z + padding.x, padding.w + padding.y)
|
||||
);
|
||||
label->setSize(getContentSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue