TPresentedScrollBox Doesn't Scroll

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

TPresentedScrollBox Doesn't Scroll

Postby jayden » Fri Aug 28, 2015 10:24 am

Hi,

I am trying to implement a TPresentedScrollBox in my application mainly as it allows us to set whether the bouncing property is true of false. What I am trying to do quite simply is have a row of images horizontally and the user can scroll through them as if there was paging enabled (if it was created in xCode - this will be coded manually), if the image height is outside the viewport then they could scroll down and/or pinch out a bit to make the image fit. Rather than changing the scale of the whole scroll view I have created a hierarchy as follows:

1) Top Level - TPresentedScrollBox Aligned to TAlignLayout::Client
2) TScrollContent (TPresentedScrollBox::Content)
3) A TRectangle (as TPanel isn't style-able)
4) A TImage

When I check the viewport size against the content bounds, the images are off the side of the scrollview and only the first is visible (output below):
Code: Select all
Viewport Size:
Height: 640 | Width: 1018
Content Bounds Size:
Height: 640 | Width: 3600


However, the problem is that *it just wont scroll*! I have tried everything using the Scroll* methods, changing the ViewportPosition but it just doesn't scroll. If anyone could help I would really appreciate it, rather than posting endless code at this point (its below!) I have zipped up the project for anyone to look at.

Project Files: https://www.dropbox.com/sh/badc4qoarf20 ... hTQVa?dl=0

Code: Select all
//Implementation
#include <fmx.h>
#pragma hdrstop

#include "Unit5.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm5 *Form5;
//---------------------------------------------------------------------------
__fastcall TForm5::TForm5(TComponent* Owner)
   : TForm(Owner)
{

}
//---------------------------------------------------------------------------
void __fastcall TForm5::createPresentedScrollBoxClick(TObject *Sender)
{
   float contentWidth = scrollBox->Height * 4;
   TRectF contentSize = TRectF(TPointF(scrollBox->Position->X, scrollBox->Position->Y), contentWidth ,scrollBox->Height);
//   scrollBox->ContentBounds = contentSize;

   #ifdef TARGET_OS_MAC
      static String path = UTF8ToString(TNSBundle::Wrap(TNSBundle::OCClass->mainBundle())->bundlePath()->UTF8String());
      #ifndef TARGET_OS_IPHONE
         static String bundlePath = System::Ioutils::TPath::Combine(path, "Contents/MacOS");
      #else
      static String bundlePath = path;
      #endif
   #else
      static String bundlePath =  System::Ioutils::TPath::GetLibraryPath();
    Memo1->Lines->Add("Bundle Path: " + bundlePath);
   #endif
   TFlowLayout *fl = new TFlowLayout(scrollBox);
   fl->FlowDirection = TFlowDirection::LeftToRight;
   fl->Align = TAlignLayout::Contents;

   for (int i = 1; i < 5; i++) {
      TRectangle *rc = new TRectangle(NULL);
      rc->Align = TAlignLayout::Left;
      rc->Height = 1232;
      rc->Width = 900;
      rc->Fill->Kind = TBrushKind::Solid;
      rc->Fill->Color = TAlphaColor(claGreen);
      rc->Stroke->Kind = TBrushKind::Solid;
      rc->Stroke->Color = TAlphaColor(claRed);


      TImage *tmpImage = new TImage(scrollBox);
      tmpImage->Bitmap->LoadFromFile(System::Ioutils::TPath::Combine(bundlePath, IntToStr(i) + ".jpeg"));
      tmpImage->Height = 1232;
      tmpImage->Width = 900;
      tmpImage->Parent = rc;
      scrollBox->AddObject(rc);
   }
   this->scrollBox->UpdateContentSize();
  this->scrollBox->RealignContent();
}

void __fastcall TForm5::scrollBoxClicked(TObject *Sender)
{
 int a = {
    1+2
 };
}
//---------------------------------------------------------------------------
void __fastcall TForm5::Button1Click(TObject *Sender)
{

   TPointF vp = scrollBox->ViewportPosition;
   TSizeF vps = scrollBox->ViewportSize;
   TRectF cb = scrollBox->ContentBounds;

   Memo1->Lines->Add("Viewport Position:");
   Memo1->Lines->Add("X: " + FloatToStr(vp.X) + " | Y: " + FloatToStr(vp.Y));
   Memo1->Lines->Add("Viewport Size:");
   Memo1->Lines->Add("Height: " + FloatToStr(vps.Height) + " | Width: " + FloatToStr(vps.Width));
   Memo1->Lines->Add("Content Bounds Size:");
   Memo1->Lines->Add("Height: " + FloatToStr(cb.Height()) + " | Width: " + FloatToStr(cb.Width()));
}
//---------------------------------------------------------------------------

void __fastcall TForm5::scrollLeftClick(TObject *Sender)
{
//   TPosition *secondPage = scrollBox->Content->Children;
   TFmxChildrenList *sc = scrollBox->Content->Children;
   TPosition *secondPage = dynamic_cast<TRectangle *>(sc->Items[1])->Position;
   scrollBox->ViewportPosition = TPointF(secondPage->X, secondPage->Y);
}
//---------------------------------------------------------------------------

void __fastcall TForm5::scrollRightClick(TObject *Sender)
{
  scrollBox->ScrollBy(200,100, true);
}
//---------------------------------------------------------------------------

void __fastcall TForm5::FormShow(TObject *Sender)
{
   scrollBox = new TPresentedScrollBox(Form5);
   scrollBox->Parent = Form5;
   scrollBox->Align = TAlignLayout::Client;
   scrollBox->AutoCalculateContentSize = true;
   scrollBox->ScrollAnimation = Fmx::Behaviormanager::TBehaviorBoolean::True;
   scrollBox->ShowScrollBars = true;
   scrollBox->ShowSizeGrip = true;
   scrollBox->EnabledScroll = true;
   scrollBox->Bounces = Fmx::Behaviormanager::TBehaviorBoolean::True;
}
//---------------------------------------------------------------------------

void __fastcall TForm5::Button2Click(TObject *Sender)
{
   TScrollContentSize *cs = scrollBox->ContentSize;
   ShowMessage("Content Is: H" + FloatToStr(cs->Height) + " | W" + FloatToStr(cs->Width));
  scrollBox->ScrollToCenter(true);
}
//---------------------------------------------------------------------------
jayden
Active Poster
Active Poster
 
Posts: 24
Joined: Fri Aug 21, 2015 3:41 pm

Re: TPresentedScrollBox Doesn't Scroll

Postby jayden » Mon Aug 31, 2015 3:57 pm

Can anyone assist?
jayden
Active Poster
Active Poster
 
Posts: 24
Joined: Fri Aug 21, 2015 3:41 pm

Re: TPresentedScrollBox Doesn't Scroll

Postby smd » Mon Aug 31, 2015 6:11 pm

which version of software are you using?
-----------------------------
Scott
smd
BCBJ Guru
BCBJ Guru
 
Posts: 130
Joined: Sat Nov 29, 2014 8:02 pm
Location: Las Vegas

Re: TPresentedScrollBox Doesn't Scroll

Postby jayden » Tue Sep 01, 2015 5:17 am

XE8.

Thanks,
Jayden
jayden
Active Poster
Active Poster
 
Posts: 24
Joined: Fri Aug 21, 2015 3:41 pm

Re: TPresentedScrollBox Doesn't Scroll

Postby smd » Thu Sep 03, 2015 10:19 pm

I just updated to XE10. A couple of programs that worked just fine under XE8, are having the same scrolling issues you describe. It is happening with several different component, the only common thing is moving the scroll bars the text does not move. The scroll button jerkily changes position as I slide it, but the text does not change until I click on some text and do a different operation. Frankly I am stumped, but am still investigating.
-----------------------------
Scott
smd
BCBJ Guru
BCBJ Guru
 
Posts: 130
Joined: Sat Nov 29, 2014 8:02 pm
Location: Las Vegas

Re: TPresentedScrollBox Doesn't Scroll

Postby jayden » Fri Sep 04, 2015 7:02 am

Hi Smd,

Theres now a TPresentedScrollBox component you can drop in at design time. Depending on the device I set the control type to Platform (Windows is styled as the behaviour is the opposite to OSX/iOS/Android). But with the previous code it is now working.

Jayden
jayden
Active Poster
Active Poster
 
Posts: 24
Joined: Fri Aug 21, 2015 3:41 pm


Return to Technical

Who is online

Users browsing this forum: No registered users and 8 guests

cron