Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Text Input #69

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ _build
*.log
*.install
default.profraw
.vscode
2 changes: 2 additions & 0 deletions renderer-macos/lib/Brisk_macos.re
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Cocoa = {
module BriskButton = BriskButton;
module BriskImage = BriskImage;
module BriskTextView = BriskTextView;
module BriskTextInput = BriskTextInput;
module GCD = GCD;

module BriskEffectView = BriskEffectView;
Expand All @@ -24,3 +25,4 @@ module Text = Text;
module Image = Image;
module Button = Button;
module EffectView = EffectView;
module TextInput = TextInput;
21 changes: 21 additions & 0 deletions renderer-macos/lib/bindings/BriskTextInput.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
type t = CocoaTypes.view;

[@noalloc] external make: unit => t = "ml_BriskTextInput_make";

[@noalloc]
external setCallback: (t, unit => unit) => unit = "ml_BriskTextInput_setCallback";

let make = (~onChange=?, ()) => {
let input = make();

switch (onChange) {
| Some(callback) =>
setCallback(
input,
UIEventCallback.make(callback),
)
| None => ()
};

input;
};
37 changes: 37 additions & 0 deletions renderer-macos/lib/components/TextInput.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
open Brisk;

type attribute = [ Layout.style ];

type style = list(attribute);

let component = nativeComponent("TextInput");
let make = (~style= [], ~callback=() => (), children) =>
component((_: Hooks.empty) =>
{
make: () => {
let input =
BriskTextInput.(
make(~onChange=callback, ())
);
},
configureInstance: (~isFirstRender as _, {view} as node) => {
style
|> List.iter(attribute =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just FYI - this doesn't do any magic. In this case the iter does nothing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, thanks. 😅
I have so many errors being thrown regarding BriskTextInput.c, I feel like once I get that ironed out I'll have a better way of understanding and implementing the component part.

switch (attribute) {
| #Layout.style => ()
}
);
node;
},
children,
}
);

let createElement = (~style=[], ~callback=?, ~children, ()) =>
element(
make(
~style,
~callback?,
listToElement(children)
)
);
1 change: 1 addition & 0 deletions renderer-macos/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
BriskButton
GCD
BriskEffectView
BriskTextInput
)
(c_flags (:standard
-Wextra -Wall -Werror -O -g -std=c99 -pedantic-errors -Wsign-compare -Wshadow
Expand Down
15 changes: 15 additions & 0 deletions renderer-macos/lib/stubs/BriskTextInput.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@interface BriskTextInput : NSTextInputContext <NSTextInputClient>

@end

@implementation BriskTextInput

@end

NSTextInputContext *ml_BriskTextInput_make() {
BriskTextInput *input = [BriskTextInput new];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so ml_BriskTextInput_make should return a view (Like NSTextField or editable NSTextView.) NSTextInputContext is just a protocol (think java interface, functor signature (kinda)) related to text input.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So NSTextInputContext is actually a class and NSTextInputClient is a protocol. Should ml_BriskTextInput_make then return a NSTextField or NSTextView conforming to NSTextInputClient protocol?

retainView(input);

return input;
}