diff options
| -rw-r--r-- | config.h | 8 | ||||
| -rw-r--r-- | font.c | 1 | ||||
| -rw-r--r-- | graphics.c | 14 | ||||
| -rw-r--r-- | layer_surface.c | 4 | ||||
| -rw-r--r-- | state.h | 2 |
5 files changed, 20 insertions, 9 deletions
diff --git a/config.h b/config.h new file mode 100644 index 0000000..3f304d5 --- /dev/null +++ b/config.h @@ -0,0 +1,8 @@ +#ifndef CONFIG_H_ +#define CONFIG_H_ + +#include <stdint.h> + +const uint32_t min_width = 600; + +#endif @@ -148,5 +148,6 @@ int atlas_get_strwidth(client_state* state, const char* str) { void atlas_calc_item_widths(client_state* state) { array_for_all(item_t, item, state->items) { item->pixel_len = atlas_get_strwidth(state, item->text); + state->required_width = MAX(state->required_width, item->pixel_len + state->line_height / 2.0f); } } @@ -142,21 +142,22 @@ void render_frame(client_state *state) { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, state->atlas.texture); - - float pen_x = state->line_height / 4.0f; + float horizontal_spacing = state->line_height / 2.0f; + float pen_x = horizontal_spacing / 2.0f; float pen_y = state->line_height * state->lines - state->atlas.vert_shift; + // draw input buffer if (state->lines > 0) { glScissor(pen_x, pen_y + state->atlas.vert_shift, state->width, state->line_height); } else { glScissor(pen_x, pen_y + state->atlas.vert_shift, state->width / 3.0f - pen_x, state->line_height); } - // draw input buffer glBindVertexArray(state->input_buffer_grafix.vao); glUniform2f(state->offset_uniform, pen_x, pen_y); glDrawElements(GL_TRIANGLES, state->input_buffer_grafix.num_elements, GL_UNSIGNED_INT, 0); - // shift pen + + // set up drawing for options if (state->lines > 0) { glScissor(0, 0, state->width, pen_y); pen_y -= state->line_height; @@ -164,10 +165,9 @@ void render_frame(client_state *state) { else { pen_x += state->width / 3.0f; glScissor(pen_x, 0, state->width, state->line_height); + pen_x += horizontal_spacing / 2.0f; } - pen_x += state->line_height / 4.0f; - // draw options array_for_all(item_t, item, state->items) { glBindVertexArray(item->text_buffer.vao); @@ -179,7 +179,7 @@ void render_frame(client_state *state) { pen_y -= state->line_height; } else { - pen_x += item->pixel_len + (state->line_height / 2.0f); + pen_x += item->pixel_len + horizontal_spacing; } } diff --git a/layer_surface.c b/layer_surface.c index fc0a7e2..7758dde 100644 --- a/layer_surface.c +++ b/layer_surface.c @@ -1,5 +1,5 @@ #include "./state.h" -#include "array.h" +#include "config.h" struct zwlr_layer_surface_v1_listener layer_surface_listener; @@ -16,8 +16,8 @@ void create_surface(client_state* state) { uint32_t desired_width = 0; uint32_t desired_height = state->line_height; if (state->lines > 0) { - desired_width = 600; // calculate based on width of option strings desired_height = (state->lines + 1) * state->line_height; + desired_width = MAX(state->required_width, min_width); } // create surface @@ -89,6 +89,8 @@ typedef struct { atlas_t atlas; uint32_t line_height; + uint32_t required_width; + // arguments int lines; |
