### SilkUI Minimal Setup Import Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-import-guide.md A minimal import example demonstrating the essential HarmonyOS and SilkUI components needed to start using SilkUI buttons. ```cangjie import ohos.base.* import ohos.component.* import ohos.state_manage.* import ohos.state_macro_manage.* import silkui.components.button.SilkButton import silkui.components.button.SilkButtonOptions ``` -------------------------------- ### Start Development Server for Documentation Website Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/Silkui/CLAUDE.md Starts the development server for the Vue.js documentation website. Run this command in the docs-vue directory. ```bash cd docs-vue npm run dev ``` -------------------------------- ### Install Dependencies for Documentation Website Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/Silkui/CLAUDE.md Installs the necessary dependencies for the Vue.js documentation website. Run this command in the docs-vue directory. ```bash cd docs-vue npm install ``` -------------------------------- ### SilkButtonLoading Usage Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-button-component.md Shows how to implement SilkButtonLoading with a linked loading state. The example demonstrates toggling the loading state to manage an asynchronous operation. ```cangjie @Component class MyView { @State var isLoading: Bool = false func build() { SilkButtonLoading( props: SilkButtonOptions( text: "Submit", buttonType: SilkButtonType.PRIMARY ), loading: $isLoading ).click { e => isLoading = true // Perform async operation... isLoading = false } } } ``` -------------------------------- ### Confirmation Dialog Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-dialog-component.md Provides an example of how to implement a confirmation dialog with a confirm action handler. ```APIDOC ## Confirmation Dialog ### Description An advanced example demonstrating a confirmation dialog that includes a `confirm` action handler to process the user's decision. ### Usage ```cangjie SilkDialog( visible: $showConfirm, props: SilkDialogOptions( title: "Delete Item", message: "This action cannot be undone. Continue?", theme: SilkDialogTheme.DEFAULT ) ).confirm { result => if (result.isSome() && result.getOrThrow()) { deleteItem() } showConfirm = false } ``` ``` -------------------------------- ### Example SilkUILinearGradientOptions Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-types.md An example of how to instantiate SilkUILinearGradientOptions to create a red gradient. ```cangjie let redGradient = SilkUILinearGradientOptions( angle: 45.0, colors: [ (Color(255, 0, 0, alpha: 1.0), 0.0), (Color(255, 100, 0, alpha: 1.0), 1.0) ] ) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/AIClassify/entry/src/main/cpp/CMakeLists.txt Sets the minimum CMake version and project name for the native build. ```cmake cmake_minimum_required(VERSION 3.5.0) project(native_demo) ``` -------------------------------- ### CJPM Command Extension Example Source: https://github.com/piagari/deveco_cangjie/blob/main/cjpm相关知识/cjpm_manual.md Demonstrates how to extend CJPM commands using an executable file named 'cjpm-demo'. This example shows a simple Cangjie program that processes command-line arguments. ```cangjie import std.process.* import std.collection.* main(): Int64 { var args = ArrayList(Process.current.arguments) if (args.size < 1) { eprintln("Error: failed to get parameters") return 1 } println("Output: ${args[0]}") return 0 } ``` -------------------------------- ### ResourceStr Usage Examples Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-types.md Demonstrates how to use ResourceStr for literal strings and resource references. ```cangjie // Literal string let text: ResourceStr = "Hello" // Resource reference let resourceText: ResourceStr = @r(app.string.button_text) ``` -------------------------------- ### CJPM Target Configuration Merging Example Source: https://github.com/piagari/deveco_cangjie/blob/main/cjpm相关知识/cjpm_manual.md Illustrates the structure of a CJPM TOML file with nested target-specific configurations for 'x86_64-unknown-linux-gnu' in both general and debug modes. This example demonstrates how 'compile-option', 'link-option', 'dependencies', and 'bin-dependencies' are defined at various levels. ```toml [package] compile-option = "compile-0" override-compile-option = "override-compile-0" link-option = "link-0" [dependencies] dep0 = { path = "./dep0" } [test-dependencies] devDep0 = { path = "./devDep0" } [target.x86_64-unknown-linux-gnu] compile-option = "compile-1" override-compile-option = "override-compile-1" link-option = "link-1" [target.x86_64-unknown-linux-gnu.dependencies] dep1 = { path = "./dep1" } [target.x86_64-unknown-linux-gnu.test-dependencies] devDep1 = { path = "./devDep1" } [target.x86_64-unknown-linux-gnu.bin-dependencies] path-option = ["./test/pro1"] [target.x86_64-unknown-linux-gnu.bin-dependencies.package-option] "pro1.xoo" = "./test/pro1/pro1.xoo.cjo" [target.x86_64-unknown-linux-gnu.debug] compile-option = "compile-2" override-compile-option = "override-compile-2" link-option = "link-2" [target.x86_64-unknown-linux-gnu.debug.dependencies] dep2 = { path = "./dep2" } [target.x86_64-unknown-linux-gnu.debug.test-dependencies] devDep2 = { path = "./devDep2" } [target.x86_64-unknown-linux-gnu.debug.bin-dependencies] path-option = ["./test/pro2"] [target.x86_64-unknown-linux-gnu.debug.bin-dependencies.package-option] "pro2.xoo" = "./test/pro2/pro2.xoo.cjo" ``` -------------------------------- ### Organize Imports by Source Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-import-guide.md Example of organizing imports by their source: framework, standard library, and SilkUI. This promotes cleaner code structure. ```cangjie // Framework imports import ohos.base.* import ohos.component.* import ohos.state_manage.* import ohos.state_macro_manage.* import ohos.resource_manager.* // Standard library import std.collection.* import std.time.* // SilkUI import silkui.components.button.* import silkui.components.dialog.* ``` -------------------------------- ### MySQL Connection API Example Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/News/NewsServer/mysqlclient-ffi/doc/feature_api.md Shows how to initialize the MySQL driver, open a data source, establish a connection, select a database using MysqlConnectionApi, and then close the connection. ```cangjie import mysqlclient_ffi.* import std.unittest.* import std.unittest.testmacro.* main():Int64{ // 初始化数据库驱动 let mysqlDriver: MysqlDriver = MysqlDriver("mysql") // 通过connectionString和选项打开数据源 let mysqlDatasource: MysqlDatasource = mysqlDriver.open( "HOST=127.0.0.1;USER=root;PASSWD=123;DB=mysql;PORT=3306;UNIX_SOCKET=;CLIENT_FLAG=0", Array<(String, String)>() ) // 返回一个可用的链接 let mysqlConnection: MysqlConnection = mysqlDatasource.connect() let mysqlConnectionApi: MysqlConnectionApi = MysqlConnectionApi(mysqlConnection) let ret: Int32 = mysqlConnectionApi.mysqlSelectDb("mysql") @Assert(0, ret) mysqlConnection.close() } ``` -------------------------------- ### CangjieScript Component Implementation Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-architecture-guide.md Shows the basic structure of a UI component class in CangjieScript, including properties and the build method. ```cangjie @Component public class MyComponent { @Prop var props: ComponentOptions @BuilderParam var Content: () -> Unit = DefaultBuilder var click: (ClickEvent) -> Unit = {_=>} func build() { // Component UI implementation } } ``` -------------------------------- ### Full Button Component Setup Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-import-guide.md Imports all necessary modules for a full button component setup, including base, component, state management, resource management, and specific SilkUI button components and constants. ```cangjie import ohos.base.* import ohos.component.* import ohos.state_manage.* import ohos.state_macro_manage.* import ohos.resource_manager.* import silkui.components.button.SilkButton import silkui.components.button.SilkButtonLoading import silkui.components.button.SilkButtonDisabled import silkui.components.button.SilkButtonAll import silkui.components.button.SilkButtonOptions import silkui.components.button.SilkButtonType import silkui.components.button.SilkButtonSize import silkui.components.button.SilkButtonIconPosition import silkui.constants.getButtonColorConstant import silkui.constants.getSizeConstant ``` -------------------------------- ### Calendar Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/INDEX.md Demonstrates how to use the SilkCalendar component for date selection. This example configures a single date selection mode and handles the confirmation event to update the selected date. ```cangjie SilkCalendar( visible: $showCalendar, props: SilkCalendarOptions( typeValue: SilkCalendarType.SINGLE ) ).confirm { date, _, _ => selectedDate = date showCalendar = false } ``` -------------------------------- ### Loading Button Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/INDEX.md Shows how to implement a button that displays a loading state. The `loading` property is bound to a state variable to control the visual indicator. ```cangjie @State var isLoading: Bool = false SilkButtonLoading( props: SilkButtonOptions(text: "Submit"), loading: $isLoading ).click { e => performAction() } ``` -------------------------------- ### ArkTS Start Recording and Recognition Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/19-CangjiexArkTS/AudioToText/README.md Initiates the recording and speech recognition process in ArkTS. This includes creating the engine, setting audio parameters, starting the listening session, and writing captured audio data to the engine. ```typescript public async startRecording(callback: AudioCallback): Promise { await this.createEngine(); // 生成新会话ID this.activeSessionId = this.generateSessionId(); this.callback = callback; // 设置识别参数 const audioParams: speechRecognizer.AudioInfo = { audioType: 'pcm', sampleRate: 16000, soundChannel: 1, sampleBit: 16 }; const extraParams: Record = { "recognitionMode": 0, // 流式识别 "vadBegin": 2000, // 开始静音检测时间(ms) "vadEnd": 3000, // 结束静音检测时间(ms) "maxAudioDuration": 60000 // 最大音频时长(ms) }; const startParams: speechRecognizer.StartParams = { sessionId: this.activeSessionId, audioInfo: audioParams, extraParams: extraParams }; // 开始识别会话 asrEngine.startListening(startParams); // 初始化音频采集器 let data: ArrayBuffer; console.info(TAG, 'create capture success'); this.mAudioCapturer.init((dataBuffer: ArrayBuffer) => { console.info(TAG, 'start write'); console.info(TAG, 'ArrayBuffer ' + JSON.stringify(dataBuffer)); data = dataBuffer let uint8Array: Uint8Array = new Uint8Array(data); console.info(TAG, 'ArrayBuffer uint8Array ' + JSON.stringify(uint8Array)); asrEngine.writeAudio(this.activeSessionId, uint8Array); }); } ``` -------------------------------- ### Configure and Get SSL Information with MysqlSslApi Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/News/NewsServer/mysqlclient-ffi/doc/feature_api.md Illustrates setting SSL options and retrieving SSL information using MysqlSslApi. It covers setting cipher, getting cipher, checking session reuse, and managing session data. ```cangjie import mysqlclient_ffi.* import std.unittest.* import std.unittest.testmacro.* main():Int64{ // 初始化数据库驱动 let mysqlDriver: MysqlDriver = MysqlDriver("mysql") // 通过connectionString和选项打开数据源 let mysqlDatasource: MysqlDatasource = mysqlDriver.open( "HOST=127.0.0.1;USER=root;PASSWD=123;DB=mysql;PORT=3306;UNIX_SOCKET=;CLIENT_FLAG=0", Array<(String, String)>() ) // 返回一个可用的链接 let mysqlConnection: MysqlConnection = mysqlDatasource.connect() let mysqlSslApi: MysqlSslApi = MysqlSslApi(mysqlConnection) var isBool: Bool = mysqlSslApi.mysqlSslSet("", "", "", "", "") @Assert(false, isBool) var strCipher: String = mysqlSslApi.mysqlGetSslCipher() @Assert("", strCipher) isBool = mysqlSslApi.mysqlGetSslSessionReused() @Assert(false, isBool) mysqlSslApi.mysqlGetSslSessionData(0, CPointer()) isBool = mysqlSslApi.mysqlFreeSslSessionData(CPointer()) @Assert(true, isBool) mysqlConnection.close() } ``` -------------------------------- ### MySQL Character Set Operations Example Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/News/NewsServer/mysqlclient-ffi/doc/feature_api.md Demonstrates how to initialize the MySQL driver, open a data source, connect, and then set and verify different character sets using the MysqlCharSetApi. ```cangjie import mysqlclient_ffi.* import std.unittest.* import std.unittest.testmacro.* main():Int64{ // 初始化数据库驱动 let mysqlDriver: MysqlDriver = MysqlDriver("mysql") // 通过connectionString和选项打开数据源 let mysqlDatasource: MysqlDatasource = mysqlDriver.open( "HOST=127.0.0.1;USER=root;PASSWD=123;DB=mysql;PORT=3306;UNIX_SOCKET=;CLIENT_FLAG=0", rray<(String, String)>() ) // 返回一个可用的链接 let mysqlConnection: MysqlConnection = mysqlDatasource.connect() let mysqlCharSetApi: MysqlCharSetApi = MysqlCharSetApi(mysqlConnection) @Assert("utf8mb4", mysqlCharSetApi.mysqlCharacterSetName()) var ret: Int32 = mysqlCharSetApi.mysqlSetCharacterSet("utf8") @Assert(true, ret == 0) @Assert("utf8mb3", mysqlCharSetApi.mysqlCharacterSetName()) ret = mysqlCharSetApi.mysqlSetCharacterSet("ascii") @Assert(true, ret == 0) @Assert("ascii", mysqlCharSetApi.mysqlCharacterSetName()) ret = mysqlCharSetApi.mysqlSetCharacterSet("gbk") @Assert(true, ret == 0) @Assert("gbk", mysqlCharSetApi.mysqlCharacterSetName()) ret = mysqlCharSetApi.mysqlSetCharacterSet("utf8mb4") @Assert(true, ret == 0) @Assert("utf8mb4", mysqlCharSetApi.mysqlCharacterSetName()) mysqlConnection.close() } ``` -------------------------------- ### Spinner Loading Indicator Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-loading-component.md Illustrates a spinner loading indicator with custom size, text, and color. ```cangjie SilkLoading( loadingType: SilkLoadingType.SPINNER, size: 24.vp, text: "Uploading...", color: Color(0xFF9800) ) ``` -------------------------------- ### SilkLoading Color Customization Examples Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-loading-component.md Demonstrates customizing SilkLoading with various theme colors for the spinner and text. ```cangjie // Primary blue SilkLoading( loadingType: SilkLoadingType.CIRCULAR, color: Color(0x3366FF), textColor: Color(0x333333) ) // Success green SilkLoading( loadingType: SilkLoadingType.CIRCULAR, color: Color(0x4CAF50), textColor: Color(0x2E7D32) ) // Warning orange SilkLoading( loadingType: SilkLoadingType.CIRCULAR, color: Color(0xFF9800), textColor: Color(0xE65100) ) // Danger red SilkLoading( loadingType: SilkLoadingType.CIRCULAR, color: Color(0xF44336), textColor: Color(0xC62828) ) ``` -------------------------------- ### Multi-Button Dialog Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-dialog-component.md Demonstrates the creation of a dialog with multiple custom buttons defined in the footer. ```APIDOC ## Multi-Button Dialog ### Description An example showcasing a dialog configured with a custom footer containing multiple buttons, allowing users to select from various actions. ### Usage ```cangjie SilkDialog( visible: $showDialog, props: SilkDialogOptions( title: "Choose an Action", message: "Select one of the options below", theme: SilkDialogTheme.CUSTOM ) ).Footer({ Row() { Button("Option A").layoutWeight(1).onClick { _ => handleOptionA() } Button("Option B").layoutWeight(1).onClick { _ => handleOptionB() } Button("Cancel").layoutWeight(1).onClick { _ => showDialog = false } }.width(100.percent).padding(12) }) ``` ``` -------------------------------- ### Basic Button Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/INDEX.md Demonstrates how to create a basic clickable button with primary styling. The click event is handled by the handleClick function. ```cangjie SilkButton(props: SilkButtonOptions( text: "Click Me", buttonType: SilkButtonType.PRIMARY )).click { e => handleClick() } ``` -------------------------------- ### Adaptive Layout for Different Screen Sizes Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-advanced-patterns.md Create responsive UIs that adapt to different screen sizes. This example demonstrates switching between a desktop and mobile layout based on screen width. ```cangjie import ohos.display.getDefaultDisplaySync @Component class AdaptiveLayout { let screenWidth = Int64(getDefaultDisplaySync().width) let isWideScreen = screenWidth > 600 func build() { if (isWideScreen) { // Desktop layout Row() { Sidebar().width(200.vp) MainContent().layoutWeight(1) } } else { // Mobile layout Column() { Sidebar().height(100.vp) MainContent().layoutWeight(1) } } } } ``` -------------------------------- ### CJPM Command Extension Usage Example Source: https://github.com/piagari/deveco_cangjie/blob/main/cjpm相关知识/cjpm_manual.md Shows the command-line invocation for an extended CJPM command ('cjpm demo') and the expected output when the 'cjpm-demo' executable is in the system's PATH. ```shell cjpm demo hello,world ``` -------------------------------- ### SilkButtonAll Usage Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-button-component.md Illustrates the usage of SilkButtonAll, managing its loading and disabled states with @State variables and defining a click handler. ```cangjie @Component class MyView { @State var isLoading: Bool = false @State var isDisabled: Bool = true func build() { SilkButtonAll( props: SilkButtonOptions( text: "Save", buttonType: SilkButtonType.SUCCESS ), loading: $isLoading, disabled: $isDisabled ).click { e => // Only executed when neither loading nor disabled saveData() } } } ``` -------------------------------- ### CJPM Build Script with Pre/Post Build Actions Source: https://github.com/piagari/deveco_cangjie/blob/main/cjpm相关知识/cjpm_manual.md Example `build.cj` script defining `stagePreBuild` and `stagePostBuild` functions that print messages. These are executed when `cjpm build` is run. ```cangjie import std.process.* func stagePreBuild(): Int64 { println("PRE-BUILD") 0 } func stagePostBuild(): Int64 { println("POST-BUILD") 0 } main(): Int64 { match (Process.current.arguments[0]) { case "pre-build" => stagePreBuild() case "post-build" => stagePostBuild() case _ => 0 } } ``` -------------------------------- ### Modal Navigation with SilkDialog Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-advanced-patterns.md Implement multi-step modal navigation using SilkDialog. This example shows how to transition between a details modal and a confirmation modal. ```cangjie @Component class ModalNavigation { @State var currentModal: Int = 0 // 0 = closed, 1 = details, 2 = confirm @State var selectedItem: ?String = Option.None func build() { Column() { Button("Show Item").onClick { _ => currentModal = 1 } // Details modal SilkDialog( visible: currentModal == 1, props: SilkDialogOptions( title: "Item Details", message: selectedItem.getOrThrow() ) ).confirm { _ => currentModal = 2 // Navigate to confirm modal }.cancel { => currentModal = 0 } // Confirm modal SilkDialog( visible: currentModal == 2, props: SilkDialogOptions( title: "Confirm Action", message: "Proceed with deletion?" ) ).confirm { result => if (result.isSome() && result.getOrThrow()) { deleteItem() currentModal = 0 } else { currentModal = 1 // Back to details } } } } } ``` -------------------------------- ### Left-Aligned Message Dialog Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-dialog-component.md Demonstrates how to configure a dialog to have left-aligned message text using the `messageAlign` property with `TextAlign.Start`. ```cangjie let leftAlignedDialog = SilkDialogOptions( title: "Left Aligned", message: "This message is left-aligned", messageAlign: TextAlign.Start // Use TextAlign enum ) ``` -------------------------------- ### Basic SilkDialog Usage Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-dialog-component.md Demonstrates how to use the SilkDialog component in a HarmonyOS application. It shows how to control dialog visibility and handle user confirmation or cancellation. ```cangjie import silkui.components.dialog.SilkDialog import silkui.components.dialog.SilkDialogOptions import silkui.components.dialog.SilkDialogTheme @Component class MyView { @State var showDialog: Bool = false func build() { Column() { Button("Show Dialog").onClick { _ => showDialog = true } SilkDialog( visible: $showDialog, props: SilkDialogOptions( title: "Confirm Action", message: "Are you sure you want to proceed?", theme: SilkDialogTheme.DEFAULT ) ).confirm { result => if (result.isSome() && result.getOrThrow()) { Log.info("User confirmed") } else { Log.info("User cancelled") } showDialog = false }.cancel { => showDialog = false } } } } ``` -------------------------------- ### Dialog Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/INDEX.md Illustrates the creation and interaction of a confirmation dialog. The dialog's visibility is controlled by a state variable, and the confirmation action is handled by handleConfirm. ```cangjie @State var showDialog: Bool = false SilkDialog( visible: $showDialog, props: SilkDialogOptions( title: "Confirm", message: "Continue?" ) ).confirm { result => handleConfirm() } ``` -------------------------------- ### Tooltip Popup Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-popup-component.md Creates a small, non-dismissible tooltip popup positioned at the top. It features a dark background and minimal content. ```cangjie @State var showTooltip: Bool = false SilkPopup( show: $showTooltip, props: SilkPopupOptions( position: SilkPopupPosition.TOP, showBackdrop: false, // Transparent width: 200.vp, height: 60.vp ) ).Children({ Row() { Text("Help Text").fontSize(12).fontColor(Color.white) } .backgroundColor(Color(0, 0, 0, alpha: 0.8)) .padding(8) }) ``` -------------------------------- ### CJPM TOML Configuration for Script Dependencies Source: https://github.com/piagari/deveco_cangjie/blob/main/cjpm相关知识/cjpm_manual.md Example `cjpm.toml` configuration showing how to declare a script dependency on the `aoo` module, specifying its path. ```toml [script-dependencies] aoo = { path = "./aoo" } ``` -------------------------------- ### Package Manifest Configuration for SilkUI Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-import-guide.md Example of configuring the 'silkui' dependency in a project's 'oh-package.json5' file, specifying a version constraint. ```json5 { "type": "module", "name": "my-app", "version": "1.0.0", "dependencies": { "silkui": ">=1.0.0" } } ``` -------------------------------- ### Left and Right Popup Configurations Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-popup-component.md Demonstrates the configuration for side-aligned popups. These examples set the position property to LEFT and RIGHT respectively. ```cangjie // Left-aligned popup let leftPopupOptions = SilkPopupOptions( position: SilkPopupPosition.LEFT ) // Right-aligned popup let rightPopupOptions = SilkPopupOptions( position: SilkPopupPosition.RIGHT ) ``` -------------------------------- ### MySQL Info API Example Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/News/NewsServer/mysqlclient-ffi/doc/feature_api.md Demonstrates retrieving various information from a MySQL connection using MysqlInfoApi, including error numbers, error messages, SQLSTATE, warning counts, and debug information. ```cangjie import mysqlclient_ffi.* import std.unittest.* import std.unittest.testmacro.* main():Int64{ // 初始化数据库驱动 let mysqlDriver: MysqlDriver = MysqlDriver("mysql") // 通过connectionString和选项打开数据源 let mysqlDatasource: MysqlDatasource = mysqlDriver.open( "HOST=127.0.0.1;USER=root;PASSWD=123;DB=mysql;PORT=3306;UNIX_SOCKET=;CLIENT_FLAG=0", Array<(String, String)>() ) // 返回一个可用的链接 let mysqlConnection: MysqlConnection = mysqlDatasource.connect() let mysqlInfoApi: MysqlInfoApi = MysqlInfoApi(mysqlConnection) let retErrno: UInt32 = mysqlInfoApi.mysqlErrno() @Assert(0, retErrno) let strError: String = mysqlInfoApi.mysqlError() @Assert("", strError) let strState: String = mysqlInfoApi.mysqlSqlstate() @Assert("00000", strState) let retCount: UInt32 = mysqlInfoApi.mysqlWarningCount() @Assert(0, retCount) let strInfo: String = mysqlInfoApi.mysqlInfo() @Assert("", strInfo) let retInfo: Int32 = mysqlInfoApi.mysqlDumpDebugInfo() @Assert(0, retInfo) mysqlConnection.close() } ``` -------------------------------- ### SilkButton Usage Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-button-component.md Demonstrates how to use the SilkButton component with specific text, type, and size. Includes a click event handler to log messages. ```cangjie import silkui.components.button.SilkButton import silkui.components.button.SilkButtonOptions import silkui.components.button.SilkButtonType import silkui.components.button.SilkButtonSize @Component class MyView { func build() { SilkButton( props: SilkButtonOptions( text: "Click Me", buttonType: SilkButtonType.PRIMARY, size: SilkButtonSize.NORMAL ) ).click { e => Log.info("Button clicked") } } } ``` -------------------------------- ### Custom Color Button Configuration Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-types.md Example of creating a button with custom background and text colors. Use this when the default theme colors are not suitable. ```cangjie let customColorButtonProps = SilkButtonOptions( text: "Custom", color: Color(255, 100, 0, alpha: 1.0), textColor: Color(255, 255, 255, alpha: 1.0) ) ``` -------------------------------- ### Dialog + Button Setup Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-import-guide.md Imports modules for integrating SilkUI dialogs and buttons, including base, component, state management, and specific SilkUI button and dialog components. ```cangjie import ohos.base.* import ohos.component.* import ohos.state_manage.* import ohos.state_macro_manage.* import silkui.components.button.SilkButton import silkui.components.button.SilkButtonOptions import silkui.components.button.SilkButtonType import silkui.components.dialog.SilkDialog import silkui.components.dialog.SilkDialogOptions import silkui.components.dialog.SilkDialogTheme ``` -------------------------------- ### Loading Indicator Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/INDEX.md Shows how to display a circular loading indicator with custom size, text, and color. This component is useful for indicating ongoing background processes. ```cangjie SilkLoading( loadingType: SilkLoadingType.CIRCULAR, size: 30.vp, text: "Loading…", color: Color(0x3366FF) ) ``` -------------------------------- ### Icon Button Configuration Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-types.md Example of configuring a button with an icon. Specify the icon name, its prefix (font family), and its position relative to the text. ```cangjie let iconButtonProps = SilkButtonOptions( text: "Download", icon: "download", iconPrefix: "silk-icon", iconPosition: SilkButtonIconPosition.LEFT ) ``` -------------------------------- ### Declare ArkTS Callable Function in Cangjie Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/19-CangjiexArkTS/AudioToText/README.md In Cangjie, use the `@Interop[ArkTS]` annotation to declare functions that will be implemented in ArkTS. This example shows how to register a callback function for starting recording. ```cangjie @Interop[ArkTS] public func startRecording(fn: ((AudioFileInfo, Int8) -> Unit) -> Unit ): Unit { AudioCallBackFunc = fn } public func AudioWithStartRecording(callback: AudioFunc) { if (let Some(fn) <- AudioCallBackFunc) { fn(callback) } else { () } } ``` -------------------------------- ### Calendar + Popup Setup Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-import-guide.md Imports modules for SilkUI calendar and popup components, including base, component, state management, time, collections, and specific SilkUI calendar and popup components. ```cangjie import ohos.base.* import ohos.component.* import ohos.state_manage.* import ohos.state_macro_manage.* import std.time.DateTime import std.collection.ArrayList import silkui.components.calendar.SilkCalendar import silkui.components.calendar.SilkCalendarOptions import silkui.components.calendar.SilkCalendarType import silkui.components.calendar.SilkCalendarMode import silkui.components.calendar.SilkCalendarPosition import silkui.components.popup.SilkPopup import silkui.components.popup.SilkPopupOptions import silkui.components.popup.SilkPopupPosition ``` -------------------------------- ### MySQL Thread API Example Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/News/NewsServer/mysqlclient-ffi/doc/feature_api.md Demonstrates the usage of the MysqlthreadApi for managing database threads, including getting the current thread ID, initializing a new thread, and ending a thread. This snippet requires a running MySQL server and a database named 'mysql'. ```cangjie import mysqlclient_ffi.* import std.unittest.* import std.unittest.testmacro.* main():Int64{ // 初始化数据库驱动 let mysqlDriver: MysqlDriver = MysqlDriver("mysql") // 通过connectionString和选项打开数据源 let mysqlDatasource: MysqlDatasource = mysqlDriver.open( "HOST=127.0.0.1;USER=root;PASSWD=123;DB=mysql;PORT=3306;UNIX_SOCKET=;CLIENT_FLAG=0", Array<(String, String)>() ) // 返回一个可用的链接 let mysqlConnection: MysqlConnection = mysqlDatasource.connect() let mysqlthreadApi: MysqlthreadApi = MysqlthreadApi(mysqlConnection) let ret1 = mysqlthreadApi.mysqlThreadId() mysqlthreadApi.mysqlThreadEnd() let retBool = mysqlthreadApi.mysqlThreadInit() let ret2 = mysqlthreadApi.mysqlThreadId() @Assert(ret1, ret2) @Assert(false, retBool) mysqlConnection.close() } ``` -------------------------------- ### List MySQL Databases using MysqlListApi Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/News/NewsServer/mysqlclient-ffi/doc/feature_api.md Demonstrates how to list databases in MySQL using the MysqlListApi. It initializes the driver, opens a datasource, connects, and then fetches and asserts database information. ```cangjie import mysqlclient_ffi.* import std.unittest.* import std.unittest.testmacro.* main():Int64{ // 初始化数据库驱动 let mysqlDriver: MysqlDriver = MysqlDriver("mysql") // 通过connectionString和选项打开数据源 let mysqlDatasource: MysqlDatasource = mysqlDriver.open( "HOST=127.0.0.1;USER=root;PASSWD=123;DB=mysql;PORT=3306;UNIX_SOCKET=;CLIENT_FLAG=0", Array<(String, String)>() ) // 返回一个可用的链接 let mysqlConnection: MysqlConnection = mysqlDatasource.connect() let mysqlListApi: MysqlListApi = MysqlListApi(mysqlConnection) let mysqlRecordApi: MysqlRecordApi = MysqlRecordApi(mysqlConnection) let cp1: CPointer = mysqlListApi.mysqlListDbs("information_schema") let retFields: UInt32 = mysqlRecordApi.mysqlNumFields(cp1) @Assert(1, retFields) let retEof: Bool = mysqlRecordApi.mysqlEof(cp1) @Assert(true, retEof) let retRows: UInt64 = mysqlRecordApi.mysqlNumRows(cp1) @Assert(1, retRows) unsafe { for (i in 0..retRows) { var cpCString: CPointer = mysqlRecordApi.mysqlFetchRow(cp1) for (j in 0..retFields) { var cString: CString = cpCString.read(Int64(j)) if (i == 0) { @Assert("information_schema", cString.toString()) } } } } mysqlRecordApi.mysqlFreeResult(cp1) mysqlConnection.close() } ``` -------------------------------- ### Initialize a static library module Source: https://github.com/piagari/deveco_cangjie/blob/main/cjpm相关知识/cjpm_manual.md Create a new module, such as 'pro0', and initialize it as a static library. This involves creating a 'pro0' directory, initializing it with 'cjpm init --name pro0 --type=static', and setting up the source directory structure. ```shell mkdir pro0 && cd pro0 cjpm init --name pro0 --type=static mkdir src/zoo ``` -------------------------------- ### Full Application Setup Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-import-guide.md Comprehensive imports for a full application using SilkUI, covering base, component, state management, resource management, time, collections, and all major SilkUI component packages and utilities. ```cangjie import ohos.base.* import ohos.component.* import ohos.state_manage.* import ohos.state_macro_manage.* import ohos.resource_manager.* import std.time.DateTime import std.collection.ArrayList // SilkUI Components import silkui.components.button.* import silkui.components.dialog.* import silkui.components.calendar.* import silkui.components.popup.* import silkui.components.loading.* import silkui.components.toast.* import silkui.components.icon.SilkIcon // SilkUI Types and Utilities import silkui.ResourceStr import silkui.ResourceColor import silkui.utils.ResourceStrToString import silkui.utils.ResourceColorToColor import silkui.constants.getColorConstant import silkui.constants.getSizeConstant ``` -------------------------------- ### Build Documentation Website for Production Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/Silkui/CLAUDE.md Builds the Vue.js documentation website for production deployment. Run this command in the docs-vue directory. ```bash cd docs-vue npm run build ``` -------------------------------- ### Basic SilkPopup Usage Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-popup-component.md Demonstrates how to use the SilkPopup component in a view. It includes a button to toggle the popup's visibility and configures the popup to appear at the bottom with a close button. ```cangjie import silkui.components.popup.SilkPopup import silkui.components.popup.SilkPopupOptions import silkui.components.popup.SilkPopupPosition @Component class MyView { @State var showPopup: Bool = false func build() { Column() { Button("Show Popup").onClick { _ => showPopup = true } SilkPopup( show: showPopup, props: SilkPopupOptions( position: SilkPopupPosition.BOTTOM, showClose: true ) ).Children({ Column() { Text("Popup Content") Button("Close").onClick { _ => showPopup = false } }.padding(20) }) } } } ``` -------------------------------- ### CJPM Build Command Help Source: https://github.com/piagari/deveco_cangjie/blob/main/cjpm相关知识/cjpm_manual.md Shows detailed help for the 'cjpm build' command, including options for incremental compilation, parallel jobs, verbose output, and more. Use this to understand how to customize the build process. ```text Compile a local module and all of its dependencies. Usage: cjpm build [option] Available options: -h, --help help for build -i, --incremental enable incremental compilation -j, --jobs the number of jobs to spawn in parallel during the build process -V, --verbose enable verbose -g enable compile debug version target --cfg enable the customized option 'cfg' -m, --member specify a member module of the workspace --target generate code for the given target platform --target-dir specify target directory -o, --output specify product name when compiling an executable file --mock enable support of mocking classes in tests --skip-script disable script 'build.cj'. ``` -------------------------------- ### Large SilkLoading Indicator Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-loading-component.md Example of a large-sized circular loading indicator. ```cangjie SilkLoading( loadingType: SilkLoadingType.CIRCULAR, size: 40.vp ) ``` -------------------------------- ### Medium SilkLoading Indicator Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-loading-component.md Example of a medium-sized circular loading indicator. ```cangjie SilkLoading( loadingType: SilkLoadingType.CIRCULAR, size: 24.vp ) ``` -------------------------------- ### Small SilkLoading Indicator Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-loading-component.md Example of a small-sized circular loading indicator. ```cangjie SilkLoading( loadingType: SilkLoadingType.CIRCULAR, size: 16.vp ) ``` -------------------------------- ### Import Only What You Need Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-import-guide.md Illustrates the best practice of importing only specific components rather than entire packages, improving build times and reducing potential conflicts. ```cangjie // Good - specific imports import silkui.components.button.SilkButton import silkui.components.button.SilkButtonOptions // Avoid - importing entire package if only using one component import silkui.components.button.* ``` -------------------------------- ### Multi-Column Picker Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/Silkui/libs/silkui/src/main/cangjie/src/components/picker/README.md Example of a multi-column Picker, allowing selection from parallel columns. ```cangjie let columns = [ SilkPickerColumn([ SilkPickerOption(text: "周一", value: "Monday"), SilkPickerOption(text: "周二", value: "Tuesday"), SilkPickerOption(text: "周三", value: "Wednesday") ]), SilkPickerColumn([ SilkPickerOption(text: "上午", value: "Morning"), SilkPickerOption(text: "下午", value: "Afternoon"), SilkPickerOption(text: "晚上", value: "Evening") ]) ] SilkPicker( columns: ObservedArrayList(columns), options: SilkPickerOptions(title: "选择时间") ) ``` -------------------------------- ### Importing SilkUI Components Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt Demonstrates how to import various SilkUI components and utilities. Ensure these imports are present for component usage. ```CangjieScript import { SilkButton, SilkButtonType, SilkButtonSize, SilkButtonIconPosition, SilkDialog, SilkDialogTheme, SilkDialogMessageAlign, SilkCalendar, SilkCalendarType, SilkCalendarMode, SilkPopup, SilkPopupPosition, SilkLoading, SilkLoadingType, SilkButtonOptions, SilkDialogOptions, SilkCalendarOptions, SilkPopupOptions, SilkUILinearGradientOptions, SilkUIBorderOptions, SilkUIPaddingOptions, ResourceStr, ResourceColor, ResourceBorder, ResourcePadding } from '@silkui/components'; import { State, Link, Observe, EventCallback } from '@silkui/state-management'; import { // ... other utility imports } from '@silkui/utils'; ``` -------------------------------- ### Initialize and End MySQL Server with MysqlServerApi Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/News/NewsServer/mysqlclient-ffi/doc/feature_api.md Demonstrates initializing and ending the MySQL server using MysqlServerApi. It includes setting up arguments and groups, and performing refresh and kill operations. ```cangjie import mysqlclient_ffi.* import std.unittest.* import std.unittest.testmacro.* main():Int64{ // 初始化数据库驱动 let mysqlDriver: MysqlDriver = MysqlDriver("mysql") // 通过connectionString和选项打开数据源 let mysqlDatasource: MysqlDatasource = mysqlDriver.open( "HOST=127.0.0.1;USER=root;PASSWD=123;DB=mysql;PORT=3306;UNIX_SOCKET=;CLIENT_FLAG=0", Array<(String, String)>() ) // 返回一个可用的链接 let mysqlConnection: MysqlConnection = mysqlDatasource.connect() let mysqlServerApi: MysqlServerApi = MysqlServerApi(mysqlConnection) var cpCtringArgv: CPointer = CPointer() var cpCtringGroups: CPointer = CPointer() var ret: Int32 = mysqlServerApi.mysqlServerInit(10, cpCtringArgv, cpCtringGroups) @Assert(0, ret) mysqlServerApi.mysqlServerEnd() ret = mysqlServerApi.mysqlRefresh(0) @Assert(0, ret) ret = mysqlServerApi.mysqlKill(0) @Assert(1, ret) mysqlConnection.close() } ``` -------------------------------- ### CJPM Command Extension Equivalent Execution Source: https://github.com/piagari/deveco_cangjie/blob/main/cjpm相关知识/cjpm_manual.md Illustrates the direct execution of the 'cjpm-demo' executable, which is equivalent to running 'cjpm demo' when the executable is properly configured in the PATH. ```shell cjpm-xxx(.exe) [args] ``` -------------------------------- ### Preview Production Build of Documentation Website Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/Silkui/CLAUDE.md Previews the production build of the Vue.js documentation website. Run this command in the docs-vue directory. ```bash cd docs-vue npm run preview ``` -------------------------------- ### Circular Loading Indicator Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-loading-component.md Shows a circular loading indicator with specified size, text, and color. ```cangjie SilkLoading( loadingType: SilkLoadingType.CIRCULAR, size: 30.vp, text: "Processing...", color: Color(0x3366FF) ) ``` -------------------------------- ### Picker Two-Way Binding Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/Silkui/libs/silkui/src/main/cangjie/src/components/picker/README.md Example of using two-way binding with the Picker component to manage selected values. ```cangjie @State var selectedValues: ObservedArrayList = ObservedArrayList([]) SilkPickerLink( values: selectedValues, columns: ObservedArrayList(columns), options: SilkPickerOptions() ) ``` -------------------------------- ### Execute MySQL Query using MysqlRecordApi Source: https://github.com/piagari/deveco_cangjie/blob/main/HarmonyOS-Examples-main/HarmonyOS-Examples-main/News/NewsServer/mysqlclient-ffi/doc/feature_api.md Shows how to execute a simple query using MysqlRecordApi. It initializes the driver, opens a datasource, connects, and then performs a query, asserting the return value. ```cangjie import mysqlclient_ffi.* import std.unittest.* import std.unittest.testmacro.* main():Int64{ // 初始化数据库驱动 let mysqlDriver: MysqlDriver = MysqlDriver("mysql") // 通过connectionString和选项打开数据源 let mysqlDatasource: MysqlDatasource = mysqlDriver.open( "HOST=127.0.0.1;USER=root;PASSWD=123;DB=mysql;PORT=3306;UNIX_SOCKET=;CLIENT_FLAG=0", Array<(String, String)>() ) // 返回一个可用的链接 let mysqlConnection: MysqlConnection = mysqlDatasource.connect() let mysqlRecordApi: MysqlRecordApi = MysqlRecordApi(mysqlConnection) let retInt32: Int32 = mysqlRecordApi.mysqlQuery("") @Assert(1, retInt32) // 关闭链接 mysqlConnection.close() } ``` -------------------------------- ### Custom Title Dialog Example Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-dialog-component.md Shows how to create a dialog with a custom title, including icons and styled text. ```APIDOC ## Custom Title Dialog ### Description An example illustrating how to replace the default dialog title with custom content, such as a `Row` containing an icon and styled text. ### Usage ```cangjie SilkDialog( visible: $showDialog, props: SilkDialogOptions( message: "Enter your preference below" ) ).Title({ // Custom title with icon Row() { SilkIcon(name: "info", fontSize: 20.vp) Text("Settings").fontSize(18).fontWeight(FontWeight.Bold) }.padding(16) }) ``` ``` -------------------------------- ### ROUND_BUTTON Theme Configuration Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-dialog-component.md Example of configuring a SilkDialog with the ROUND_BUTTON theme, which features rounded-corner buttons with a gradient effect. ```cangjie let roundButtonDialog = SilkDialogOptions( title: "Important Notice", message: "This is a round button dialog", theme: SilkDialogTheme.ROUND_BUTTON ) ``` -------------------------------- ### Initialize a new Cangjie project Source: https://github.com/piagari/deveco_cangjie/blob/main/cjpm相关知识/cjpm_manual.md Use 'cjpm init' to create a new Cangjie project with a specified name and path. This command generates the 'src' directory and a default 'cjpm.toml' configuration file. ```shell cjpm init --name test --path .../cj_project mkdir koo ``` -------------------------------- ### CangjieScript Component Type Definitions Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-architecture-guide.md Example of defining enums and structs for component configuration and options using CangjieScript. ```cangjie public enum ComponentType { | PRIMARY | SECONDARY | DEFAULT } public struct ComponentOptions { public let type: ComponentType public let size: Length public let color: ResourceColor // ... more fields public init(...) { ... } } ``` -------------------------------- ### Top Popup Configuration Source: https://github.com/piagari/deveco_cangjie/blob/main/_autodocs/silkui-popup-component.md Configures a SilkPopup to be positioned at the top of the screen. This example shows how to set the position property. ```cangjie let topPopupOptions = SilkPopupOptions( position: SilkPopupPosition.TOP ) SilkPopup( show: $showPopup, props: topPopupOptions ).Children({ Column() { Text("Top Popup Content").padding(16) } }) ```