Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

[[ CrossPlatformButton ]] Add cross-platform button widget #6266

Open
wants to merge 13 commits into
base: develop
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[[ CrossPlatformButton ]] Add cross platform button
  • Loading branch information
livecodeali committed Mar 12, 2018
commit 029d03db074b991e7d4c57304f835b9cb4394409
2 changes: 2 additions & 0 deletions 2 extensions/extensions.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@
'widgets/gradientrampeditor/gradientrampeditor.lcb',
'widgets/tile/tile.lcb',
'widgets/spinner/spinner.lcb',

'widgets/button/button.lcb',
],

'actions':
Expand Down
120 changes: 120 additions & 0 deletions 120 extensions/widgets/button/button-android.lcb
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
Copyright (C) 2018 LiveCode Ltd.

This file is part of LiveCode.

LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.

LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */

module com.livecode.widget.native.button.android

use com.livecode.widget.native.button.shared
use com.livecode.canvas
use com.livecode.foreign
use com.livecode.java
use com.livecode.library.androidutils

public handler Implementation_Android() returns Array
return \
{ \
"HasImplementation": HasImplementation_Android, \
"HasView": HasView_Android, \
"SetLabel": SetLabel_Android, \
"NativeView": NativeView_Android, \
"UpdateView": UpdateView_Android, \
"DestroyView": DestroyView_Android \
}
end handler

private variable mButtonView_Android as optional JObject

public handler HasImplementation_Android() returns Boolean
return true
end handler

public handler HasView_Android() returns Boolean
return mButtonView_Android is not nothing
end handler

__safe foreign handler _JNI_SetTextViewText(in pView as JObject, in pValue as JString) returns nothing \
binds to "java:android.widget.TextView>setText(Ljava/lang/CharSequence;)V?ui"

public handler SetLabel_Android(in pLabel as String) returns nothing
_JNI_SetTextViewText(mButtonView_Android, StringToJString(pLabel))
end handler

__safe foreign handler _JNI_GetAndroidEngine() returns JObject \
binds to "java:com.runrev.android.Engine>getEngine()Lcom/runrev/android/Engine;!static"
__safe foreign handler _JNI_GetEngineContext(in pEngine as JObject) returns JObject \
binds to "java:android.view.View>getContext()Landroid/content/Context;"

// Handlers for creating and attaching view
__safe foreign handler _JNI_CreateButton(in pContext as JObject) returns JObject \
binds to "java:android.widget.Button>new(Landroid/content/Context;)?ui"
__safe foreign handler _JNI_AddButtonView(in pParentView as JObject, in pChildView as JObject) returns nothing \
binds to "java:android.view.ViewGroup>addView(Landroid/view/View;)V?ui"

public handler ButtonActionCallback(in pView as JObject) returns nothing
PostAction()
end handler

// Handlers for adding click listener
handler type ClickCallback(in pView as JObject) returns nothing
__safe foreign handler _JNI_OnClickListener(in pHandler as ClickCallback) returns JObject \
binds to "java:android.view.View$OnClickListener>interface()"
__safe foreign handler _JNI_SetOnClickListener(in pButton as JObject, in pListener as JObject) returns nothing \
binds to "java:android.view.View>setOnClickListener(Landroid/view/View$OnClickListener;)V?ui"
public handler NativeView_Android() returns Pointer
// Create an android button using the Engine Context
variable tEngine as JObject
put _JNI_GetAndroidEngine() into tEngine

variable tContext as JObject
put _JNI_GetEngineContext(tEngine) into tContext
put _JNI_CreateButton(tContext) into mButtonView_Android

// add an OnClick listener
variable tListener as JObject
put _JNI_OnClickListener(ButtonActionCallback) into tListener
_JNI_SetOnClickListener(mButtonView_Android, tListener)

return PointerFromJObject(mButtonView_Android)
end handler

public handler DestroyView_Android() returns nothing
put nothing into mButtonView_Android
end handler

__safe foreign handler _JNI_SetTextViewEnabled(in pView as JObject, in pValue as JBoolean) returns nothing \
binds to "java:android.view.View>setEnabled(Z)V?ui"
__safe foreign handler _JNI_SetTextViewTypeface(in pView as JObject, in pValue as JBoolean) returns nothing \
binds to "java:android.widget.TextView>setTypeface(Landroid/graphics/Typeface;)V?ui"

__safe foreign handler _JNI_TextViewSetTextSize(in pObj as JObject, in pUnit as JInt, in pSize as JFloat) returns nothing \
binds to "java:android.widget.TextView>setTextSize(IF)V?ui"

constant COMPLEX_UNIT_DIP is 1
public handler UpdateView_Android(in pIntrinsicProps as Array) returns nothing
if mButtonView_Android is nothing then
return
end if

_JNI_SetTextViewEnabled(mButtonView_Android, pIntrinsicProps["enabled"])

variable tTypeface as JObject
variable tSize as Number
put CanvasFontToTypeFace(pIntrinsicProps["font"]) into tTypeface
put the size of pIntrinsicProps["font"] into tSize
_JNI_TextViewSetTextSize(mButtonView_Android, COMPLEX_UNIT_DIP, tSize)
end handler

end module
128 changes: 128 additions & 0 deletions 128 extensions/widgets/button/button-ios.lcb
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
Copyright (C) 2018 LiveCode Ltd.

This file is part of LiveCode.

LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.

LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */

module com.livecode.widget.native.button.ios

use com.livecode.widget.native.button.shared
use com.livecode.canvas
use com.livecode.foreign
use com.livecode.objc

