Skip to content

Commit

Permalink
add scale slider to floating controls window
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Dec 9, 2024
1 parent da370bc commit 8ab44a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,26 @@ float2_t gfx_get_offset(void) {
return gfx.offset;
}

float gfx_min_scale(void) {
return 1.0f;
}

float gfx_max_scale(void) {
return 100.0f;
}

void gfx_add_scale(float scale_add) {
assert(gfx.valid);
gfx.scale += scale_add;
if (gfx.scale < 1.0f) {
gfx.scale = 1.0f;
gfx_set_scale(gfx.scale + scale_add);
}

void gfx_set_scale(float scale) {
gfx.scale = scale;
if (gfx.scale < gfx_min_scale()) {
gfx.scale = gfx_min_scale();
}
else if (gfx.scale > 100.0f) {
gfx.scale = 100.0f;
else if (gfx.scale > gfx_max_scale()) {
gfx.scale = gfx_max_scale();
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ void gfx_end(void);
float2_t gfx_get_display_size(void);
void gfx_set_offset(float2_t offset);
float2_t gfx_get_offset(void);
float gfx_min_scale(void);
float gfx_max_scale(void);
void gfx_add_scale(float scale_add);
void gfx_set_scale(float scale);
float gfx_get_scale(void);
float gfx_get_aspect(void);
void gfx_highlight_node(int node_index);
Expand Down
4 changes: 4 additions & 0 deletions src/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,10 @@ static void ui_floating_controls(void) {
pick_set_layer_enabled(i, false);
}
}
float scale = gfx_get_scale();
if (ImGui::SliderFloat("Scale", &scale, gfx_min_scale(), gfx_max_scale(), "%.2f", ImGuiSliderFlags_Logarithmic)) {
gfx_set_scale(scale);
}
}
ImGui::End();
}
Expand Down

0 comments on commit 8ab44a8

Please sign in to comment.