Skip to content

sliderstruct

Thomas edited this page Aug 24, 2020 · 3 revisions

obj_uiZ_sliderstruct

This object is a type of structure but only shows a minimum of frames at a time.
It allows you to create something like a "slideshow" of frames.
There is a (either horizontal or vertical) row of frames that you can put stuff in.
However, it only keeps the visible frames loaded (that normally only 1 frame or 2 frames if an animation is running). Because of this, you will need some extra code that recreates frames that have been unloaded before.

Settings

  • frames[1]: The number of frames your object has. Has to be 0 or higher.
  • updatescript[-1]: What script should be called whenever a new frame needs to be created. This object deletes frames that are not within view. That means objects need to be recreated every time the user switches to a slide. The first argument passed to this script will be the instance id of the slider struct. The second argument can be any custom argument set in updatescriptargument. Set updatescript to -1 for no script. You don't have to set this script, you can also poll for changes in the step event using uiz_sliderstruct_docheck, and then using your own code if that returns any value >= 0.
  • updatescriptargument[0]: An extra argument that can be given to the updatescript. Use this if you needs extra information in your script.
  • animation[uiz_exponential_inout]: The animation used to switch between frames.
  • animationtime[0.25]: The time in seconds the animation used to switch between frames will last.
  • horizontal[true]: True if the frames should switch horizontally and false is they should be vertically stacked on top of each other.
  • mouseslide[true]: Allow the sides to "grab" the frame and swipe it to the next frame.
  • slideonwholeframe[false]: Allow the entire frame to be "grabbed" by the mouse. (Only has effect when mouseslide=true)
  • slidesize[0.3]: How big the areas on the side of the frames should be for "grabbing" the frames. (Only has effect when mouseslide=true and slideonwholeframe=false)
  • slidesizetype[dp]: The type of how big the areas on the side of the frames should be for "grabbing" the frames. (Only has effect when mouseslide=true and slideonwholeframe=false)
  • slidedist[1]: The minimum distance for a swipe to be registered and the frame to move to its new position even after the mouse has been released.
  • slidedisttype[dp]: The type for the minimum distance for a swipe to be registered and the frame to move to its new position even after the mouse has been released.
  • tabslider[0]: Allows you to chain a tabslider object to the sliderstruct. The objects will then react to each other. Leave to 0 for no tabslider.

Readable variables

  • frame: The current frame being shown.
  • dir: The direction the frame is moving. -1 for left/top and 1 for right/bottom.
  • newframe: The newest created frame. (This frame should contain your objects)
  • linearvalue: How far the switch animation is activated. Ranges from 0 to 1.

