mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
LibGfx+LibGUI: Allow setting tab text alignment with set_property()
This commit is contained in:
parent
856f683dc9
commit
e78cf6c590
2 changed files with 28 additions and 0 deletions
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
|
@ -407,6 +408,13 @@ bool TabWidget::set_property(const StringView& name, const JsonValue& value)
|
|||
return true;
|
||||
}
|
||||
|
||||
if (name == "text_alignment") {
|
||||
auto alignment = Gfx::text_alignment_from_string(value.to_string());
|
||||
if (alignment.has_value())
|
||||
set_text_alignment(alignment.value());
|
||||
return true;
|
||||
}
|
||||
|
||||
return Widget::set_property(name, value);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/StringView.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
enum class TextAlignment {
|
||||
|
@ -49,4 +52,21 @@ inline bool is_right_text_alignment(TextAlignment alignment)
|
|||
}
|
||||
}
|
||||
|
||||
inline Optional<TextAlignment> text_alignment_from_string(const StringView& string)
|
||||
{
|
||||
if (string == "TopLeft")
|
||||
return TextAlignment::TopLeft;
|
||||
if (string == "CenterLeft")
|
||||
return TextAlignment::CenterLeft;
|
||||
if (string == "Center")
|
||||
return TextAlignment::Center;
|
||||
if (string == "CenterRight")
|
||||
return TextAlignment::CenterRight;
|
||||
if (string == "TopRight")
|
||||
return TextAlignment::TopRight;
|
||||
if (string == "BottomRight")
|
||||
return TextAlignment::BottomRight;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue