/* Copyright (c) 2023 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 __UITypes_H__ #define __UITypes_H__ #include "font/String.h" #include "gamemath/Rect4f.h" #include "gamemath/Vector2f.h" #include // Functions that return UIEventResponse are capable to forwarding; functions that return bool instead should return true for handled, false for unhandled typedef enum UIEventResponse { RESPONSE_UNHANDLED, // Event was not handled by this element and had no effect on its state, and should continue to propagate RESPONSE_HANDLED, // Event was fully handled by this element and should stop propagation RESPONSE_HANDLED_FORWARD_NEXT, // Event was handled by this element, changing its state in some way, but should also continue to propagate RESPONSE_IGNORE // Event made no visual or logical state change to this element, but should stop propagation } UIEventResponse; typedef enum UIHitTestType { HIT_TEST_MOUSE_DOWN, HIT_TEST_MOUSE_OVER, HIT_TEST_SCROLL_WHEEL, HIT_TEST_KEY_DOWN } UIHitTestType; typedef enum UIOverflowMode { OVERFLOW_TRUNCATE, // Clip text where it's larger than the element's bounds OVERFLOW_SPILL, // Allow text to spill outside the element's bounds if it's larger, without actually changing this object's bounds OVERFLOW_RESIZE // Change this element's bounds to fit the measured size of the text } UIOverflowMode; typedef enum UINavigationDirection { UI_NONE = 0x00, UI_LEFT = 0x01, UI_RIGHT = 0x02, UI_UP = 0x04, UI_DOWN = 0x08, UI_PREVIOUS = 0x10, UI_NEXT = 0x20 #define UI_DIRECTION_COUNT 6 } UINavigationDirection; typedef uint32_t UIAppearance_key; typedef enum UISidePreference { UISidePreference_left, UISidePreference_right, UISidePreference_bottom, UISidePreference_top } UISidePreference; // Measured in texels typedef struct UISliceGrid3x3 { float leftColumn; float centerColumn; float rightColumn; float bottomRow; float centerRow; float topRow; } UISliceGrid3x3; #define SLICE_GRID_3x3(left_column, center_column, right_column, bottom_row, center_row, top_row) ((UISliceGrid3x3) {left_column, center_column, right_column, bottom_row, center_row, top_row}) typedef struct UISliceGrid3x1 { float leftColumn; float centerColumn; float rightColumn; } UISliceGrid3x1; #define SLICE_GRID_3x1(left_column, center_column, right_column) ((UISliceGrid3x1) {left_column, center_column, right_column}) typedef struct UISliceGrid1x3 { float bottomRow; float centerRow; float topRow; } UISliceGrid1x3; #define SLICE_GRID_1x3(bottom_row, center_row, top_row) ((UISliceGrid1x3) {bottom_row, center_row, top_row}) typedef struct UIAtlasEntry { Rect4f bounds; Rect4f bounds2x; Vector2f size; } UIAtlasEntry; typedef struct UITooltip { String text; UISidePreference sidePreference; struct UIElement * invoker; Rect4f invokerBounds; // Absolute unsigned int identifier; // Unique per invoker; can be nonunique betweeen different invokers } UITooltip; #define UIAtlasEntry_none ((UIAtlasEntry) {RECT4f_EMPTY, RECT4f_EMPTY, VECTOR2f(0.0f, 0.0f)}) #define UITooltip_none ((UITooltip) {STR_NULL, UISidePreference_right, NULL, RECT4f_EMPTY, 0}) static inline Rect4f UIAtlasEntry_boundsForScale(UIAtlasEntry entry, float scale) { if (scale > 1.0f) { return entry.bounds2x; } return entry.bounds; } #endif