Functions

  • uiz_sliderstruct_setNumberOfFrames(instanceid, frames):
    • instanceid: the instance id of the instance you want to modify
    • frames[1]: The number of frames your slider has. Has to be 0 or higher.
  • uiz_sliderstruct_setUpdateScript(instanceid, script[-1], argument[0], doImmidiateUpdate): Set a script to be called whenever a new frame is created. This object deletes frames that are not within view. That means objects need to be recreated every time the user switches to a slide. You don't have to set this script, you can also poll for changes in the step event using uiz_sliderstruct_docheck, and then using your own code if that returns any value >= 0.
    • instanceid: the instance id of the instance you want to modify
    • updatescript: What script should be called whenever a new frame needs to be created. The first argument passed to this script will be the instance id of the slider struct. The second argument can be any custom argument set in updatescriptargument. Set updatescript to -1 for no script.
    • updatescriptargument: An extra argument that can be given to the updatescript. Use this if you needs extra information in your script.
    • doImmidiateUpdate: Whether to instantly execute the given script. If there are any objects left within the currently selected frame, these objects will get removed when this is true. I recommend setting this to true if you are calling this function right after creating the sliderstruct. If you set this argument to false, your frame may not get populated.
  • frameid = uiz_sliderstruct_docheck(instance id): This will take any sliderstruct and return -1 if nothing needs to happen and will return the frame number (where 0 is left/top) if a new frame needs to be created. (wont return an instance id). This script should poll every step. See a code sample below. If you want to use a event driven method, you should use the uiz_sliderstruct_setUpdateScript function. I recommend the eventdriven method over this polling method.
    • instanceid: the instance id of the instance you want to modify
  • uiz_sliderstruct_getnewframe(instance id): This returns and instance id of a frame in which objects need to be created. DO NOT MODIFY THIS FRAME ITSELF, it will cause problems. This only returns something valid if uiz_sliderstruct_docheck returns a number above -1.
    • instanceid: the instance id of the instance you want to modify
  • uiz_sliderstruct_setframe(instance id, new frame number): Moves the frame on the slider to a new frame, using an animation.
    • instanceid: the instance id of the instance you want to modify
    • new frame number: what frame to move to. 0 is the most left/top frame. Cannot be equal to or higher than the value of "frames".
  • uiz_sliderstruct_setanimation(instanceid,animation[uiz_exponential_inout],time[0.25]):
    • instanceid: the instance id of the instance you want to modify
    • animation: The animation used to switch between frames.
    • time: The time in seconds the animation used to switch between frames will last.
  • uiz_sliderstruct_setorientation(instanceid,horizonal[true]):
    • instanceid: the instance id of the instance you want to modify
    • horizontal: True if the frames should switch horizontally and false is they should be vertically stacked on top of each other.
  • uiz_sliderstruct_setmouse(instanceid,mouseslide[true],slideonwholeframe[false],slidesize[0.3],slidesizetype[dp],slidedist[1],slidedisttype[dp]):
    • instanceid: the instance id of the instance you want to modify
    • mouseslide: Allow the sides to "grab" the frame and swipe it to the next frame.
    • slideonwholeframe: Allow the entire frame to be "grabbed" by the mouse. (Only has effect when mouseslide=true)
    • slidesize: How big the areas on the side of the frames should be for "grabbing" the frames. (Only has effect when mouseslide=true and slideonwholeframe=false)
    • slidesizetype: The type of how big the areas on the side of the frames should be for "grabbing" the frames. (Only has effect when mouseslide=true and slideonwholeframe=false)
    • slidedist: The minimum distance for a swipe to be registered and the frame to move to its new position even after the mouse has been released.
    • slidedisttype: The type for the minimum distance for a swipe to be registered and the frame to move to its new position even after the mouse has been released.
  • uiz_sliderstruct_settabslider(instanceid,tabslider instanceid[0]):
    • instanceid: the instance id of the instance you want to modify
    • tabslider instanceid[0]: Allows you to chain a tabslider object to the sliderstruct. The objects will then react to each other. Leave to 0 for no tabslider.
  • frame=uiz_sliderstruct_getframe(instanceid):
    • frame: The current frame being shown.
    • instanceid: the instance id of the instance you want to modify

Extra needed code

Because frames are destroyed after switching you will need to create the objects inside of it again. This can be done by using the event driven method or the polling method.

Event driven

///create
sliderstruct=uiz_c(obj_uiZ_sliderstruct);
sliderstruct.posinframex=uiz_fill;
sliderstruct.posinframey=uiz_fill;
uiz_sliderstruct_setNumberOfFrames(sliderstruct,3);
uiz_sliderstruct_setUpdateScript(sliderstruct, scr_slide_reactor_createObjects, 0, true);
uiz_fixgeneralpos(sliderstruct);

///scr_slide_reactor_createObjects
switch(uiz_sliderstruct_getframe(argument0)){
case 0:
    //left frame
    var fr=uiz_sliderstruct_getnewframe(argument0)
    var frameobject=uiz_c(obj_uiZ_rotator)
    uiz_setParent(frameobject,fr)
    frameobject.posinframex=uiz_fill;
    frameobject.posinframey=uiz_fill;
    uiz_fixgeneralpos(frameobject)
break;
case 1:
    //middle frame
    var fr=uiz_sliderstruct_getnewframe(argument0)
    var frameobject=uiz_c(obj_uiZ_loadingcircle)
    uiz_setParent(frameobject,fr)
    frameobject.posinframex=uiz_fill;
    frameobject.posinframey=uiz_fill;
    uiz_fixgeneralpos(frameobject)
break;
case 2:
    //right frame
    var fr=uiz_sliderstruct_getnewframe(argument0)
    var frameobject=uiz_c(obj_uiZ_sprbutton)
    uiz_setParent(frameobject,fr)
    frameobject.posinframex=uiz_fill;
    frameobject.posinframey=uiz_fill;
    uiz_fixgeneralpos(frameobject)
    break;
}

