Add tab_align_right

This commit is contained in:
luboslenco
2025-09-20 14:13:18 +02:00
parent ecfcd6bae8
commit fb960ea83a
3 changed files with 10 additions and 3 deletions
+7 -1
View File
@@ -1291,6 +1291,9 @@ void ui_draw_tabs() {
current->_w = current->tab_vertical ? (UI_ELEMENT_W() - 1 * UI_SCALE()) : current->_w = current->tab_vertical ? (UI_ELEMENT_W() - 1 * UI_SCALE()) :
theme->FULL_TABS ? (current->_window_w / current->tab_count) : theme->FULL_TABS ? (current->_window_w / current->tab_count) :
(draw_string_width(current->ops->font, current->font_size, current->tab_names[i]) + current->button_offset_y * 2.0 + 18.0 * UI_SCALE()); (draw_string_width(current->ops->font, current->font_size, current->tab_names[i]) + current->button_offset_y * 2.0 + 18.0 * UI_SCALE());
if (current->tab_align_right) {
current->_x = current->_window_w - current->_w - current->_x;
}
bool released = ui_get_released(tab_h); bool released = ui_get_released(tab_h);
bool started = ui_get_started(tab_h); bool started = ui_get_started(tab_h);
bool pushed = ui_get_pushed(tab_h); bool pushed = ui_get_pushed(tab_h);
@@ -1499,6 +1502,8 @@ void ui_init(ui_t *ui, ui_options_t *ops) {
current->window_ended = true; current->window_ended = true;
current->restore_x = -1; current->restore_x = -1;
current->restore_y = -1; current->restore_y = -1;
current->input_x = -1;
current->input_y = -1;
if (ui_combo_search_handle == NULL) { if (ui_combo_search_handle == NULL) {
ui_combo_search_handle = ui_handle_create(); ui_combo_search_handle = ui_handle_create();
gc_root(ui_combo_search_handle); gc_root(ui_combo_search_handle);
@@ -1820,10 +1825,11 @@ int ui_text(char *text, int align, int bg) {
return started ? UI_STATE_STARTED : released ? UI_STATE_RELEASED : down ? UI_STATE_DOWN : UI_STATE_IDLE; return started ? UI_STATE_STARTED : released ? UI_STATE_RELEASED : down ? UI_STATE_DOWN : UI_STATE_IDLE;
} }
bool ui_tab(ui_handle_t *handle, char *text, bool vertical, uint32_t color) { bool ui_tab(ui_handle_t *handle, char *text, bool vertical, uint32_t color, bool align_right) {
if (current->tab_count == 0) { // First tab if (current->tab_count == 0) { // First tab
current->tab_handle = handle; current->tab_handle = handle;
current->tab_vertical = vertical; current->tab_vertical = vertical;
current->tab_align_right = align_right;
current->_w -= current->tab_vertical ? UI_ELEMENT_OFFSET() + UI_ELEMENT_W() - 1 * UI_SCALE() : 0; // Shrink window area by width of vertical tabs current->_w -= current->tab_vertical ? UI_ELEMENT_OFFSET() + UI_ELEMENT_W() - 1 * UI_SCALE() : 0; // Shrink window area by width of vertical tabs
if (vertical) { if (vertical) {
current->window_header_w += UI_ELEMENT_W(); current->window_header_w += UI_ELEMENT_W();
+2 -1
View File
@@ -256,6 +256,7 @@ typedef struct ui {
ui_handle_t *tab_handle; ui_handle_t *tab_handle;
float tab_scroll; float tab_scroll;
bool tab_vertical; bool tab_vertical;
bool tab_align_right;
bool sticky; bool sticky;
bool scissor; bool scissor;
@@ -276,7 +277,7 @@ void ui_end_region();
bool ui_window(ui_handle_t *handle, int x, int y, int w, int h, bool drag); // Returns true if redraw is needed bool ui_window(ui_handle_t *handle, int x, int y, int w, int h, bool drag); // Returns true if redraw is needed
bool ui_button(char *text, int align, char *label); bool ui_button(char *text, int align, char *label);
int ui_text(char *text, int align, int bg); int ui_text(char *text, int align, int bg);
bool ui_tab(ui_handle_t *handle, char *text, bool vertical, uint32_t color); bool ui_tab(ui_handle_t *handle, char *text, bool vertical, uint32_t color, bool align_right);
bool ui_panel(ui_handle_t *handle, char *text, bool is_tree, bool filled); bool ui_panel(ui_handle_t *handle, char *text, bool is_tree, bool filled);
int ui_sub_image(gpu_texture_t *image, uint32_t tint, int h, int sx, int sy, int sw, int sh); int ui_sub_image(gpu_texture_t *image, uint32_t tint, int h, int sx, int sy, int sw, int sh);
int ui_image(gpu_texture_t *image, uint32_t tint, int h); int ui_image(gpu_texture_t *image, uint32_t tint, int h);
+1 -1
View File
@@ -702,7 +702,7 @@ declare let ui_nodes_grid_snap: bool;
declare function ui_nest(handle: ui_handle_t, pos: i32): ui_handle_t; declare function ui_nest(handle: ui_handle_t, pos: i32): ui_handle_t;
declare function ui_theme_default(theme: ui_theme_t): void; declare function ui_theme_default(theme: ui_theme_t): void;
declare function ui_tab(handle: ui_handle_t, text: string, vertical: bool = false, color: i32 = -1): bool; declare function ui_tab(handle: ui_handle_t, text: string, vertical: bool = false, color: i32 = -1, align_right: bool = false): bool;
declare function ui_combo(handle: ui_handle_t, texts: string[], label: string = "", show_label: bool = false, align: ui_align_t = ui_align_t.LEFT, search_bar: bool = true): i32; declare function ui_combo(handle: ui_handle_t, texts: string[], label: string = "", show_label: bool = false, align: ui_align_t = ui_align_t.LEFT, search_bar: bool = true): i32;
declare function ui_slider(handle: ui_handle_t, text: string, from: f32 = 0.0, to: f32 = 1.0, filled: bool = false, precision: f32 = 100.0, display_value: bool = true, align: ui_align_t = ui_align_t.RIGHT, text_edit: bool = true): f32; declare function ui_slider(handle: ui_handle_t, text: string, from: f32 = 0.0, to: f32 = 1.0, filled: bool = false, precision: f32 = 100.0, display_value: bool = true, align: ui_align_t = ui_align_t.RIGHT, text_edit: bool = true): f32;
declare function ui_button(text: string, align: ui_align_t = ui_align_t.CENTER, label: string = ""): bool; declare function ui_button(text: string, align: ui_align_t = ui_align_t.CENTER, label: string = ""): bool;