Login
1 branch 0 tags
Ben (Desktop/Arch) Show paused icon in topbar bff5fa6 1 month ago 62 Commits
moon / src / topbar.c
#include "topbar.h"
#include "audio_player.h"
#include "fonts/fonts.h"
#include "lvgl.h"
#include "moon.h"
#include "ui.h"
#include <stdio.h>

static lv_obj_t *topbar;
static lv_obj_t *title_label;
static lv_obj_t *status_label;

void topbar_create(void) {
    topbar = lv_obj_create(lv_layer_top());
    lv_obj_set_size(topbar, SCREEN_WIDTH, TOPBAR_H);
    lv_obj_set_pos(topbar, 0, 0);
    lv_obj_clear_flag(topbar, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_set_style_radius(topbar, 0, 0);
    lv_obj_set_style_border_width(topbar, 0, 0);
    lv_obj_set_style_pad_hor(topbar, 4, 0);
    lv_obj_set_style_pad_ver(topbar, 0, 0);
    lv_obj_set_style_bg_color(topbar, lv_palette_main(LV_PALETTE_LIGHT_BLUE),
                              0);
    lv_obj_set_style_bg_opa(topbar, LV_OPA_COVER, 0);

    title_label = lv_label_create(topbar);
    lv_label_set_text(title_label, "");
    lv_obj_set_style_text_font(title_label, &roboto_condensed, 0);
    lv_obj_set_style_text_color(title_label, lv_color_white(), 0);
    lv_obj_set_width(title_label, 110);
    lv_label_set_long_mode(title_label, LV_LABEL_LONG_CLIP);
    lv_obj_align(title_label, LV_ALIGN_LEFT_MID, 0, 0);

    status_label = lv_label_create(topbar);
    lv_label_set_text(status_label, "");
    lv_obj_set_style_text_font(status_label, &roboto_condensed, 0);
    lv_obj_set_style_text_color(status_label, lv_color_white(), 0);
    lv_obj_set_style_transform_scale(status_label, TOPBAR_ICON_SCALE, 0);
    lv_obj_set_style_transform_pivot_x(status_label, LV_PCT(100), 0);
    lv_obj_set_style_transform_pivot_y(status_label, LV_PCT(50), 0);
    lv_obj_align(status_label, LV_ALIGN_RIGHT_MID, 0, 0);
}

void topbar_set_title(const char *title) {
    lv_label_set_text(title_label, title);
}

void topbar_update(void) {
    int n = 0;

    const audio_state_t player_state = audio_player_get_state();
    if (player_state == AUDIO_STATE_PLAYING) {
        n += snprintf(string_buffer + n, sizeof(string_buffer) - (size_t)n,
                      LV_SYMBOL_PLAY " ");
    } else if (player_state == AUDIO_STATE_PAUSED) {
        n += snprintf(string_buffer + n, sizeof(string_buffer) - (size_t)n,
                      LV_SYMBOL_PAUSE " ");
    }

    n += snprintf(string_buffer + n, sizeof(string_buffer) - (size_t)n,
                  LV_SYMBOL_WIFI " ");
    snprintf(string_buffer + n, sizeof(string_buffer) - (size_t)n,
             LV_SYMBOL_BATTERY_FULL);

    lv_label_set_text(status_label, string_buffer);
}