opuntiaOS - an operating system targeting x86 and ARMv7
1/* 2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors. 3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com> 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9#include "Button.h" 10#include "../Helpers/TextDrawer.h" 11#include <algorithm> 12 13namespace WinServer { 14 15void Button::recalc_dims() 16{ 17 size_t new_width = 0; 18 size_t new_height = 0; 19 if (m_is_icon_set) { 20 new_height = m_icon.height(); 21 new_width += m_icon.width(); 22 if (m_title.size()) { 23 new_width += 4; 24 } 25 } 26 bounds().set_width(new_width + text_width()); 27 bounds().set_height(std::max(new_height, text_height())); 28} 29 30size_t Button::text_width() 31{ 32 return Helpers::text_width(m_title, font()); 33} 34 35void Button::display(LG::Context& ctx, LG::Point<int> pt) 36{ 37 if (m_is_icon_set) { 38 ctx.draw(pt, m_icon); 39 pt.offset_by(m_icon.width() + 4, 0); 40 } 41 42 Helpers::draw_text(ctx, pt, m_title, font()); 43} 44 45} // namespace WinServer