#include "ui/formula_bar.hpp" #include namespace htab::ui { void FormulaBar::draw(gemui_app_t* app, cairo_t* cr, gemui_rect_t rect, const std::string& cell_addr, const TextEditor& editor, bool bar_focused, const UiScale& ui, int hit_id_addr, int hit_id_input) { const gemui_theme_t* t = gemui_theme(app); int div_h = std::max(1, spx(1, ui)); gemui_fill_rect(cr, rect, t->bg_bar); gemui_fill_rect(cr, gemui_rect_t{rect.x, rect.y + rect.h - div_h, rect.w, div_h}, t->divider); int font_px = ui.compact ? 10 : 14; int pad_x = spx(ui.compact ? 2 : 6, ui); int pad_y = spx(ui.compact ? 2 : 4, ui); int addr_w = spx(ui.compact ? 46 : 84, ui); int inner_h = std::max(6, rect.h - pad_y * 2 - div_h); gemui_rect_t addr_r{rect.x + pad_x, rect.y + pad_y, addr_w, inner_h}; double rad = 3.0 * ui.scale; double lw = std::max(1.0, ui.scale); gemui_fill_round(cr, addr_r, rad, t->bg_button); gemui_stroke_round(cr, addr_r, rad, lw, t->border); int addr_pad = spx(2, ui); gemui_draw_text(cr, t, gemui_rect_t{addr_r.x + addr_pad, addr_r.y, std::max(1, addr_r.w - addr_pad * 2), addr_r.h}, cell_addr.c_str(), pt_delta_for_ui(t, font_px, ui), true, GEMUI_ALIGN_CENTER, t->accent); if (hit_id_addr >= 0) { gemui_hit_add(app, addr_r, hit_id_addr, 0); } int input_x = addr_r.x + addr_r.w + pad_x; int input_w = std::max(spx(20, ui), rect.x + rect.w - input_x - pad_x); gemui_rect_t input_r{input_x, rect.y + pad_y, input_w, inner_h}; draw_single_line_editor(cr, t, input_r, editor, "=formula or value", bar_focused, font_px, ui); gemui_hit_add(app, input_r, hit_id_input, 0); } } // namespace htab::ui