-
Notifications
You must be signed in to change notification settings - Fork 2
tutorial.basic.5
Welcome back to the fifth tutorial already! You should have a decent understanding of how to position your objects. From here on weβll focus on some more complicated stuff. The application for these features might be somewhat unclear at first. But just try to understand all of it, and later on when working with uiz, you will end up using them a ton.
Anyways, today weβll talk about canvases and a little about containment. Letβs get the canvases out the way first.
Canvases are like an empty frames: something to put objects in. They can provide a layer for you to use in your programming. Frames are important if you want to add structure to your ui, without actually placing objects.
Think about the example from tutorial 2 about parenting:
"Another example might be is that you have some sort of square, in which you want to put some health bars, stamina bars, etcβ¦. That square with the different bars could be snapped to the right side of your screen. When we change the size of our window, the square should move with it, but we also want our bars to move with it." βTutorial 2, a while ago.
We could put our health and stamina bar inside a square, but what if we donβt want it inside a visible square? We can use a canvas instead, creating an invisible "square". This way, we can move the bars around just by moving the frame around, without it being visible to the end user.
How do I make a canvas? Easy, canvases are just objects. Just use:
canvas = uiz_c(obj_uiZ_canvas)A canvas is just an object like a square, it just doesnβt really do or draw anything. This doesnβt mean itβs useless though, they are very important to structure in your ui!
EXAMPLE 16:
//create event of a newly created object.
//initialize uiz
uiz_init()
//create our gradientsquare object
canvas=uiz_c(obj_uiZ_canvas)
//our parent is the uiz controller object.
//setup some variables
uiz_position(canvas, 50,px, 50,px);
uiz_size(canvas, 200,px, 200,px);
//fix our canvas object.
uiz_fix(canvas)
//create our square object
square=uiz_c(obj_uiZ_square)
//set the parent
uiz_setParent(square,canvas)
//setup some variables
uiz_position(square, 25,px, 25,px);
uiz_size(square, 40,px, 50,px);
//fix our square object.
uiz_fix(square)Which looks like:
IMAGE 19
Or with given lengths:
IMAGE 20
Using a gradientsquare:
IMAGE 12
Note that the square object in the frame is in the exact same position as the one in the gradientsquare.
What is this? This is some stuff can be your greatest friend and your worst enemy at the same time. It is a feature built into every uiz object and makes sure that that object is never drawn at places where it isnβt supposed to be drawn.
Letβs say we have a window, with some buttons in it. Now the user resizes the window and makes it very small, due to a combination of space restrictions, the use of px or dp values and/or some bad programming practices, the buttons might get stuck outside the window for some reason. This obviously cannot happen, and there would be a few ways to prevent this from happening like setting a minimum size for the window. But there is no way you can prevent this in every single case. So the βcontainmentβ mechanics in uiZ make sure that the button is never drawn outside the window. And example of this can be shown here:
An image where the window is big enough for the button:
IMAGE 21
And, an image where the window is not big enough for the window:
IMAGE 22
In the bottom picture you can see that the button isnβt being drawn outside the window. It is cut off.
No example code will be given for this here, since there hasnβt been any explanation on windows. If you want to see it anyway, look for example 17 in the obj_uiz_basictutorial object.
Technical details: There are 2 ways in which uiz βcontainsβ stuff, the default is using a shader, and the secondary option for when shaders arenβt compatible is using surfaces. Because of uizβs implementation, youβll need to make some workarounds when you are making your own uiZ objects. But you donβt need to worry about that now, you can read all about it in the tutorials showing you how to make your own objects.
This is it for this tutorial, until next time. You learned:
- How canvases work
- That trough containment, object cannot draw outside of their parent.
πTutorials
Basics 1: Basic positioning
Basics 2: Parenting system
Basics 3: Advanced positioning
Basics 4: Advanced sizing and set point
Basics 5: Canvas and containment
Basics 6: Alpha and depth
Basics 7: Using the manual and Animations
Basics 8: Object backgrounds
Basics 9: Grids
Basics 10: Framesets
Basics 11: Windows
Basics 12: Scroll bars
βοΈ Positioning
π Depth
π 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
π Strings
uiz_addChar
uiz_changechar
uiz_charCanHaveAddon
uiz_returnCharAddon
uiz_charIsNumber
uiz_charIsNumberOrText
uiz_getlines
uiz_gettext_contained
uiz_gettextlines_contained
uiz_getValidVariableName
uiz_isSpaceChar
uiz_lastStringChars
uiz_removeChar
uiz_replaceChars_
uiz_string_copy
uiz_string_digits
uiz_string_format
uiz_string_fromReal
uiz_string_real_getFracLength
uiz_string_real_getIntLength
uiz_string_repeat
uiz_string_replace
uiz_string_pos_at
uiz_stringUntilNewline