Skip to content

Commit

Permalink
fix ui tooltip first frame position
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfouilleul committed Oct 5, 2024
1 parent d9d8a49 commit 59de973
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ui/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ oc_ui_box* oc_ui_box_make_str8(oc_str8 string, oc_ui_flags flags)
box->fresh = false;
}

box->flags = flags;
box->string = oc_str8_push_copy(&ui->frameArena, string);

//NOTE: setup hierarchy
if(box->frameCounter != ui->frameCounter)
{
Expand All @@ -421,10 +424,7 @@ oc_ui_box* oc_ui_box_make_str8(oc_str8 string, oc_ui_flags flags)
oc_log_warning("trying to make ui box '%.*s' multiple times in the same frame\n", (int)box->string.len, box->string.ptr);
}

//NOTE: setup per-frame state
box->frameCounter = ui->frameCounter;
box->string = oc_str8_push_copy(&ui->frameArena, string);
box->flags = flags;

//NOTE: create style and setup non-inherited attributes to default values
box->targetStyle = oc_arena_push_type(&ui->frameArena, oc_ui_style);
Expand Down Expand Up @@ -1204,6 +1204,8 @@ void oc_ui_layout_upward_dependent_size(oc_ui_context* ui, oc_ui_box* box, int a
}
}
}
box->rect.c[2 + axis] = oc_max(box->minSize[axis], box->rect.c[2 + axis]);

f32 sum = 0;

//NOTE: recurse in children and recompute children sum
Expand Down Expand Up @@ -2442,7 +2444,7 @@ void oc_ui_tooltip_str8(oc_str8 label)
oc_ui_style containerStyle = { .floating.x = true,
.floating.y = true,
.floatTarget.x = p.x,
.floatTarget.y = p.y };
.floatTarget.y = p.y - 10 }; //TODO: quick fix for aliging single line tooltips arrow to mouse, fix that!
oc_ui_style_next(&containerStyle, OC_UI_STYLE_FLOAT);
oc_ui_container_str8(label, OC_UI_FLAG_OVERLAY)
{
Expand Down
1 change: 1 addition & 0 deletions src/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ ORCA_API oc_ui_sig oc_ui_button(const char* label);
ORCA_API oc_ui_sig oc_ui_checkbox(const char* name, bool* checked);
ORCA_API oc_ui_box* oc_ui_slider(const char* name, f32* value);
ORCA_API oc_ui_box* oc_ui_scrollbar(const char* name, f32 thumbRatio, f32* scrollValue);
ORCA_API void oc_ui_tooltip_str8(oc_str8 label);
ORCA_API void oc_ui_tooltip(const char* label);

ORCA_API void oc_ui_panel_begin(const char* name, oc_ui_flags flags);
Expand Down

0 comments on commit 59de973

Please sign in to comment.