Files
coven/ui/widgets.jai
2024-10-11 22:21:32 +02:00

184 lines
7.7 KiB
Plaintext

ui_full_size_background :: (identifier: s64 = 0, loc := #caller_location) {
ui_set_next_size_x(.PIXELS, xx renderer.render_target_width);
ui_set_next_size_y(.PIXELS, xx renderer.render_target_height);
ui_set_next_background_color(.{0.0, 0.0, 0.0, 1.0});
background := ui_box_make(.DRAW_BACKGROUND, hash=get_hash(loc, identifier));
}
ui_button :: (text: string, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_set_next_text(text);
ui_set_next_background_color(.{0.2,0.2,0.2,1});
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(5);
//ui_set_next_text_alignment(CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_TEXT | .DRAW_BACKGROUND | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
}
ui_button_with_texture :: (texture_handle: Texture_Handle, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_set_next_texture(texture_handle);
ui_set_next_size_x(.PIXELS, 20);
ui_set_next_size_y(.PIXELS, 20);
box := ui_box_make(.CLICKABLE | .DRAW_BACKGROUND | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
}
ui_button_no_bg :: (text: string, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_set_next_text(text);
ui_set_next_background_color(.{0.2,0.2,0.2,1});
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(5);
//ui_set_next_text_alignment(.CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
}
ui_button_no_border :: (text: string, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_set_next_text(text);
ui_set_next_background_color(.{0.2,0.2,0.2,1});
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(5);
//ui_set_next_text_alignment(.CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_BACKGROUND | .DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
}
ui_toolbar_button :: (text: string, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_set_next_text(text);
ui_set_next_border_width(1);
ui_set_next_border_color(.{0.5,0.5,0.5,1});
ui_set_next_background_color(.{0.1,0.1,0.1,1});
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding_left(20);
ui_set_next_padding_right(20);
ui_set_next_padding_top(5);
ui_set_next_padding_bottom(5);
//ui_set_next_text_alignment(.CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
box := ui_box_make(.CLICKABLE | .DRAW_BORDER | .DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
}
ui_label :: (text: string, text_color: Color = .{1,1,1,1}, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_text(text);
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
ui_set_next_text_color(text_color);
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(5);
box := ui_box_make(.DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
}
ui_label_fill_parent_x :: (text: string, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_text(text);
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.PCT, 1);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(5);
//ui_set_next_text_alignment(.CENTER_VERTICALLY);
box := ui_box_make(.DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
}
ui_clickable_label :: (text: string, selected: bool = false, identifier: s64 = 0, loc := #caller_location) -> clicked: bool, Interaction_State {
ui_set_next_text(text);
if selected {
ui_set_next_background_color(.{0.5,0.5,0.5,1.0});
} else {
ui_set_next_background_color(.{0.0,1.0,1.0,0.0});
}
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.PCT, 1);
ui_set_next_size_y(.TEXT_DIM);
ui_set_next_padding(5);
//ui_set_next_text_alignment(.CENTER_VERTICALLY);
box := ui_box_make(.DRAW_BACKGROUND | .DRAW_TEXT | .ANIMATE_ON_HOVER | .CLICKABLE, get_hash(loc, identifier));
return box.interaction.clicked, box.interaction;
}
ui_toolbar :: (identifier: s64 = 0, loc := #caller_location) {
ui_set_next_background_color(.{0.2,0.2,0.2,1});
ui_set_next_size_x(.PIXELS, xx renderer.render_target_width);
ui_set_next_size_y(.CHILDREN_SUM);
box := ui_box_make(.DRAW_BACKGROUND | .DRAW_BORDER, get_hash(loc, identifier));
}
ui_tab_title_bar :: (title: string, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_background_color(.{0.03, 0.03, 0.03, 1.0});
ui_set_next_padding(5);
ui_set_next_size_y(.CHILDREN_SUM);
parent := ui_box_make(.DRAW_BACKGROUND | .DRAW_BORDER, get_hash(loc, identifier));
ui_push_parent(parent, alignment=.LEFT, axis=.VERTICAL);
{
ui_set_next_text_alignment(.CENTER_VERTICALLY);
ui_set_next_text(title);
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.TEXT_DIM);
ui_set_next_size_y(.TEXT_DIM);
text := ui_box(.DRAW_TEXT);
}
ui_pop_parent();
}
ui_texture :: (texture: Texture_Handle, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_texture(texture);
ui_set_next_background_color(.{0.1,0.1,0.1,1});
box := ui_box_make(.DRAW_BACKGROUND | .DRAW_BORDER, get_hash(loc, identifier));
}
ui_interactable_texture :: (texture: Texture_Handle, identifier: s64 = 0, loc := #caller_location) -> Interaction_State {
ui_set_next_texture(texture);
ui_set_next_background_color(.{0.1,0.1,0.1,1});
box := ui_box_make(.DRAW_BACKGROUND | .CLICKABLE, get_hash(loc, identifier));
return box.interaction;
}
ui_space :: (width: float, height: float, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_background_color(.{0,0,0,0});
ui_set_next_size_x(.PIXELS, width);
ui_set_next_size_y(.PIXELS, height);
box := ui_box_make(.NONE, get_hash(loc, identifier));
}
ui_slider :: (value: *float, min: float = 0.0, max: float = 1.0, identifier: s64 = 0, loc := #caller_location) {
ui_set_next_background_color(.{0.2,0.2,0.2,1});
ui_set_next_text_color(.{1,1,1,1});
ui_set_next_size_x(.PCT, 1.0);
ui_set_next_size_y(.PIXELS, 15);
ui_set_next_text_alignment(.CENTER_HORIZONTALLY | .CENTER_VERTICALLY);
ui_set_next_text(tprint("%", <<value));
box := ui_box_make(.DRAW_BACKGROUND | .DRAW_TEXT | .ANIMATE_ON_HOVER, get_hash(loc, identifier));
ui_push_parent(box, alignment=.LEFT, axis=.HORIZONTAL);
{
percentage := (<<value - min) / (max - min);
ui_set_next_size_x(.PCT, percentage * 0.95);
ui_set_next_size_y(.PCT, 1.0);
ui_box(.NONE);
ui_set_next_size_x(.PCT, 0.05);
ui_set_next_size_y(.PCT, 1.0);
ui_set_next_background_color(.{0.5,0.5,0.5,1});
draggable := ui_box(.DRAW_BACKGROUND | .CLICKABLE | .ANIMATE_ON_HOVER);
mouse_delta_x := input.mouse.delta_x;
if draggable.interaction.left_mouse_pressed {
increment := (max - min) / box.rect.w;
<<value = clamp(<<value + mouse_delta_x * increment, min, max);
}
}
ui_pop_parent();
}
#load "ui.jai";