From deeb7123afd096420ca953c73a2bbd5c08f3ecf9 Mon Sep 17 00:00:00 2001 From: "dongsug.song" Date: Thu, 28 Apr 2022 09:04:51 +0900 Subject: [PATCH] [NUI] Fix FocusIndicator default value --- src/Tizen.NUI/res/keyboard_focus.9.png | Bin 0 -> 3073 bytes .../src/internal/Application/Application.cs | 1 + .../src/public/Input/FocusManager.cs | 60 ++++++++- .../Examples/DialogAndAlertDialogExample.cs | 14 +-- .../Examples/FocusIndicatorTest.cs | 119 ++++++++++++++++++ .../Tizen.NUI.StyleGuide.cs | 21 +--- .../Tizen.NUI.StyleGuide.csproj | 1 + 7 files changed, 184 insertions(+), 32 deletions(-) create mode 100644 src/Tizen.NUI/res/keyboard_focus.9.png create mode 100644 test/Tizen.NUI.StyleGuide/Examples/FocusIndicatorTest.cs diff --git a/src/Tizen.NUI/res/keyboard_focus.9.png b/src/Tizen.NUI/res/keyboard_focus.9.png new file mode 100644 index 0000000000000000000000000000000000000000..5590f15316ed351edaa74bc74ee93b26085ea870 GIT binary patch literal 3073 zcmV+c4F2Oz@Z0f2-7z;ux~O9+4z06=<WDR*FRcSTFz- zW=q650N5=6FiBTtNC2?60Km==3$g$R3;-}uh=nNt1bYBr$Ri_o0EC$U6h`t_Jn<{8 z5a%iY0C<_QJh>z}MS)ugEpZ1|S1ukX&Pf+56gFW3VVXcL!g-k)GJ!M?;PcD?0HBc- z5#WRK{dmp}uFlRjj{U%*%WZ25jX z{P*?XzTzZ-GF^d31o+^>%=Ap99M6&ogks$0k4OBs3;+Bb(;~!4V!2o<6ys46agIcq zjPo+3B8fthDa9qy|77CdEc*jK-!%ZRYCZvbku9iQV*~a}ClFY4z~c7+0P?$U!PF=S z1Au6Q;m>#f??3%Vpd|o+W=WE9003S@Bra6Svp>fO002awfhw>;8}z{#EWidF!3EsG z3;bXU&9EIRU@z1_9W=mEXoiz;4lcq~xDGvV5BgyU zp1~-*fe8db$Osc*A=-!mVv1NJjtCc-h4>-CNCXm#Bp}I%6j35eku^v$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QEGA zUct(O!LkCy1<%NCg+}G`0PgpNm-?d@-hMgNe6^V+j6x$b<6@S<$+<4_1hi}Ti zncS4LsjI}fWY1>OX6feMEuLErma3QLmkw?X+1j)X-&VBk_4Y;EFPF_I+q;9dL%E~B zJh;4Nr^(LEJ3myURP{Rblsw%57T)g973R8o)DE9*xN#~;4_o$q%o z4K@u`jhx2fBXC4{U8Qn{*%*B$Ge=nny$HAYq{=vy|sI0 z_vss+H_qMky?OB#|JK!>IX&II^LlUh#rO5!7TtbwC;iULyV-Xq?ybB}ykGP{?LpZ? z-G|jbTmIbG@7#ZCz;~eY(cDM(28Dyq{*m>M4?_iynUBkc4TkHUI6gT!;y-fz>HMcd z&t%Ugo)`Y2{>!cx7B7DI)$7;J(U{Spm-3gBzioV_{p!H$8L!*M!p0uH$#^p{Ui4P` z?ZJ24cOCDe-w#jZd?0@)|7iKK^;6KN`;!@ylm7$*nDhK&GcDTy000JJOGiWi{{a60 z|De66lK=n!32;bRa{vGf6951U69E94oEQKA00(qQO+^Ra3k?nd7^?4SivR!tGf6~2 zR5;7+l}$>-KoEt$3No{pxq&BeH7Z0sgNnFuq3G71EA#P>K0dQ5+`8*Tmr{H4vZVfa^M-rfE(|m z{8J@P!Yc3ttkVu}z`l3#{Y$8wy>uX}@D6NyCq*^##T?lg@aUc7bzjFx7z2mEtu9S~ zb6{E#o>(&PBwf^w7E0qJ1RymW(@0Nq)4YGzV$^#RZvY|EWMHb7%d&YVg-M415k2Fd zus_0bPR~n0FSyk=k;?DYJUD96(1D3R0jZRd0XrI}aS{Z0@J?n8osCp_R#BNXhoPFo zq~q3o09)Qk5t$pmr&iR(X?82sNR7c>0jIzkFlr!~0be@ub*;hn^$Yj`rgm1Sh@5ZG P00000NkvXXu0mjfwdS$k literal 0 HcmV?d00001 diff --git a/src/Tizen.NUI/src/internal/Application/Application.cs b/src/Tizen.NUI/src/internal/Application/Application.cs index b434edbc1..effb0d8aa 100755 --- a/src/Tizen.NUI/src/internal/Application/Application.cs +++ b/src/Tizen.NUI/src/internal/Application/Application.cs @@ -587,6 +587,7 @@ namespace Tizen.NUI // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread. DisposeQueue.Instance.Initialize(); Window.Instance = GetWindow(); + _ = FocusManager.Instance; // Notify that the window is displayed to the app core. if (NUIApplication.IsPreload) diff --git a/src/Tizen.NUI/src/public/Input/FocusManager.cs b/src/Tizen.NUI/src/public/Input/FocusManager.cs index bcd662404..cdfa12cc9 100755 --- a/src/Tizen.NUI/src/public/Input/FocusManager.cs +++ b/src/Tizen.NUI/src/public/Input/FocusManager.cs @@ -73,6 +73,7 @@ namespace Tizen.NUI private delegate void FocusedViewEnterKeyEventCallback2(IntPtr view); private View internalFocusIndicator = null; + private View nullFocusIndicator = null; /// /// PreFocusChange will be triggered before the focus is going to be changed.
@@ -264,11 +265,23 @@ namespace Tizen.NUI { set { - SetFocusIndicatorView(value); + internalFocusIndicator = value; + if (internalFocusIndicator == null) + { + if (nullFocusIndicator == null) + { + nullFocusIndicator = new View(); + } + SetFocusIndicatorView(nullFocusIndicator); + } + else + { + SetFocusIndicatorView(internalFocusIndicator); + } } get { - return GetFocusIndicatorView(); + return internalFocusIndicator; } } @@ -476,10 +489,49 @@ namespace Tizen.NUI if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } + /// + /// Get a default focus indicator + /// + /// + /// The type actually of blue border squred png image, so it would be difficult to modify itself. + /// To change focus indicator, creating new indicator and assigning it to FocusIndicator are recommended. + /// For example, + /// + /// FocusManager.Instance.FocusIndicator = new View() + /// { + /// PositionUsesPivotPoint = true, + /// PivotPoint = new Position(0, 0, 0), + /// WidthResizePolicy = ResizePolicyType.FillToParent, + /// HeightResizePolicy = ResizePolicyType.FillToParent, + /// BorderlineColor = Color.Orange, + /// BorderlineWidth = 4.0f, + /// BorderlineOffset = -1f, + /// BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.2f), + /// }; + /// + /// + /// instance of default focus indicator + [EditorBrowsable(EditorBrowsableState.Never)] + public View GetDefaultFocusIndicator() + { + ImageView ret = new ImageView(FrameworkInformation.ResourcePath + "keyboard_focus.9.png") + { + Name = "DefaultFocusIndicatorCreatedByNUI", + PositionUsesAnchorPoint = true, + ParentOrigin = ParentOrigin.Center, + PivotPoint = ParentOrigin.Center, + Position2D = new Position2D(0, 0), + }; + ret.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions); + return ret; + } + internal static FocusManager Get() { FocusManager ret = new FocusManager(Interop.FocusManager.Get(), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + + ret.FocusIndicator = ret.GetDefaultFocusIndicator(); return ret; } @@ -500,15 +552,13 @@ namespace Tizen.NUI { Interop.FocusManager.SetFocusIndicatorActor(SwigCPtr, View.getCPtr(indicator)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - internalFocusIndicator = indicator; } internal View GetFocusIndicatorView() { //to fix memory leak issue, match the handle count with native side. IntPtr cPtr = Interop.FocusManager.GetFocusIndicatorActor(SwigCPtr); - internalFocusIndicator = this.GetInstanceSafely(cPtr); - return internalFocusIndicator; + return this.GetInstanceSafely(cPtr); } internal PreFocusChangeSignal PreFocusChangeSignal() diff --git a/test/Tizen.NUI.StyleGuide/Examples/DialogAndAlertDialogExample.cs b/test/Tizen.NUI.StyleGuide/Examples/DialogAndAlertDialogExample.cs index 7be53af8f..6f00a9a83 100644 --- a/test/Tizen.NUI.StyleGuide/Examples/DialogAndAlertDialogExample.cs +++ b/test/Tizen.NUI.StyleGuide/Examples/DialogAndAlertDialogExample.cs @@ -78,7 +78,7 @@ namespace Tizen.NUI.StyleGuide Text = "OK", }; - button.Clicked += (object s, ClickedEventArgs a) => + button.Clicked += (object sender, ClickedEventArgs args) => { Navigator?.Pop(); }; @@ -101,7 +101,7 @@ namespace Tizen.NUI.StyleGuide Text = "Cancel", }; - button.Clicked += (object s, ClickedEventArgs a) => + button.Clicked += (object sender, ClickedEventArgs args) => { Navigator?.Pop(); }; @@ -111,7 +111,7 @@ namespace Tizen.NUI.StyleGuide Text = "OK", }; - button2.Clicked += (object s, ClickedEventArgs a) => + button2.Clicked += (object sender, ClickedEventArgs args) => { Navigator?.Pop(); }; @@ -134,7 +134,7 @@ namespace Tizen.NUI.StyleGuide Text = "Cancel", }; - button.Clicked += (object s, ClickedEventArgs a) => + button.Clicked += (object sender, ClickedEventArgs args) => { Navigator?.Pop(); }; @@ -144,7 +144,7 @@ namespace Tizen.NUI.StyleGuide Text = "OK", }; - button2.Clicked += (object s, ClickedEventArgs a) => + button2.Clicked += (object sender, ClickedEventArgs args) => { Navigator?.Pop(); }; @@ -167,7 +167,7 @@ namespace Tizen.NUI.StyleGuide Text = "Cancel", }; - button.Clicked += (object s, ClickedEventArgs a) => + button.Clicked += (object sender, ClickedEventArgs args) => { Navigator?.Pop(); }; @@ -177,7 +177,7 @@ namespace Tizen.NUI.StyleGuide Text = "OK", }; - button2.Clicked += (object s, ClickedEventArgs a) => + button2.Clicked += (object sender, ClickedEventArgs args) => { Navigator?.Pop(); }; diff --git a/test/Tizen.NUI.StyleGuide/Examples/FocusIndicatorTest.cs b/test/Tizen.NUI.StyleGuide/Examples/FocusIndicatorTest.cs new file mode 100644 index 000000000..34ce3aff6 --- /dev/null +++ b/test/Tizen.NUI.StyleGuide/Examples/FocusIndicatorTest.cs @@ -0,0 +1,119 @@ +/* + * Copyright(c) 2022 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +using System; +using System.ComponentModel; +using Tizen.NUI; +using Tizen.NUI.BaseComponents; +using Tizen.NUI.Components; + +namespace Tizen.NUI.StyleGuide +{ + // IExample inehrited class will be automatically added in the main examples list. + internal class FocusIndicatorTest : ContentPage, IExample + { + private View rootContent; + private Button buttonSetNewIndi, buttonRestoreIndi, buttonSetNull; + private FocusManager focusmanager; + + + public void Activate() + { + } + public void Deactivate() + { + } + + /// Modify this method for adding other examples. + public FocusIndicatorTest() : base() + { + focusmanager = FocusManager.Instance; + + WidthSpecification = LayoutParamPolicies.MatchParent; + HeightSpecification = LayoutParamPolicies.MatchParent; + + // Navigator bar title is added here. + AppBar = new AppBar() + { + Title = "Focus Indicator Test", + }; + + // Example root content view. + // you can decorate, add children on this view. + rootContent = new View() + { + WidthSpecification = LayoutParamPolicies.MatchParent, + HeightSpecification = LayoutParamPolicies.MatchParent, + + Layout = new LinearLayout() + { + LinearOrientation = LinearLayout.Orientation.Vertical, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + CellPadding = new Size2D(10, 20), + }, + }; + + buttonSetNewIndi = new Button + { + WidthSpecification = LayoutParamPolicies.MatchParent, + Text = "Set New Focus Indicator", + }; + rootContent.Add(buttonSetNewIndi); + + buttonSetNewIndi.Clicked += (s, e) => + { + focusmanager.FocusIndicator = new View() + { + PositionUsesPivotPoint = true, + PivotPoint = new Position(0, 0, 0), + WidthResizePolicy = ResizePolicyType.FillToParent, + HeightResizePolicy = ResizePolicyType.FillToParent, + BorderlineColor = Color.Orange, + BorderlineWidth = 4.0f, + BorderlineOffset = -1f, + BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.2f), + }; + }; + + buttonSetNull = new Button + { + WidthSpecification = LayoutParamPolicies.MatchParent, + Text = "Set null Focus Indicator", + }; + rootContent.Add(buttonSetNull); + + buttonSetNull.Clicked += (s, e) => + { + focusmanager.FocusIndicator = null; + }; + + buttonRestoreIndi = new Button + { + WidthSpecification = LayoutParamPolicies.MatchParent, + Text = "Restore default Focus Indicator", + }; + rootContent.Add(buttonRestoreIndi); + + buttonRestoreIndi.Clicked += (s, e) => + { + focusmanager.FocusIndicator = focusmanager.GetDefaultFocusIndicator(); + }; + + Content = rootContent; + } + } +} diff --git a/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs b/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs index def75a425..c52082700 100644 --- a/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs +++ b/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs @@ -174,7 +174,6 @@ namespace Tizen.NUI.StyleGuide private ContentPage page; private SearchField field; private List testSource; - private FocusManager focusManager; public void OnKeyEvent(object sender, Window.KeyEventArgs e) { @@ -216,26 +215,8 @@ namespace Tizen.NUI.StyleGuide Initialize(); SetMainPage(); - focusManager = FocusManager.Instance; - - //set user customized focus indicator - if (!focusManager.FocusIndicator) - { - focusManager.FocusIndicator = new View() - { - PositionUsesPivotPoint = true, - PivotPoint = new Position(0, 0, 0), - WidthResizePolicy = ResizePolicyType.FillToParent, - HeightResizePolicy = ResizePolicyType.FillToParent, - BorderlineColor = Color.Orange, - BorderlineWidth = 4.0f, - BorderlineOffset = -1f, - BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.2f), - }; - } - //enable FocusManger default algorithm - focusManager.EnableDefaultAlgorithm(true); + FocusManager.Instance.EnableDefaultAlgorithm(true); } private void Initialize() { diff --git a/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.csproj b/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.csproj index 1aab6362e..c9187b0e7 100755 --- a/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.csproj +++ b/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.csproj @@ -20,6 +20,7 @@ + -- 2.34.1