mac_touchbar_common.mm 847 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "platform/mac/touchbar/mac_touchbar_common.h"
  8. #include "base/platform/mac/base_utilities_mac.h"
  9. #import <AppKit/NSTextField.h>
  10. namespace TouchBar {
  11. int WidthFromString(NSString *s) {
  12. return (int)ceil(
  13. [[NSTextField labelWithString:s] frame].size.width) * 1.2;
  14. }
  15. NSImage *CreateNSImageFromStyleIcon(const style::icon &icon, int size) {
  16. auto instance = icon.instance(QColor(255, 255, 255, 255), 100);
  17. instance.setDevicePixelRatio(style::DevicePixelRatio());
  18. NSImage *image = Platform::Q2NSImage(instance);
  19. [image setSize:NSMakeSize(size, size)];
  20. return image;
  21. }
  22. } // namespace TouchBar