mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-19 15:47:11 +02:00
Added common touchbar utils.
This commit is contained in:
parent
b02dd889e0
commit
0970728273
3 changed files with 64 additions and 0 deletions
|
@ -891,6 +891,8 @@ PRIVATE
|
|||
platform/mac/specific_mac_p.h
|
||||
platform/mac/window_title_mac.mm
|
||||
platform/mac/window_title_mac.h
|
||||
platform/mac/touchbar/mac_touchbar_common.h
|
||||
platform/mac/touchbar/mac_touchbar_common.mm
|
||||
platform/win/audio_win.cpp
|
||||
platform/win/audio_win.h
|
||||
platform/win/file_utilities_win.cpp
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#import <AppKit/NSImage.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
namespace TouchBar {
|
||||
|
||||
constexpr auto kCircleDiameter = 30;
|
||||
|
||||
template <typename Callable>
|
||||
void CustomEnterToCocoaEventLoop(Callable callable) {
|
||||
id block = [^{ callable(); } copy]; // Don't forget to -release.
|
||||
[block
|
||||
performSelectorOnMainThread:@selector(invoke)
|
||||
withObject:nil
|
||||
waitUntilDone:true];
|
||||
// [block performSelector:@selector(invoke) withObject:nil afterDelay:d];
|
||||
[block release];
|
||||
}
|
||||
|
||||
int WidthFromString(NSString *s);
|
||||
|
||||
NSImage *CreateNSImageFromStyleIcon(const style::icon &icon, int size);
|
||||
|
||||
} // namespace TouchBar
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "platform/mac/touchbar/mac_touchbar_common.h"
|
||||
|
||||
#import <AppKit/NSTextField.h>
|
||||
|
||||
NSImage *qt_mac_create_nsimage(const QPixmap &pm);
|
||||
|
||||
namespace TouchBar {
|
||||
|
||||
int WidthFromString(NSString *s) {
|
||||
return (int)ceil(
|
||||
[[NSTextField labelWithString:s] frame].size.width) * 1.2;
|
||||
}
|
||||
|
||||
NSImage *CreateNSImageFromStyleIcon(const style::icon &icon, int size) {
|
||||
const auto instance = icon.instance(QColor(255, 255, 255, 255), 100);
|
||||
auto pixmap = QPixmap::fromImage(instance);
|
||||
pixmap.setDevicePixelRatio(cRetinaFactor());
|
||||
NSImage *image = [qt_mac_create_nsimage(pixmap) autorelease];
|
||||
[image setSize:NSMakeSize(size, size)];
|
||||
return image;
|
||||
}
|
||||
|
||||
} // namespace TouchBar
|
Loading…
Add table
Reference in a new issue