From 2dd8d8d256625e1ca67bac07ec9b4b7b94443512 Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko <2277098+anoshenko@users.noreply.github.com> Date: Tue, 24 Jun 2025 19:31:38 +0300 Subject: [PATCH] Updated readme --- CHANGELOG.md | 2 +- README-ru.md | 64 +++++++++++++++++++++++++++++++++++++++++++++ README.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 134 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 000ac9b..91903e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ # v0.18.2 -* fixed typo: GetShadowPropertys -> GetShadowProperty +* fixed typo: GetShadowProperties -> GetShadowProperty # v0.18.0 diff --git a/README-ru.md b/README-ru.md index 13a7518..7b37861 100644 --- a/README-ru.md +++ b/README-ru.md @@ -5704,6 +5704,70 @@ Safari и Firefox. Для получения объекта используется метод Object. Для получения элементов массива используются методы ArraySize, ArrayElement и ArrayElements +## Связывание (binding) + +Механизм связывания предназначен для задания обработчиков событий и слушателей изменений в ресурсах приложений. + +Рассмотрим пример: + +Файл ресурсов описывающий кнопку button.rui + + Button { + click-event = ButtonClick, + } + +Код для создания этой кнопки из ресурсов + + type button struct { + view rui.View + } + + func createButton(session rui.Session) rui.View { + b := new(button) + b.view = rui.CreateViewFromResources(session, "button.rui", b) + return b.view + } + + func (button *button) ButtonClick() { + rui.DebugLog("Button clicked") + } + +В данном примере в файле ресурсов указано, что в качестве обработчика клика надо использовать функцию с именем "ButtonClick". +При создании View из ресeрсов с помощью функции CreateViewFromResources в качестве третьего параметра задается объект связывания. +При возникновении события "click-event" система будет искать в связанном объекте один из следующих методов + + ButtonClick() + ButtonClick(rui.View) + ButtonClick(rui.MouseEvent) + ButtonClick(rui.View, rui.MouseEvent) + +Система найдет метод ButtonClick() и вызовет его. + +Теперь рассотрим как добавить отслеживание изменения свойств. +Для этого добавим в пример слушателя изменения свойства "background-color" в свойство "change-listeners" + + Button { + click-event = ButtonClick, + change-listeners = { + background-color = BackgroundColorChanged, + }, + } + +И добавим соответствующий метод + + func (button *button) BackgroundColorChanged() { + rui.DebugLog("Background color changed") + } + +Данный метод может иметь одно из следующих описаний + + BackgroundColorChanged() + BackgroundColorChanged(rui.View) + BackgroundColorChanged(rui.PropertyName) + BackgroundColorChanged(rui.View, rui.PropertyName) + +Важное замечание: Все методы вызываемые через связывание должны быть публичными (начинаться с большой буквы) + ## Ресурсы Ресурсы (картинки, темы, переводы и т.д.) с которыми работает приложение должны размещаться по diff --git a/README.md b/README.md index 95b59e6..02fa351 100644 --- a/README.md +++ b/README.md @@ -520,7 +520,7 @@ For the "edit-text-changed" event, this * func(newText string) * []func(editor EditView, newText string) * []func(newText string) -* []any содержащий только func(editor EditView, newText string) и func(newText string) +* []any containing only func(editor EditView, newText string) и func(newText string) And the "edit-text-changed" property always stores and returns []func(EditView, string). @@ -1062,7 +1062,7 @@ The ShadowProperty text representation has the following format: You can get the value of "shadow" property using the function - func GetShadowPropertys(view View, subviewID ...string) []ShadowProperty + func GetShadowProperties(view View, subviewID ...string) []ShadowProperty If no shadow is specified, then this function will return an empty array @@ -5720,6 +5720,71 @@ using the SetResourcePath function before creating the Application: app.Start("localhost:8000") } +## Binding + +The binding mechanism is designed to set event handlers and listeners for changes in application resources. + +Let's look at an example: + +Resource file ("button.rui") describing the button + + Button { + click-event = ButtonClick, + } + +Code to create this button from resources + + type button struct { + view rui.View + } + + func createButton(session rui.Session) rui.View { + b := new(button) + b.view = rui.CreateViewFromResources(session, "button.rui", b) + return b.view + } + + func (button *button) ButtonClick() { + rui.DebugLog("Button clicked") + } + +In this example, the resource file specifies that a function named "ButtonClick" should be used as the click handler. +When creating a View from resources using the CreateViewFromResources function, the binding object is specified as the third parameter. +When a "click-event" occurs, the system will look for one of the following methods in the binding object + + ButtonClick() + ButtonClick(rui.View) + ButtonClick(rui.MouseEvent) + ButtonClick(rui.View, rui.MouseEvent) + +The system will find the ButtonClick() method and call it. + +Now let's look at how to add property change tracking. + +To do this, let's add a property change listener "background-color" to the property "change-listeners" in the example. + + Button { + click-event = ButtonClick, + change-listeners = { + background-color = BackgroundColorChanged, + }, + } + +And we will add the corresponding method + + func (button *button) BackgroundColorChanged() { + rui.DebugLog("Background color changed") + } + +This method can have one of the following descriptions + + BackgroundColorChanged() + BackgroundColorChanged(rui.View) + BackgroundColorChanged(rui.PropertyName) + BackgroundColorChanged(rui.View, rui.PropertyName) + +Important note: All methods called via binding must be public (start with a capital letter) + ## Images for screens with different pixel densities If you need to add separate images to the resources for screens with different pixel densities, @@ -5919,7 +5984,7 @@ The library defines a number of constants and styles. You can override them in y System styles that you can override: -| Style name | Описание | +| Style name | Description | |---------------------|---------------------------------------------------------------------| | ruiApp | This style is used to set the default text style (font, size, etc.) | | ruiView | Default View Style | @@ -6011,7 +6076,7 @@ Translation files must have the "rui" extension and the following format = , … }, - <язык 2> = _{ + = _{ = , = , …