public handler Implementation_Ios() returns Array
return \
{ \
"HasImplementation": HasImplementation_Ios, \
"HasView": HasView_Ios, \
"SetLabel": SetLabel_Ios, \
"NativeView": NativeView_Ios, \
"UpdateView": UpdateView_Ios, \
"DestroyView": DestroyView_Ios \
}
end handler

private variable mButtonView_Ios as optional ObjcObject
private variable mButtonProxy_Ios as optional ObjcObject

public handler HasImplementation_Ios() returns Boolean
return true
end handler

public handler HasView_Ios() returns Boolean
return mButtonView_Ios is not nothing
end handler

public type NSUInteger is CULong

private foreign handler ObjC_UIButtonSetTitleForState(in pObj as ObjcId, in pTitle as ObjcId, in pState as NSUInteger) returns nothing binds to "objc:UIButton.-setTitle:forState:?ui"
public handler SetLabel_Ios(in pLabel as String) returns nothing
unsafe
_SetLabel_Ios(pLabel)
end unsafe
end handler

private unsafe handler _SetLabel_Ios(in pLabel as String) returns nothing
/* We use UIControlStateNormal = 0 */
ObjC_UIButtonSetTitleForState(mButtonView_Ios, StringToNSString(pLabel), 0)
end handler

public handler NativeView_Ios() returns Pointer
unsafe
return _NativeView_Ios()
end unsafe
end handler

private handler ButtonActionCallback_Ios(in pSender as ObjcObject, in pContext as optional any) returns nothing
PostAction()
end handler

private foreign handler ObjC_UIButtonButtonWithType(in pType as NSUInteger) returns ObjcId binds to "objc:UIButton.+buttonWithType:?ui"
private foreign handler ObjC_UIButtonSetEnabled(in pObj as ObjcId, in pEnabled as CBool) returns nothing binds to "objc:UIButton.-setEnabled:?ui"
private foreign handler ObjC_UIButtonGetTitleLabel(in pObj as ObjcId) returns ObjcId binds to "objc:UIButton.-titleLabel?ui"
private foreign handler ObjC_UILabelSetFont(in pObj as ObjcId, in pFont as ObjcId) returns nothing binds to "objc:UILabel.-setFont:?ui"
private foreign handler ObjC_UIButtonAddTargetActionForControlEvents(in pObj as ObjcId, in pTarget as ObjcId, in pAction as UIntPtr, in pControlEvents as NSUInteger) returns nothing binds to "objc:UIButton.-addTarget:action:forControlEvents:?ui"

private unsafe handler _NativeView_Ios() returns Pointer
variable tButtonView as ObjcObject

/* For a standard push button we need:
* type to be UIButtonTypeSystem = 1 */
put ObjC_UIButtonButtonWithType(1) into tButtonView
put tButtonView into mButtonView_Ios

put ObjcProxyGetTarget(ButtonActionCallback_Ios, nothing) into mButtonProxy_Ios

/* For a push button action we need:
* controlEvents to be UIControlEventTouchUpInside = 1 << 6 */
ObjC_UIButtonAddTargetActionForControlEvents(mButtonView_Ios, mButtonProxy_Ios, ObjcProxyGetAction(), 1 shifted left by 6 bitwise)

return PointerFromObjcObject(tButtonView)
end handler

public handler DestroyView_Ios() returns nothing
unsafe
_DestroyView_Ios()
end unsafe
end handler

private unsafe handler _DestroyView_Ios()
put nothing into mButtonView_Ios
put nothing into mButtonProxy_Ios
end handler

public handler UpdateView_Ios(in pIntrinsicProps as Array) returns nothing
unsafe
_UpdateView_Ios(pIntrinsicProps)
end unsafe
end handler

private foreign handler GetFontHandle_Ios(in pFont as Font, out rHandle as ObjcId) returns nothing binds to "MCCanvasFontGetHandle"
private unsafe handler _UpdateView_Ios(in pIntrinsicProps as Array)
if mButtonView_Ios is nothing then
return
end if

/* Set the enabled state of the button to the host property. */
ObjC_UIButtonSetEnabled(mButtonView_Ios, pIntrinsicProps["enabled"])

/* Set the font of the button to the host property. */
variable tFontToUse as ObjcObject
GetFontHandle_Ios(pIntrinsicProps["font"], tFontToUse)
ObjC_UILabelSetFont(ObjC_UIButtonGetTitleLabel(mButtonView_Ios), \
tFontToUse)
end handler

end module
61 changes: 61 additions & 0 deletions 61 extensions/widgets/button/button-linux.lcb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright (C) 2018 LiveCode Ltd.

This file is part of LiveCode.

LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.

LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */

module com.livecode.widget.native.button.linux

use com.livecode.widget.native.button.shared
use com.livecode.foreign

public handler Implementation_Linux() returns Array
return \
{ \
"HasImplementation": HasImplementation_Linux, \
"HasView": HasView_Linux, \
"SetLabel": SetLabel_Linux, \
"NativeView": NativeView_Linux, \
"UpdateView": UpdateView_Linux, \
"DestroyView": DestroyView_Linux \
}
end handler

private variable mButtonView_Linux as optional Pointer

public handler HasImplementation_Linux() returns Boolean
return false
end handler

public handler HasView_Linux() returns Boolean
return mButtonView_Linux is not nothing
end handler

public handler SetLabel_Linux(in pLabel as String) returns nothing
-- not implemented
end handler

public handler NativeView_Linux() returns Pointer
-- not implemented
end handler

public handler DestroyView_Linux() returns nothing
-- not implemented
end handler

public handler UpdateView_Linux(in pIntrinsicProps as Array) returns nothing
-- not implemented
end handler

end module
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.