/* Copyright (c) 2018 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __UILabel_H__ #define __UILabel_H__ #ifdef __cplusplus extern "C" { #endif typedef struct UILabel UILabel; #define UILabel_superclass UIElement #include "uitoolkit/UIElement.h" #include "uitoolkit/UITextLayout.h" #define UILabel_ivars \ UIElement_ivars \ \ UITextLayout * textLayout; \ Vector2f size; \ Vector2f lastSize; \ UIOverflowMode overflowModeX; \ UIOverflowMode overflowModeY; #define UILabel_vtable(self_type) \ UIElement_vtable(self_type) \ \ void (* setText)(self_type * self, String text); stemobject_declare(UILabel) // Initialization properties should generally be treated as immutable for this UILabel's lifetime. If text needs to be updated, use UILabel_setText(). // If wrapMode is not WORD_WRAP_NONE, size.x will determine the wrap width, so set it to a sensible value even if you're using OVERFLOW_RESIZE for overflowModeX. // Note that alignMode works separately from relativeOrigin. relativeOrigin determines where the overall rectangle of the text field extends from position. // alignMode determines how the text itself is aligned within this rectangle. For single-line text with OVERFLOW_TRUNCATE for overflowModeX, all align modes are equal. UILabel * UILabel_create(String text, Vector2f position, Vector2f size, Vector2f relativeOrigin, TextAlignMode alignMode, WordWrapBehavior wrapBehavior, UIOverflowMode overflowModeX, UIOverflowMode overflowModeY, UIAppearance appearance); bool UILabel_init(UILabel * self, String text, Vector2f position, Vector2f size, Vector2f relativeOrigin, TextAlignMode alignMode, WordWrapBehavior wrapBehavior, UIOverflowMode overflowModeX, UIOverflowMode overflowModeY, UIAppearance appearance); void UILabel_dispose(UILabel * self); // Creates an auto-resizing, non-word-wrapping label, with its alignment based on relativeOrigin (x 0.0 = left, x 0.5 = center, x 1.0 = right) UILabel * UILabel_createSimple(String text, Vector2f position, Vector2f relativeOrigin, UIAppearance appearance); bool UILabel_initSimple(UILabel * self, String text, Vector2f position, Vector2f relativeOrigin, UIAppearance appearance); void UILabel_setText(UILabel * self, String text); String UILabel_getText(UILabel * self); Rect4f UILabel_getBounds(UILabel * self); void UILabel_draw(UILabel * self, Vector2f offset, UIDrawingInterface * drawingInterface, VertexIO * vertexIO); #ifdef __cplusplus } #endif #endif