Recent

Author Topic: [SOLVED] How to rotate a Module ?  (Read 3440 times)

tintinux

  • Sr. Member
  • ****
  • Posts: 325
    • Gestinux
[SOLVED] How to rotate a Module ?
« on: June 16, 2016, 02:36:02 pm »
Hi

In the attached example, made with LAMW, the main panel (in blue) should contain a square as large as possible.
To achieve this I would like to have the 2 buttons in the bottom when the orientation is Portrait, and on the right side when it is Landscape.

I tried to change the relative position of the buttons when the orientation is changed.
Unfortunately, in Landscape orientation, the second button position is not changed and it always remains hidden by the first button.
I have tried various things like UpdateLayout and ResetAllRules, without result.
I'm certainly missing something, but I do not find what...
 
Can you help me ?
Thanks !
« Last Edit: June 21, 2016, 05:13:40 pm by tintinux »
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: How to rotate a Module ?
« Reply #1 on: June 17, 2016, 10:32:37 am »
Hello tintinux!

Here is a possible solution:

"unit1.lfm"
Code: Pascal  [Select][+][-]
  1. object AndroidModule1: TAndroidModule1
  2.   Left = 268
  3.   Top = 152
  4.   Width = 320
  5.   Height = 523
  6.   MarginLeft = 0
  7.   MarginTop = 0
  8.   MarginRight = 0
  9.   MarginBottom = 0
  10.   Text = 'AndroidModule1'
  11.   ActivityMode = actMain
  12.   BackgroundColor = colbrDefault
  13.   ActionBarTitle = abtDefault
  14.   OnRotate = AndroidModule1Rotate
  15.   object jPanel1: jPanel
  16.     Left = 4
  17.     Top = 4
  18.     Width = 308
  19.     Height = 404
  20.     MarginLeft = 4
  21.     MarginTop = 4
  22.     MarginRight = 4
  23.     MarginBottom = 4
  24.     Visible = True
  25.     PosRelativeToAnchor = []
  26.     PosRelativeToParent = [rpTop]
  27.     LayoutParamWidth = lpMatchParent
  28.     LayoutParamHeight = lpFourFifthOfParent
  29.     BackgroundColor = colbrSkyBlue
  30.     MinPinchZoomFactor = 0.25
  31.     MaxPinchZoomFactor = 4
  32.     Id = 5954533
  33.   end
  34.   object jPanel2: jPanel
  35.     Left = 4
  36.     Top = 416
  37.     Width = 308
  38.     Height = 90
  39.     MarginLeft = 4
  40.     MarginTop = 4
  41.     MarginRight = 4
  42.     MarginBottom = 4
  43.     Visible = True
  44.     Anchor = jPanel1
  45.     PosRelativeToAnchor = [raBelow]
  46.     PosRelativeToParent = []
  47.     LayoutParamWidth = lpMatchParent
  48.     LayoutParamHeight = lpOneFifthOfParent
  49.     BackgroundColor = colbrLightGreen
  50.     MinPinchZoomFactor = 0.25
  51.     MaxPinchZoomFactor = 4
  52.     Id = 0
  53.     object jPanel3: jPanel
  54.       Left = 4
  55.       Top = 4
  56.       Width = 140
  57.       Height = 48
  58.       MarginLeft = 4
  59.       MarginTop = 4
  60.       MarginRight = 4
  61.       MarginBottom = 4
  62.       Visible = True
  63.       PosRelativeToAnchor = []
  64.       PosRelativeToParent = [rpTop]
  65.       LayoutParamWidth = lpHalfOfParent
  66.       LayoutParamHeight = lpWrapContent
  67.       BackgroundColor = colbrSilver
  68.       MinPinchZoomFactor = 0.25
  69.       MaxPinchZoomFactor = 4
  70.       Id = 5672351
  71.       object jButton1: jButton
  72.         Left = 4
  73.         Top = 4
  74.         Width = 132
  75.         Height = 40
  76.         MarginLeft = 2
  77.         MarginTop = 4
  78.         MarginRight = 2
  79.         MarginBottom = 4
  80.         Visible = True
  81.         PosRelativeToAnchor = []
  82.         PosRelativeToParent = [rpCenterInParent]
  83.         LayoutParamWidth = lpMatchParent
  84.         LayoutParamHeight = lpWrapContent
  85.         Text = 'jButton1'
  86.         BackgroundColor = colbrDefault
  87.         FontColor = colbrDefault
  88.         FontSize = 0
  89.         FontSizeUnit = unitDefault
  90.         Id = 0
  91.       end
  92.     end
  93.     object jPanel4: jPanel
  94.       Left = 152
  95.       Top = 4
  96.       Width = 140
  97.       Height = 48
  98.       MarginLeft = 4
  99.       MarginTop = 4
  100.       MarginRight = 4
  101.       MarginBottom = 4
  102.       Visible = True
  103.       Anchor = jPanel3
  104.       PosRelativeToAnchor = [raToRightOf, raAlignBaseline]
  105.       PosRelativeToParent = []
  106.       LayoutParamWidth = lpHalfOfParent
  107.       LayoutParamHeight = lpWrapContent
  108.       BackgroundColor = colbrSilver
  109.       MinPinchZoomFactor = 0.25
  110.       MaxPinchZoomFactor = 4
  111.       Id = 3763529
  112.       object jButton2: jButton
  113.         Left = 4
  114.         Top = 4
  115.         Width = 132
  116.         Height = 40
  117.         MarginLeft = 2
  118.         MarginTop = 4
  119.         MarginRight = 2
  120.         MarginBottom = 4
  121.         Visible = True
  122.         PosRelativeToAnchor = []
  123.         PosRelativeToParent = [rpCenterInParent]
  124.         LayoutParamWidth = lpMatchParent
  125.         LayoutParamHeight = lpWrapContent
  126.         Text = 'jButton2'
  127.         BackgroundColor = colbrDefault
  128.         FontColor = colbrDefault
  129.         FontSize = 0
  130.         FontSizeUnit = unitDefault
  131.         Id = 0
  132.       end
  133.     end
  134.   end
  135. end
  136.  

"Unit1.pas"
Code: Pascal  [Select][+][-]
  1. unit unit1;
  2.  
  3. {$mode delphi}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, And_jni, And_jni_Bridge, Laz_And_Controls,
  9.     Laz_And_Controls_Events, AndroidWidget;
  10.  
  11. type
  12.  
  13.   { TAndroidModule1 }
  14.  
  15.   TAndroidModule1 = class(jForm)
  16.     jButton1: jButton;
  17.     jButton2: jButton;
  18.     jPanel1: jPanel;
  19.     jPanel2: jPanel;
  20.     jPanel3: jPanel;
  21.     jPanel4: jPanel;
  22.     procedure AndroidModule1Rotate(Sender: TObject; rotate: TScreenStyle);
  23.   private
  24.     {private declarations}
  25.   public
  26.     {public declarations}
  27.   end;
  28.  
  29. var
  30.   AndroidModule1: TAndroidModule1;
  31.  
  32. implementation
  33.  
  34. {$R *.lfm}
  35.  
  36.  
  37. { TAndroidModule1 }
  38.  
  39. procedure TAndroidModule1.AndroidModule1Rotate(Sender: TObject;
  40.   rotate: TScreenStyle);
  41. begin
  42.  
  43.   case  rotate of
  44.      ssLandscape:
  45.      begin
  46.  
  47.        jPanel3.LayoutParamWidth:= lpMatchParent;
  48.        jPanel3.PosRelativeToParent:= [rpTop];
  49.  
  50.        jPanel4.LayoutParamWidth:= lpMatchParent;
  51.        jPanel4.PosRelativeToAnchor:= [raBelow];
  52.  
  53.        jPanel1.LayoutParamHeight := lpMatchParent;
  54.        jPanel1.LayoutParamWidth := lpThreeQuarterOfParent;
  55.        jPanel1.PosRelativeToParent := [rpLeft];
  56.  
  57.        jPanel2.LayoutParamHeight := lpMatchParent;
  58.        jPanel2.LayoutParamWidth := lpOneQuarterOfParent;
  59.        jPanel2.PosRelativeToAnchor := [raToRightOf, raAlignBaseline];
  60.  
  61.      end;
  62.      ssPortrait:
  63.      begin
  64.  
  65.        jPanel3.LayoutParamWidth:= lpHalfOfParent;
  66.        jPanel3.PosRelativeToParent:= [rpTop];
  67.  
  68.        jPanel4.LayoutParamWidth:= lpHalfOfParent;
  69.        jPanel4.PosRelativeToAnchor:= [raToRightOf,raAlignBaseline];
  70.  
  71.  
  72.        jPanel1.LayoutParamHeight := lpFourFifthOfParent;
  73.        jPanel1.LayoutParamWidth := lpMatchParent;
  74.        jPanel1.PosRelativeToParent := [rpTop];
  75.  
  76.        jPanel2.LayoutParamHeight := lpOneFifthOfParent;
  77.        jPanel2.LayoutParamWidth := lpMatchParent;
  78.        jPanel2.PosRelativeToAnchor := [raBelow];
  79.  
  80.      end;
  81.   end;
  82.  
  83.   if rotate in [ssLandscape, ssPortrait] then
  84.   begin
  85.  
  86.     jPanel1.ResetAllRules;
  87.     jPanel2.ResetAllRules;
  88.     jPanel3.ResetAllRules;
  89.     jPanel4.ResetAllRules;
  90.  
  91.     Self.UpdateLayout;
  92.   end;
  93.  
  94. end;
  95.  
  96. end.
  97.  
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

tintinux

  • Sr. Member
  • ****
  • Posts: 325
    • Gestinux
Re: How to rotate a Module ?
« Reply #2 on: June 20, 2016, 11:55:51 am »
Hi

Thanks for the idea, it works with each button over it's panel, but it is a little tedious...

Isn't it possible and simpler to make jButton.ResetAllRules a public method ? 

Or maybe even to make public the jVisualControl ancestor method ?

Best regards
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: How to rotate a Module ?
« Reply #3 on: June 21, 2016, 12:10:13 am »

Quote
Isn't it possible and simpler to make jButton.ResetAllRules a public method ? 
Or maybe even to make public the jVisualControl ancestor method ?

Yes!

I will try some improvement to rotate!

Thank you!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018