Polling driven

///create
sliderstruct=uiz_c(obj_uiZ_sliderstruct);
sliderstruct.posinframex=uiz_fill;
sliderstruct.posinframey=uiz_fill;
uiz_sliderstruct_setNumberOfFrames(sliderstruct,3);
uiz_fixgeneralpos(sliderstruct);

///step
switch(uiz_sliderstruct_docheck(sliderstruct)){
case -1:

break;
case 0:
    //left frame
    var fr=uiz_sliderstruct_getnewframe(sliderstruct)
    frameobject=uiz_c(obj_uiZ_rotator)
    uiz_setParent(frameobject,fr)
    frameobject.posinframex=uiz_fill;
    frameobject.posinframey=uiz_fill;
    uiz_fixgeneralpos(frameobject)
break;
case 1:
    //middle frame
    var fr=uiz_sliderstruct_getnewframe(sliderstruct)
    frameobject=uiz_c(obj_uiZ_loadingcircle)
    uiz_setParent(frameobject,fr)
    frameobject.posinframex=uiz_fill;
    frameobject.posinframey=uiz_fill;
    uiz_fixgeneralpos(frameobject)
break;
case 2:
    //right frame
    var fr=uiz_sliderstruct_getnewframe(sliderstruct)
    frameobject=uiz_c(obj_uiZ_sprbutton)
    uiz_setParent(frameobject,fr)
    frameobject.posinframex=uiz_fill;
    frameobject.posinframey=uiz_fill;
    uiz_fixgeneralpos(frameobject)
    break;
}

This code uses a simple switch statement controller by a function uiz_sliderstruct_docheck(instance id) which you will need to give the instance id of a sliderstruct.
Also, you will need to use uiz_sliderstruct_getnewframe(instance id) to get the frame that needs objects created in it.
We've got a loose -1 case which gets activated when there is NO update. This has been added extra to prevent conflicts with potential default cases.

Wiki pages

🏑Home / General
πŸ“ƒTutorials
πŸ‘ͺ Parent
↕️ Positioning
πŸ›  Fixing & Updating
πŸ• Depth
πŸ“ƒ Templates and Examples
πŸŒ† Background
πŸ“‡ Structures
🎈 Objects

obj_uiZ_3waybutton
obj_uiZ_button
obj_uiZ_checkbox
obj_uiZ_clock
obj_uiZ_colorbox
obj_uiZ_cover
obj_uiZ_drawdslist obj_uiZ_dropdown
obj_uiZ_easybutton
obj_uiZ_frame
obj_uiZ_framescrollbar
obj_uiZ_functionbar
obj_uiZ_gradientsquare
obj_uiZ_gradientroundrect
obj_uiZ_gridlist
obj_uiZ_huesquare
obj_uiZ_loadingbar
obj_uiZ_loadingcircle
obj_uiZ_menubutton
obj_uiZ_mousemenu
obj_uiZ_radiobox
obj_uiZ_rotator
obj_uiZ_slider
obj_uiZ_scrollbar
obj_uiZ_slider_2col
obj_uiZ_slickslider
obj_uiZ_slideframe
obj_uiZ_sprbutton
obj_uiZ_spriteanimationbutton
obj_uiZ_spritecounter
obj_uiZ_stringbox
obj_uiZ_sliderstruct
obj_uiZ_surfacecanvas
obj_uiZ_sprite
obj_uiZ_square
obj_uiZ_squarebutton
obj_uiZ_swipicon
obj_uiZ_switch
obj_uiZ_tabslider
obj_uiZ_tabs
obj_uiZ_treelist
obj_uiZ_text
obj_uiZ_text_background
obj_uiZ_textarea
obj_uiZ_valuebox


🎈 Your own objects
🚫 Destroy
🐭 Mouse
πŸ’» Windows (uiz)
🌌 Animations
❓ General
πŸ“’ Numbers
πŸ“’ Strings
✏️ Draw
🚩 Popup
πŸ“‚ Files
πŸ’» Windows (os)
Clone this wiki locally