cocoa: Add basic support for TouchBar.
parent
75d6395849
commit
a632337ba2
|
@ -55,3 +55,9 @@ PRIVATE>
|
|||
|
||||
PREDICATE: enum-c-type-word < c-type-word
|
||||
"c-type" word-prop enum-c-type? ;
|
||||
|
||||
: enum>values ( enum -- seq )
|
||||
"c-type" word-prop members>> values ;
|
||||
|
||||
: enum>keys ( enum -- seq )
|
||||
"c-type" word-prop members>> keys [ name>> ] map ;
|
|
@ -51,6 +51,7 @@ SYNTAX: IMPORT: scan-token [ ] import-objc-class ;
|
|||
"NSBundle"
|
||||
"NSButton"
|
||||
"NSColorSpace"
|
||||
"NSCustomTouchBarItem"
|
||||
"NSData"
|
||||
"NSDictionary"
|
||||
"NSError"
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
! Copyright (C) 2017 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors alien.enums alien.syntax cocoa cocoa.classes
|
||||
cocoa.messages combinators core-foundation.strings kernel locals
|
||||
namespaces sequences words ;
|
||||
IN: cocoa.touchbar
|
||||
|
||||
! ui.backend.cocoa.views creates buttons for each of these actions
|
||||
ENUM: default-touchbar refresh-all-action auto-use-action ;
|
||||
|
||||
: enum>CFStringArray ( seq -- alien )
|
||||
enum>keys
|
||||
NSArray -> alloc
|
||||
swap <CFStringArray> -> initWithArray: ;
|
||||
|
||||
: make-touchbar ( enum self -- touchbar )
|
||||
[ NSTouchBar -> alloc -> init dup ] dip -> setDelegate: {
|
||||
[ swap enum>CFStringArray -> setDefaultItemIdentifiers: ]
|
||||
[ swap enum>CFStringArray -> setCustomizationAllowedItemIdentifiers: ]
|
||||
[ nip ]
|
||||
} 2cleave ;
|
||||
|
||||
:: make-NSTouchBar-button ( self identifier label-string action-string -- button )
|
||||
NSCustomTouchBarItem -> alloc
|
||||
identifier <CFString> -> initWithIdentifier: :> item
|
||||
NSButton
|
||||
label-string <CFString>
|
||||
self
|
||||
action-string lookup-selector -> buttonWithTitle:target:action: :> button
|
||||
item button -> setView:
|
||||
item ;
|
|
@ -2,12 +2,13 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors alien alien.c-types alien.data alien.strings
|
||||
arrays assocs cocoa cocoa.application cocoa.classes
|
||||
cocoa.pasteboard cocoa.runtime cocoa.subclassing cocoa.types
|
||||
cocoa.views combinators core-foundation.strings core-graphics
|
||||
core-graphics.types core-text io.encodings.utf8 kernel literals
|
||||
locals math math.rectangles namespaces opengl sequences threads
|
||||
ui.gadgets ui.gadgets.private ui.gadgets.worlds ui.gestures
|
||||
ui.private unicode ;
|
||||
cocoa.pasteboard cocoa.runtime cocoa.subclassing cocoa.touchbar
|
||||
cocoa.types cocoa.views combinators core-foundation.strings
|
||||
core-graphics core-graphics.types core-text io.encodings.utf8
|
||||
kernel literals locals math math.rectangles namespaces opengl
|
||||
sequences threads ui.gadgets ui.gadgets.private
|
||||
ui.gadgets.worlds ui.gestures ui.private ui.tools.listener
|
||||
vocabs.refresh ;
|
||||
IN: ui.backend.cocoa.views
|
||||
|
||||
: send-mouse-moved ( view event -- )
|
||||
|
@ -183,6 +184,29 @@ CLASS: FactorView < NSOpenGLView
|
|||
] when
|
||||
] ;
|
||||
|
||||
METHOD: void refreshAllAction [
|
||||
[ refresh-all ] \ refresh-all call-listener
|
||||
] ;
|
||||
|
||||
METHOD: void autoUseAction [
|
||||
[ com-auto-use ] \ com-auto-use call-listener
|
||||
] ;
|
||||
|
||||
METHOD: Class makeTouchBar [ default-touchbar self make-touchbar ] ;
|
||||
|
||||
METHOD: Class touchBar: Class touchbar makeItemForIdentifier: Class string [
|
||||
string CF>string
|
||||
{
|
||||
{ "refresh-all-action" [
|
||||
self "refresh-all-action" "refresh-all" "refreshAllAction" make-NSTouchBar-button
|
||||
] }
|
||||
{ "auto-use-action" [
|
||||
self "auto-use-action" "auto-use" "autoUseAction" make-NSTouchBar-button
|
||||
] }
|
||||
[ drop f ]
|
||||
} case
|
||||
] ;
|
||||
|
||||
! Rendering
|
||||
METHOD: void drawRect: NSRect rect [ self window [ draw-world ] when* ] ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue