Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation since 06/04/2020 in Posts

  1. 3 points
    A new update is available: IDE: Fix character set that was sent from the internal server RTL: Bug fix to handling resizes when anchor gaps are locked. Improvements to TW3ScrollBox Scrollbars -property can now be changed in Object Inspector The ScrollBox waits properly until it's subcontrols are ready ScrollBars and indicators did not work properly if ForceParent was true Fix bugs in resizing the scrollbox
  2. 2 points
    lynkfs

    styling

    Off topic : there is an interesting effect when putting images on top of images. Take an image and give it a large width and height. Take the same image (same src) and place it on top of the first image, give it same height but say 25% of width and center it. Both images should have object-fit set to 'cover' and reduce opacity of the first one to about 65%. Depending on the image, about 1 in 5 give a passable interesting result doing this, 1 in 50 look amazing. Some examples here. (not optimised for size, so slow loading)
  3. 1 point
    lynkfs

    percentage based positioning

    Percentage based positioning has the advantage of having a 'responsive' page layout with little effort. Responsive in this respect means that page layouts will scale seamlessly on devices which may have slightly different pixel dimensions horizontally and/or vertically. So instead of having an editbox on absolute positioning 100,100,400,35 in pixel terms, it is sometimes easier to define all or some of these in percentages. Conveniently 10%-left is interpreted by the browser as starting on 10% of the viewport width, 10%-top starts at 10% of the viewport height etc. Mixing pixels and percentages works fine too MyEditBox.handle.style.left := '10%'; MyEditBox.handle.style.top := '12px'; //MyEditBox.left := 12; This is all still based on absolute positioning, which is the default in Smart. An alternative approach, with the same outcome, is to define dimensions at runtime based on a formula. MyEditBox.handle.style.left := 'calc(10vw - 20px)' resolves in a left positioning of 10% of the viewport-width minus 20 pixels : 28 pixels on a 480 pixels wide phone Note that the minus sign needs to be enclosed in spaces or this won't work This can be also used to scale f.i. font size depending on device capabilities : MyEditBox.handle.style['font-size'] := 'calc(16px + 1vw)' which has the effect of a font size which grows by 1 pixel for every 100 pixels of viewport width. It can get a bit funny on orientation change an all-percentage example page with some random text and images, based on these principles, looks like this , which scales nicely from mobile to desktop (resize browser window).
  4. 1 point
    lynkfs

    percentage based positioning

    It becomes even more interesting when combining css variables and calc : since .... it has been possible to define css variables, which can be referenced in multiple ways they can even be set/get in pascal/js : get a handle to a stylesheet, or create one on the fly //stylesheet var style := browserapi.document.createElement("STYLE"); browserapi.document.head.appendChild(style); var styleSheet := style.sheet; set a css variable ("--variable-width") and insert into the stylesheet css variable names can be any string but have to start with -- //set initial css variable (width) var s1 := #' :root { --variable-width: 500px; }'; styleSheet.insertRule(s1, 0); retrieve and display css width variable browserapi.window.alert( browserapi.window.getComputedStyle(browserapi.document.documentElement) .getPropertyValue('--variable-width')); set css variable to some value browserapi.document.documentElement.style['--variable-width'] := Memo1.handle.getBoundingClientRect().width; use this variable in a 'calc'ulation Memo1.handle.style['height'] := 'calc(var(--variable-width) * 0.6)'; having a 'width' variable is just an example, maybe a bit contrived. Works fine though. Usually css variables are used for colors etc, and those values which need to be set globally for the whole application.
  5. 1 point
    sibar

    Self.OnRemove error when using TRestCall

    I get an annoying Self.OnRemove error in the console when using the TRestCall class. It doesn't affect t he operation but it floods the console when doing a lot of http calls. Perhaps not a bug, but It would been nice to get it away. Latest 3.9 beta release.
  6. 1 point
    jarto

    mouse position

    Thank you. This is one of the really old demos where lots of code is in TForm1.InitializeObject. When that is done, you run the risk of everything not being initialized when your code runs. Standard fix is to move the code to TForm1.InitializeForm: type TForm1 = class(TW3Form) private {$I 'Form1:intf'} FIsCapture: boolean; function MakeMouseEvent(label: TW3Label; name: string): TMouseEvent; function MouseToStr(shift: TShiftState; x, y: integer; scrXY: TPoint): string; protected procedure InitializeForm; override; procedure InitializeObject; override; end; implementation { TForm1} procedure TForm1.InitializeObject; begin inherited; {$I 'Form1:impl'} end; procedure TForm1.InitializeForm; procedure EndCapture; begin W3pnlSetCapture.Visible := true; W3pnlReleaseCapture.Visible := false; W3Panel2.OnMouseUp := nil; FIsCapture := false; end; begin inherited; OnMouseMove := MakeMouseEvent(W3lblFormCoords, 'Form'); W3Panel1.OnMouseMove := MakeMouseEvent(W3lblPanel1Coords, 'Panel1');
  7. 1 point
    Basically you'll want to add a history entry whenever you change forms. Also make up alias url's for every form. For instance 'Form1' can have an url-alias of 'index.html', 'Form2' an alias of 'bookreviews.html' etc. Every history entry links a Form (from) to an alias (to), see below. There is an old post on this forum (2015), but checking my last project I did this : Put an initial history entry on startup and also initiate the main eventhandler for handling backbutton presses unit Unit1; interface uses Pseudo.CreateForms, // auto-generated unit that creates forms during startup System.Types, SmartCL.System, SmartCL.Components, SmartCL.Forms, SmartCL.Application; type TApplication = class(TW3CustomApplication) procedure ApplicationStarting; reintroduce; end; implementation uses Globals; procedure TApplication.ApplicationStarting; begin browserapi.window.onpopstate := procedure(e:variant) begin CBOnPopState(e); end; browserapi.window.history.pushState(nil,'Form1','index.html'); end; end. Whenever there is a change in form, add an entry to the history object browserapi.window.history.pushState(nil,'Form1','bookreview.html'); //from Form1 to bookreview.html The second parameter (Form1) is the 'from' Smart form-name and the third parameter is the 'to' fake url. Supposing that Form2 in this example handles the bookreviews, then at some stage users will return to Form1, at which time another history entry 'Form2' --> 'index.html' will be added. The handler simply reacts to the history popstate events : Procedure CBOnPopState(e: variant); Begin if (browserapi.window.location.pathname = '/') then GoToForm('Form1'); if (browserapi.window.location.pathname = '/index.html') then GoToForm('Form1'); if (browserapi.window.location.pathname = '/bookreview.html') then GoToForm('Form2'); ... The above is for browser projects, but should work for native android as well
  8. 1 point
    lynkfs

    drag and drop

    I've spend hours to implement a simple drag & drop mechanism, and I've given up. The mechanism is not that difficult, but the browser implementations drive me nuts. The problem is that on different chrome browsers the 'drop' position is off from what it should be. If someone's interested, the code below works flawlessly in the internal ide browser. Executing on win10-latest chrome you'll see a jump in positioning of elements when dropped. I've finally figured out, that the jump-amount is based on where the element has been 'grabbed'. It is zero when grabbing top/left, and half the width of the grabbed element when grabbed bottom/right. Checking up on stack-overflow, there are heaps of references to this problem. Without a workable solution. And posts dating from 6 years ago until recently. One might expect these type of bugs to be resolved in a timespan that long. test-code procedure TForm1.InitializeForm; begin inherited; // this is a good place to initialize components Var Drag : JW3Panel := JW3Panel.Create(self); Drag.SetBounds(50,50,100,100); Drag.handle.style.border := '1px solid silver'; Drag.handle.setAttribute('draggable','true'); Var Drop : JW3Panel := JW3Panel.Create(self); Drop.SetBounds(50,300,400,200); Drop.handle.style.border := '1px solid silver'; Drag.handle.ondragstart := procedure(ev: variant) begin Drop.handle.ondragover := procedure(ev: variant) begin ev.preventDefault(); end; //payload = image.id, mouse-offsetX and mouse-offsetY ev.dataTransfer.setData("text", ev.target.id + ';' + inttostr(ev.offsetX) + ';' + inttostr(ev.offsetY)); ev.dataTransfer.effectAllowed := "copy"; ev.dataTransfer.dropEffect := "copy"; end; Drop.handle.ondrop := procedure(ev: variant) begin ev.preventDefault(); var data := ev.dataTransfer.getData("text"); //split payload into image.id, mouse-offsetX and mouse-offsetY var myarray := StrSplit(data,';'); var target : variant := document.getElementById(myarray[0]); ev.target.appendChild(target); target.style.left := ev.offsetX - StrToInt(MyArray[1]) + "px"; target.style.top := ev.offsetY - StrToInt(MyArray[2]) + "px"; end; end; I've ended up with a mouse-event based drag & drop solution rather than using the html5 based d&d api.
  9. 1 point
    lynkfs

    ionic

    Usually I try to steer away from external frameworks. They seldom provide exactly what is needed and are difficult to modify. An exception may be the ionic framework. It is an open source ui toolkit with some nice elements in it. The good thing is that their components subtly change depending on which platform they are used on. The following code uses 2 Ionic components : a button and an extremely elegant selector var iobutton : TIonicButton := TIonicButton.Create(self); iobutton.setbounds(100,100,100,35); iobutton.color := 'primary'; iobutton.fill := 'outline'; iobutton.caption := 'mybutton'; iobutton.onclick := procedure(sender:TObject) begin showmessage((sender as TIonicButton).caption); end; end); and the selector var iofab : TIonicFab := TIonicFab.Create(self); iofab.setbounds(400,200,56,56); iofab.mainIcon := 'share'; iofab.topIcon := 'logo-vimeo'; iofab.bottomIcon := 'logo-facebook'; iofab.leftIcon := 'logo-instagram'; iofab.rightIcon := 'logo-twitter'; iofab.right.button.onclick := lambda showmessage('twitter'); end; See demo here The code for both the button and the selector component in unit2/3 of this project
  10. 1 point
    lynkfs

    styling

    Looking into this idea a bit further. So the ultimate styler program needs to do this : - read in a theme file - discover the visual components in the theme - and populate them for use - have a canvas where these components can be dropped on - and can be manipulated qua size and position - and have a preview for how it looks in real life Basically this is an exercise in elevating css to its maximum capabilites, without using js (pascal) or html at all in the styling process. A first draft of such a program : The demo theme file contains components for buttons and images, and thus these are displayed on top. These can be dragged onto the canvas and positioned at will. The coordinates are displayed on the right, either in absolute or relative values. The preview icon on the canvas opens up a new live browser window. So far so good. The huge number of atomic css properties per visual component (280) now has been subdivided in 3 chunks : A- those css properties to do with visual design : x (left), y (top), width and height These are displayed on the right B- those css properties which are part of the theme file for this component so if for instance the theme file has a line like this: "theme01.buttons.generic.fontWeight: bold", then this will result in a modifier on the screen, where 'bold' can be changed. <to do> C- the remainder of the 280 css properties (280 minus A minus B). Those are either not important, have passable default values or are only seldomly important for styling of the particular component. <to do> Using components ultimately translates into html. Taking this example : <img class="img" id="Component38" src="images/buttons.jpg" name="button" style="visibility: visible; display: inline-block; position: absolute; overflow: auto; left: 350px; top: 10px; width: 82px; height: 34px; cursor: pointer;"> Styling through css results in modifying the style attribute (.. style="visibility: etc...) Still debating whether the other attributes should be part of the styling process. In the demo above for instance I've assigned the 'src' attribute of images to a random unsplash picture, instead of making it directly editable. Its not a css property after all. Demo here (alpha version)
  11. 1 point
    jorn

    Auto payment for SMS

    Mail received, and mission accomplished 🙂
×
×
  • Create New...