Storage: better presentation
This commit is contained in:
@@ -356,6 +356,71 @@ bool gui_slider(Rect r, f32 min, f32 max, f32 *value)
|
|||||||
return gui_slider(&global_gui_state.default_context, r, min, max, value);
|
return gui_slider(&global_gui_state.default_context, r, min, max, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool gui_slider_text(Gui_Context *ctx, Rect r, f32 min, f32 max, f32 *value, const char *text)
|
||||||
|
{
|
||||||
|
Gui_Id widget_id = gui_id_from_pointer(ctx, value);
|
||||||
|
bool behaviour = gui_button_behaviuor(ctx, widget_id, r);
|
||||||
|
|
||||||
|
if(ctx->active == widget_id)
|
||||||
|
{
|
||||||
|
f32 pointer_ratio = (ctx->input.pointer_position.x - r.position.x) / r.size.x;
|
||||||
|
*value = clamp(0.0f, 1.0f, pointer_ratio) * (max - min) + min;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Colors
|
||||||
|
v4 button_color = ctx->style.button_color;
|
||||||
|
v4 text_color = ctx->style.button_text_color;
|
||||||
|
{
|
||||||
|
f64 delta_t = (ctx->current_frame_time - ctx->hot_start_time);
|
||||||
|
f32 interpolation = sin(10 * delta_t) * 0.5 + 0.5;
|
||||||
|
if(ctx->hot == widget_id)
|
||||||
|
{
|
||||||
|
button_color = lerp(ctx->style.button_color, ctx->style.button_color_hovered, interpolation);
|
||||||
|
text_color = lerp(ctx->style.button_text_color, ctx->style.button_text_color_hovered, interpolation);
|
||||||
|
}
|
||||||
|
if(ctx->active == widget_id)
|
||||||
|
{
|
||||||
|
button_color = lerp(ctx->style.button_color_hovered, ctx->style.button_color_pressed, interpolation * 0.4 + 0.6);
|
||||||
|
text_color = lerp(ctx->style.button_text_color_hovered, ctx->style.button_text_color_pressed, interpolation * 0.4 + 0.6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
f32 border = 2;
|
||||||
|
f32 radius = ctx->style.button_radius;
|
||||||
|
|
||||||
|
// Draw background
|
||||||
|
v4 background_color = ctx->style.button_color;
|
||||||
|
r_2d_immediate_rounded_rectangle(r, radius, background_color); // Background
|
||||||
|
|
||||||
|
// Draw fill
|
||||||
|
f32 ratio = (*value - min) / (max - min);
|
||||||
|
Rect fill_r = r;
|
||||||
|
fill_r.position += v2{border, border};
|
||||||
|
fill_r.size = v2{maximum(0, fill_r.size.x - 2*border), maximum(0, fill_r.size.y - 2*border)};
|
||||||
|
f32 fill_radius = maximum(0, radius - border);
|
||||||
|
fill_r.size.x = fill_r.size.x * ratio;
|
||||||
|
r_2d_immediate_rounded_rectangle(fill_r, fill_radius, ctx->style.slider_fill_color);
|
||||||
|
|
||||||
|
// Draw border
|
||||||
|
v4 border_color = ctx->style.button_color_pressed;
|
||||||
|
Rect border_r = r;
|
||||||
|
border_r.position += v2{border, border} * 0.5;
|
||||||
|
border_r.size = v2{maximum(0, border_r.size.x - border), maximum(0, border_r.size.y - border)};
|
||||||
|
f32 border_radius = maximum(0, radius - border*0.5);
|
||||||
|
r_2d_immediate_rounded_rectangle_outline(border_r, border_radius, border_color, border);
|
||||||
|
|
||||||
|
// Draw value text
|
||||||
|
gui_button_draw_inner_text(ctx, r, text, text_color);
|
||||||
|
|
||||||
|
return behaviour || ctx->active == widget_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gui_slider_text(Rect r, f32 min, f32 max, f32 *value, const char *text)
|
||||||
|
{
|
||||||
|
return gui_slider_text(&global_gui_state.default_context, r, min, max, value, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Images
|
// Images
|
||||||
bool gui_image(Gui_Context *ctx, Rect r, r_texture *texture)
|
bool gui_image(Gui_Context *ctx, Rect r, r_texture *texture)
|
||||||
|
|||||||
@@ -155,6 +155,9 @@ bool gui_button(Rect r, const char *text);
|
|||||||
bool gui_slider(Gui_Context *ctx, Rect r, f32 min, f32 max, f32 *value);
|
bool gui_slider(Gui_Context *ctx, Rect r, f32 min, f32 max, f32 *value);
|
||||||
bool gui_slider(Rect r, f32 min, f32 max, f32 *value);
|
bool gui_slider(Rect r, f32 min, f32 max, f32 *value);
|
||||||
|
|
||||||
|
bool gui_slider_text(Gui_Context *ctx, Rect r, f32 min, f32 max, f32 *value, const char *text);
|
||||||
|
bool gui_slider_text(Rect r, f32 min, f32 max, f32 *value, const char *text);
|
||||||
|
|
||||||
// Checkbox
|
// Checkbox
|
||||||
// Option buttons
|
// Option buttons
|
||||||
// Combo box
|
// Combo box
|
||||||
|
|||||||
@@ -387,7 +387,7 @@ void system_info_gui(Gui_Layout_Grid *grid)
|
|||||||
|
|
||||||
// Window with cpu n., load, ram
|
// Window with cpu n., load, ram
|
||||||
r = grid->rect_at({4,1}, {2,3});
|
r = grid->rect_at({4,1}, {2,3});
|
||||||
layout = gui_layout_grid_create_by_divisions(v2{0,0}, r.size, 2, 3, 0.2*engine.gui_scaling);
|
layout = gui_layout_grid_create_by_divisions(v2{0,0}, r.size, 4, 3, 0.2*engine.gui_scaling);
|
||||||
|
|
||||||
style_select(ctx, system_info.status);
|
style_select(ctx, system_info.status);
|
||||||
gui_window_start(r, 0xabcdef01);
|
gui_window_start(r, 0xabcdef01);
|
||||||
@@ -399,11 +399,19 @@ void system_info_gui(Gui_Layout_Grid *grid)
|
|||||||
char processors[128]; snprintf(processors, 128, "CPUs: %d/%d", system_info.cpus_active, system_info.cpus_total);
|
char processors[128]; snprintf(processors, 128, "CPUs: %d/%d", system_info.cpus_active, system_info.cpus_total);
|
||||||
|
|
||||||
// slider for ram?
|
// slider for ram?
|
||||||
char ram[128]; snprintf(ram, 128, "RAM: %.2f/%.2f GiB", system_info.ram_used / (1024.0*1024.0*1024.0), system_info.ram_total / (1024.0*1024.0*1024.0));
|
char ram[128]; snprintf(ram, 128, "%.2f/%.2f GiB", system_info.ram_used / (1024.0*1024.0*1024.0), system_info.ram_total / (1024.0*1024.0*1024.0));
|
||||||
|
f32 ram_value = system_info.ram_used;
|
||||||
|
|
||||||
gui_text_aligned(layout.cell(2), processors, GUI_ALIGN_LEFT);
|
gui_text_aligned(layout.cell(layout.max_cells_count.x), processors, GUI_ALIGN_LEFT);
|
||||||
gui_text_aligned(layout.cell(2), ram, GUI_ALIGN_LEFT);
|
|
||||||
gui_text_aligned(layout.cell(2), load, GUI_ALIGN_LEFT);
|
v2 ram_text_size = gui_text_compute_size("RAM: ");
|
||||||
|
Rect ram_rect = layout.cell(layout.max_cells_count.x);
|
||||||
|
ram_rect.position.x += ram_text_size.x;
|
||||||
|
ram_rect.size.x -= ram_text_size.x;
|
||||||
|
gui_text_aligned(layout.rect(), "RAM: ", GUI_ALIGN_LEFT);
|
||||||
|
gui_slider_text(ram_rect, 0, system_info.ram_total, &ram_value, ram);
|
||||||
|
|
||||||
|
gui_text_aligned(layout.cell(layout.max_cells_count.x), load, GUI_ALIGN_LEFT);
|
||||||
|
|
||||||
gui_window_end();
|
gui_window_end();
|
||||||
}
|
}
|
||||||
@@ -432,8 +440,6 @@ void network_gui(Gui_Layout_Grid *grid)
|
|||||||
if(device->type != NM_DEVICE_TYPE_ETHERNET && device->type != NM_DEVICE_TYPE_WIFI && device->type != NM_DEVICE_TYPE_WIREGUARD)
|
if(device->type != NM_DEVICE_TYPE_ETHERNET && device->type != NM_DEVICE_TYPE_WIFI && device->type != NM_DEVICE_TYPE_WIREGUARD)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
gui_id_stack_push(ctx, gui_id_from_pointer(ctx, device->name));
|
|
||||||
|
|
||||||
{
|
{
|
||||||
Section_Status status = SECTION_STATUS_OK;
|
Section_Status status = SECTION_STATUS_OK;
|
||||||
if(device->state == NM_DEVICE_STATE_PREPARE ||
|
if(device->state == NM_DEVICE_STATE_PREPARE ||
|
||||||
@@ -525,8 +531,6 @@ void network_gui(Gui_Layout_Grid *grid)
|
|||||||
layout.cell(1);
|
layout.cell(1);
|
||||||
gui_text(layout.cell(layout.max_cells_count.x - layout.cursor.x), state_text);
|
gui_text(layout.cell(layout.max_cells_count.x - layout.cursor.x), state_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
gui_id_stack_pop(ctx);
|
|
||||||
}
|
}
|
||||||
gui_window_end();
|
gui_window_end();
|
||||||
}
|
}
|
||||||
@@ -612,7 +616,7 @@ void fs_gui(Gui_Layout_Grid *grid)
|
|||||||
Gui_Context *ctx = &global_gui_state.default_context;
|
Gui_Context *ctx = &global_gui_state.default_context;
|
||||||
|
|
||||||
Rect r = grid->rect_at({4,5}, {2,grid->max_cells_count.y - 5});
|
Rect r = grid->rect_at({4,5}, {2,grid->max_cells_count.y - 5});
|
||||||
Gui_Layout_Grid layout = gui_layout_grid_create_by_divisions(v2{0,0}, r.size, 2, grid->max_cells_count.y - 5, 0.2*engine.gui_scaling);
|
Gui_Layout_Grid layout = gui_layout_grid_create_by_divisions(v2{0,0}, r.size, 1, grid->max_cells_count.y - 5, 0.2*engine.gui_scaling);
|
||||||
|
|
||||||
style_select(ctx, fs_info.status);
|
style_select(ctx, fs_info.status);
|
||||||
gui_window_start(r, 0xabcdef04);
|
gui_window_start(r, 0xabcdef04);
|
||||||
@@ -622,23 +626,31 @@ void fs_gui(Gui_Layout_Grid *grid)
|
|||||||
layout.row();
|
layout.row();
|
||||||
|
|
||||||
r = layout.rect_at({0,1}, layout.max_cells_count - v2s{0,1});
|
r = layout.rect_at({0,1}, layout.max_cells_count - v2s{0,1});
|
||||||
layout = gui_layout_grid_create_by_divisions(r.position, r.size, layout.max_cells_count.x, layout.max_cells_count.y/1, 0.2*engine.gui_scaling);
|
layout = gui_layout_grid_create_by_divisions(r.position, r.size, layout.max_cells_count.x, layout.max_cells_count.y/3, 0.2*engine.gui_scaling);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for(s32 i = 0; i < fs_info.fs_count; i++)
|
for(s32 i = 0; i < fs_info.fs_count; i++)
|
||||||
{
|
{
|
||||||
gui_id_stack_push(ctx, gui_id_from_pointer(ctx, fs_info.fs[i].device));
|
Rect r = layout.cell();
|
||||||
|
gui_panel(r);
|
||||||
|
|
||||||
gui_button(layout.cell(2), fs_info.fs[i].device);
|
Gui_Layout_Grid layout = gui_layout_grid_create_by_divisions(r.position, r.size, 8, 4, 0.1*engine.gui_scaling);
|
||||||
gui_button(layout.cell(1), fs_info.fs[i].directory);
|
|
||||||
gui_button(layout.cell(1), fs_info.fs[i].type);
|
Rect icon_r = layout.cell(1);
|
||||||
|
icon_r.position += (icon_r.size - v2{1,1}*minimum(icon_r.size.x, icon_r.size.y)) * .5;
|
||||||
|
icon_r.size = v2{1,1} * minimum(icon_r.size.x, icon_r.size.y);
|
||||||
|
|
||||||
|
gui_image(icon_r, &icon_disk);
|
||||||
|
gui_text(layout.cell(layout.max_cells_count.x - layout.cursor.x), fs_info.fs[i].directory);
|
||||||
|
|
||||||
|
|
||||||
|
layout.row(2);
|
||||||
char space[64]; snprintf(space, 64, "%.1f/%.1f GiB", (f32)(fs_info.fs[i].bytes_total - fs_info.fs[i].bytes_available) / (1024*1024*1024), (f32)fs_info.fs[i].bytes_total / (1024*1024*1024));
|
char space[64]; snprintf(space, 64, "%.1f/%.1f GiB", (f32)(fs_info.fs[i].bytes_total - fs_info.fs[i].bytes_available) / (1024*1024*1024), (f32)fs_info.fs[i].bytes_total / (1024*1024*1024));
|
||||||
char percentage[64]; snprintf(percentage, 64, "%.1f%%", (f32)(fs_info.fs[i].bytes_total - fs_info.fs[i].bytes_available) / fs_info.fs[i].bytes_total * 100);
|
char percentage[64]; snprintf(percentage, 64, "%.1f%%", (f32)(fs_info.fs[i].bytes_total - fs_info.fs[i].bytes_available) / fs_info.fs[i].bytes_total * 100);
|
||||||
gui_button(layout.cell(1), space);
|
f32 space_value = fs_info.fs[i].bytes_total - fs_info.fs[i].bytes_available;
|
||||||
gui_button(layout.cell(1), percentage);
|
gui_slider_text(layout.cell(layout.max_cells_count.x), 0, fs_info.fs[i].bytes_total, &space_value, space);
|
||||||
|
gui_text_aligned(layout.cell(layout.max_cells_count.x), percentage, GUI_ALIGN_CENTER);
|
||||||
gui_id_stack_pop(ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gui_window_end();
|
gui_window_end();
|
||||||
|
|||||||
Reference in New Issue
Block a user