Fix button background drawing
This commit is contained in:
parent
a9e0c8bfcb
commit
0a74af7ef6
@ -39,6 +39,28 @@ typedef double f64;
|
|||||||
typedef u32 Hash32;
|
typedef u32 Hash32;
|
||||||
typedef u64 Hash64;
|
typedef u64 Hash64;
|
||||||
|
|
||||||
|
#define STRUCT_FORWARD_DECL(S) typedef struct S S
|
||||||
|
#define STRUCT(S) STRUCT_FORWARD_DECL(S); struct S
|
||||||
|
#define UNION_FORWARD_DECL(U) typedef union U U
|
||||||
|
#define UNION(U) UNION_FORWARD_DECL(U); union U
|
||||||
|
|
||||||
|
STRUCT(UVec2)
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
u32 x;
|
||||||
|
u32 y;
|
||||||
|
};
|
||||||
|
u32 v[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
STRUCT(Vec4)
|
||||||
|
{
|
||||||
|
f32 v[4];
|
||||||
|
}__attribute__((aligned(16)));
|
||||||
|
typedef Vec4 Color;
|
||||||
|
|
||||||
|
|
||||||
typedef enum Axis2
|
typedef enum Axis2
|
||||||
{
|
{
|
||||||
AXIS2_X,
|
AXIS2_X,
|
||||||
@ -58,10 +80,6 @@ typedef enum Axis2
|
|||||||
#define NO_EXCEPT
|
#define NO_EXCEPT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define STRUCT_FORWARD_DECL(S) typedef struct S S
|
|
||||||
#define STRUCT(S) STRUCT_FORWARD_DECL(S); struct S
|
|
||||||
#define UNION_FORWARD_DECL(U) typedef union U U
|
|
||||||
#define UNION(U) UNION_FORWARD_DECL(U); union U
|
|
||||||
|
|
||||||
#define Slice(T) Slice_ ## T
|
#define Slice(T) Slice_ ## T
|
||||||
#define SliceP(T) SliceP_ ## T
|
#define SliceP(T) SliceP_ ## T
|
||||||
|
@ -37,3 +37,4 @@ STRUCT(TextureAtlasCreate)
|
|||||||
#include <std/render.h>
|
#include <std/render.h>
|
||||||
|
|
||||||
EXPORT TextureAtlas font_texture_atlas_create(Arena* arena, Renderer* renderer, TextureAtlasCreate create);
|
EXPORT TextureAtlas font_texture_atlas_create(Arena* arena, Renderer* renderer, TextureAtlasCreate create);
|
||||||
|
EXPORT UVec2 texture_atlas_compute_string_rect(String string, const TextureAtlas* atlas);
|
||||||
|
@ -11,12 +11,6 @@ typedef struct Renderer Renderer;
|
|||||||
typedef struct RenderWindow RenderWindow;
|
typedef struct RenderWindow RenderWindow;
|
||||||
typedef struct Pipeline Pipeline;
|
typedef struct Pipeline Pipeline;
|
||||||
|
|
||||||
STRUCT(Vec4)
|
|
||||||
{
|
|
||||||
f32 v[4];
|
|
||||||
}__attribute__((aligned(16)));
|
|
||||||
typedef Vec4 Color;
|
|
||||||
|
|
||||||
STRUCT(RenderRect)
|
STRUCT(RenderRect)
|
||||||
{
|
{
|
||||||
u32 x0;
|
u32 x0;
|
||||||
@ -188,6 +182,7 @@ EXPORT PipelineLayoutIndex renderer_pipeline_get_layout(PipelineIndex pipeline);
|
|||||||
EXPORT void renderer_window_frame_begin(Renderer* renderer, RenderWindow* window);
|
EXPORT void renderer_window_frame_begin(Renderer* renderer, RenderWindow* window);
|
||||||
EXPORT void renderer_window_frame_end(Renderer* renderer, RenderWindow* window);
|
EXPORT void renderer_window_frame_end(Renderer* renderer, RenderWindow* window);
|
||||||
EXPORT TextureIndex renderer_texture_create(Renderer* renderer, TextureMemory texture_memory);
|
EXPORT TextureIndex renderer_texture_create(Renderer* renderer, TextureMemory texture_memory);
|
||||||
|
EXPORT UVec2 renderer_font_compute_string_rect(Renderer* renderer, RenderFontType type, String string);
|
||||||
EXPORT void window_command_begin(RenderWindow* window);
|
EXPORT void window_command_begin(RenderWindow* window);
|
||||||
EXPORT void window_command_end(RenderWindow* window);
|
EXPORT void window_command_end(RenderWindow* window);
|
||||||
EXPORT void window_render_begin(RenderWindow* window);
|
EXPORT void window_render_begin(RenderWindow* window);
|
||||||
|
@ -48,7 +48,6 @@ STRUCT(UI_State)
|
|||||||
Arena* arena;
|
Arena* arena;
|
||||||
Renderer* renderer;
|
Renderer* renderer;
|
||||||
RenderWindow* render;
|
RenderWindow* render;
|
||||||
|
|
||||||
UI_Widget* root;
|
UI_Widget* root;
|
||||||
UI_MousePosition mouse_position;
|
UI_MousePosition mouse_position;
|
||||||
OSEventMouseButtonEvent mouse_button_events[OS_EVENT_MOUSE_BUTTON_COUNT];
|
OSEventMouseButtonEvent mouse_button_events[OS_EVENT_MOUSE_BUTTON_COUNT];
|
||||||
@ -81,5 +80,6 @@ EXPORT u8 ui_build_begin(OSWindow window, f64 frame_time, OSEventQueue* event_qu
|
|||||||
EXPORT void ui_build_end();
|
EXPORT void ui_build_end();
|
||||||
EXPORT void ui_draw();
|
EXPORT void ui_draw();
|
||||||
EXPORT UI_Signal ui_signal_from_widget(UI_Widget* widget);
|
EXPORT UI_Signal ui_signal_from_widget(UI_Widget* widget);
|
||||||
|
EXPORT UI_State* ui_state_get();
|
||||||
|
|
||||||
EXPORT UI_Widget* ui_widget_make(UI_WidgetFlags flags, String string, UI_Rect rect);
|
EXPORT UI_Widget* ui_widget_make(UI_WidgetFlags flags, String string, UI_Rect rect);
|
||||||
|
@ -107,3 +107,20 @@ TextureAtlas font_texture_atlas_create(Arena* arena, Renderer* renderer, Texture
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UVec2 texture_atlas_compute_string_rect(String string, const TextureAtlas* atlas)
|
||||||
|
{
|
||||||
|
auto height = atlas->ascent - atlas->descent;
|
||||||
|
u32 x_offset = 0;
|
||||||
|
u32 y_offset = height;
|
||||||
|
|
||||||
|
for (u64 i = 0; i < string.length; i += 1)
|
||||||
|
{
|
||||||
|
auto ch = string.pointer[i];
|
||||||
|
auto* character = &atlas->characters[ch];
|
||||||
|
auto kerning = (atlas->kerning_tables + ch * 256)[string.pointer[i + 1]];
|
||||||
|
x_offset += character->advance + kerning;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (UVec2) { .x = x_offset, .y = y_offset };
|
||||||
|
}
|
||||||
|
@ -2270,7 +2270,7 @@ void window_render_text(Renderer* renderer, RenderWindow* window, String string,
|
|||||||
auto ch = string.pointer[i];
|
auto ch = string.pointer[i];
|
||||||
auto* character = &texture_atlas->characters[ch];
|
auto* character = &texture_atlas->characters[ch];
|
||||||
auto pos_x = x_offset;
|
auto pos_x = x_offset;
|
||||||
auto pos_y = y_offset + character->y_offset + height; // Offset of the height to render the character from the bottom (y + height) up (y)
|
auto pos_y = y_offset + character->y_offset + height + texture_atlas->descent; // Offset of the height to render the character from the bottom (y + height) up (y)
|
||||||
auto uv_x = character->x;
|
auto uv_x = character->x;
|
||||||
auto uv_y = character->y;
|
auto uv_y = character->y;
|
||||||
auto uv_width = character->width;
|
auto uv_width = character->width;
|
||||||
@ -2328,3 +2328,10 @@ void window_render_text(Renderer* renderer, RenderWindow* window, String string,
|
|||||||
x_offset += character->advance + kerning;
|
x_offset += character->advance + kerning;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UVec2 renderer_font_compute_string_rect(Renderer* renderer, RenderFontType type, String string)
|
||||||
|
{
|
||||||
|
auto* texture_atlas = &renderer->fonts[type];
|
||||||
|
auto result = texture_atlas_compute_string_rect(string, texture_atlas);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
#include <std/ui_builder.h>
|
#include <std/ui_builder.h>
|
||||||
|
#include <std/render.h>
|
||||||
|
|
||||||
UI_Signal ui_button(String string, UI_Rect rect)
|
UI_Signal ui_button(String string, UI_Rect rect)
|
||||||
{
|
{
|
||||||
|
auto rect_offset = renderer_font_compute_string_rect(ui_state_get()->renderer, RENDER_FONT_TYPE_PROPORTIONAL, string);
|
||||||
|
rect.x1 = rect.x0 + rect_offset.x;
|
||||||
|
rect.y1 = rect.y0 + rect_offset.y;
|
||||||
auto* widget = ui_widget_make((UI_WidgetFlags) {
|
auto* widget = ui_widget_make((UI_WidgetFlags) {
|
||||||
.draw_text = 1,
|
.draw_text = 1,
|
||||||
.draw_background = 1,
|
.draw_background = 1,
|
||||||
|
@ -8,6 +8,11 @@ void ui_state_select(UI_State* state)
|
|||||||
ui_state = state;
|
ui_state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UI_State* ui_state_get()
|
||||||
|
{
|
||||||
|
return ui_state;
|
||||||
|
}
|
||||||
|
|
||||||
u8 ui_build_begin(OSWindow window, f64 frame_time, OSEventQueue* event_queue)
|
u8 ui_build_begin(OSWindow window, f64 frame_time, OSEventQueue* event_queue)
|
||||||
{
|
{
|
||||||
u8 open = 1;
|
u8 open = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user