@@ -1,33 +0,0 @@
|
||||
#
|
||||
# Demonstrate how scrolling appears automatically
|
||||
#
|
||||
# Create an object with the new style
|
||||
panel = lv.obj(lv.screen_active())
|
||||
panel.set_size(200, 200)
|
||||
panel.center()
|
||||
|
||||
child = lv.obj(panel)
|
||||
child.set_pos(0, 0);
|
||||
child.set_size(70, 70)
|
||||
label = lv.label(child)
|
||||
label.set_text("Zero")
|
||||
label.center()
|
||||
|
||||
child = lv.obj(panel)
|
||||
child.set_pos(160, 80)
|
||||
child.set_size(80, 80)
|
||||
|
||||
child2 = lv.button(child)
|
||||
child2.set_size(100, 50)
|
||||
|
||||
label = lv.label(child2)
|
||||
label.set_text("Right")
|
||||
label.center()
|
||||
|
||||
child = lv.obj(panel)
|
||||
child.set_pos(40, 160)
|
||||
child.set_size(100, 70)
|
||||
label = lv.label(child)
|
||||
label.set_text("Bottom")
|
||||
label.center()
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
def sw_event_cb(e,panel):
|
||||
|
||||
code = e.get_code()
|
||||
sw = e.get_target_obj()
|
||||
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
|
||||
if sw.has_state(lv.STATE.CHECKED):
|
||||
panel.add_flag(lv.obj.FLAG.SCROLL_ONE)
|
||||
else:
|
||||
panel.remove_flag(lv.obj.FLAG.SCROLL_ONE)
|
||||
|
||||
|
||||
#
|
||||
# Show an example to scroll snap
|
||||
#
|
||||
|
||||
panel = lv.obj(lv.screen_active())
|
||||
panel.set_size(280, 150)
|
||||
panel.set_scroll_snap_x(lv.SCROLL_SNAP.CENTER)
|
||||
panel.set_flex_flow(lv.FLEX_FLOW.ROW)
|
||||
panel.center()
|
||||
|
||||
for i in range(10):
|
||||
button = lv.button(panel)
|
||||
button.set_size(150, 100)
|
||||
|
||||
label = lv.label(button)
|
||||
if i == 3:
|
||||
label.set_text("Panel {:d}\nno snap".format(i))
|
||||
button.remove_flag(lv.obj.FLAG.SNAPPABLE)
|
||||
else:
|
||||
label.set_text("Panel {:d}".format(i))
|
||||
label.center()
|
||||
|
||||
panel.update_snap(lv.ANIM.ON)
|
||||
|
||||
|
||||
# Switch between "One scroll" and "Normal scroll" mode
|
||||
sw = lv.switch(lv.screen_active())
|
||||
sw.align(lv.ALIGN.TOP_RIGHT, -20, 10)
|
||||
sw.add_event_cb(lambda evt: sw_event_cb(evt,panel), lv.EVENT.ALL, None)
|
||||
label = lv.label(lv.screen_active())
|
||||
label.set_text("One scroll")
|
||||
label.align_to(sw, lv.ALIGN.OUT_BOTTOM_MID, 0, 5)
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
class ScrollExample_3():
|
||||
def __init__(self):
|
||||
self.button_cnt = 1
|
||||
#
|
||||
# Create a list with a floating button
|
||||
#
|
||||
|
||||
list = lv.list(lv.screen_active())
|
||||
list.set_size(280, 220)
|
||||
list.center()
|
||||
|
||||
for button_cnt in range(2):
|
||||
list.add_button(lv.SYMBOL.AUDIO,"Track {:d}".format(button_cnt))
|
||||
|
||||
float_button = lv.button(list)
|
||||
float_button.set_size(50, 50)
|
||||
float_button.add_flag(lv.obj.FLAG.FLOATING)
|
||||
float_button.align(lv.ALIGN.BOTTOM_RIGHT, 0, -list.get_style_pad_right(lv.PART.MAIN))
|
||||
float_button.add_event_cb(lambda evt: self.float_button_event_cb(evt,list), lv.EVENT.ALL, None)
|
||||
float_button.set_style_radius(lv.RADIUS_CIRCLE, 0)
|
||||
float_button.set_style_bg_image_src(lv.SYMBOL.PLUS, 0)
|
||||
float_button.set_style_text_font(lv.theme_get_font_large(float_button), 0)
|
||||
|
||||
def float_button_event_cb(self,e,list):
|
||||
code = e.get_code()
|
||||
float_button = e.get_target_obj()
|
||||
|
||||
if code == lv.EVENT.CLICKED:
|
||||
list_button = list.add_button(lv.SYMBOL.AUDIO, "Track {:d}".format(self.button_cnt))
|
||||
self.button_cnt += 1
|
||||
|
||||
float_button.move_foreground()
|
||||
|
||||
list_button.scroll_to_view(lv.ANIM.ON)
|
||||
|
||||
scroll_example_3 = ScrollExample_3()
|
||||
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
#
|
||||
# Styling the scrollbars
|
||||
#
|
||||
obj = lv.obj(lv.screen_active())
|
||||
obj.set_size(200, 100)
|
||||
obj.center()
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text(
|
||||
"""
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
||||
Etiam dictum, tortor vestibulum lacinia laoreet, mi neque consectetur neque, vel mattis odio dolor egestas ligula.
|
||||
Sed vestibulum sapien nulla, id convallis ex porttitor nec.
|
||||
Duis et massa eu libero accumsan faucibus a in arcu.
|
||||
Ut pulvinar odio lorem, vel tempus turpis condimentum quis. Nam consectetur condimentum sem in auctor.
|
||||
Sed nisl augue, venenatis in blandit et, gravida ac tortor.
|
||||
Etiam dapibus elementum suscipit.
|
||||
Proin mollis sollicitudin convallis.
|
||||
Integer dapibus tempus arcu nec viverra.
|
||||
Donec molestie nulla enim, eu interdum velit placerat quis.
|
||||
Donec id efficitur risus, at molestie turpis.
|
||||
Suspendisse vestibulum consectetur nunc ut commodo.
|
||||
Fusce molestie rhoncus nisi sit amet tincidunt.
|
||||
Suspendisse a nunc ut magna ornare volutpat.
|
||||
""")
|
||||
|
||||
|
||||
# Remove the style of scrollbar to have clean start
|
||||
obj.remove_style(None, lv.PART.SCROLLBAR | lv.STATE.ANY)
|
||||
|
||||
# Create a transition the animate the some properties on state change
|
||||
props = [lv.STYLE.BG_OPA, lv.STYLE.WIDTH, 0]
|
||||
trans = lv.style_transition_dsc_t()
|
||||
trans.init(props, lv.anim_t.path_linear, 200, 0, None)
|
||||
|
||||
# Create a style for the scrollbars
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
style.set_width(4) # Width of the scrollbar
|
||||
style.set_pad_right(5) # Space from the parallel side
|
||||
style.set_pad_top(5) # Space from the perpendicular side
|
||||
|
||||
style.set_radius(2)
|
||||
style.set_bg_opa(lv.OPA._70)
|
||||
style.set_bg_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_border_color(lv.palette_darken(lv.PALETTE.BLUE, 3))
|
||||
style.set_border_width(2)
|
||||
style.set_shadow_width(8)
|
||||
style.set_shadow_spread(2)
|
||||
style.set_shadow_color(lv.palette_darken(lv.PALETTE.BLUE, 1))
|
||||
|
||||
style.set_transition(trans)
|
||||
|
||||
# Make the scrollbars wider and use 100% opacity when scrolled
|
||||
style_scrolled = lv.style_t()
|
||||
style_scrolled.init()
|
||||
style_scrolled.set_width(8)
|
||||
style_scrolled.set_bg_opa(lv.OPA.COVER)
|
||||
|
||||
obj.add_style(style, lv.PART.SCROLLBAR)
|
||||
obj.add_style(style_scrolled, lv.PART.SCROLLBAR | lv.STATE.SCROLLED)
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
#
|
||||
# Scrolling with Right To Left base direction
|
||||
#
|
||||
obj = lv.obj(lv.screen_active())
|
||||
obj.set_style_base_dir(lv.BASE_DIR.RTL, 0)
|
||||
obj.set_size(200, 100)
|
||||
obj.center()
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text("میکروکُنترولر (به انگلیسی: Microcontroller) گونهای ریزپردازنده است که دارای حافظهٔ دسترسی تصادفی (RAM) و حافظهٔ فقطخواندنی (ROM)، تایمر، پورتهای ورودی و خروجی (I/O) و درگاه ترتیبی (Serial Port پورت سریال)، درون خود تراشه است، و میتواند به تنهایی ابزارهای دیگر را کنترل کند. به عبارت دیگر یک میکروکنترلر، مدار مجتمع کوچکی است که از یک CPU کوچک و اجزای دیگری مانند تایمر، درگاههای ورودی و خروجی آنالوگ و دیجیتال و حافظه تشکیل شدهاست.")
|
||||
label.set_width(400)
|
||||
label.set_style_text_font(lv.font_dejavu_16_persian_hebrew, 0)
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
def scroll_event_cb(e):
|
||||
|
||||
cont = e.get_target_obj()
|
||||
|
||||
cont_a = lv.area_t()
|
||||
cont.get_coords(cont_a)
|
||||
cont_y_center = cont_a.y1 + cont_a.get_height() // 2
|
||||
|
||||
r = cont.get_height() * 7 // 10
|
||||
|
||||
child_cnt = cont.get_child_count()
|
||||
for i in range(child_cnt):
|
||||
child = cont.get_child(i)
|
||||
child_a = lv.area_t()
|
||||
child.get_coords(child_a)
|
||||
|
||||
child_y_center = child_a.y1 + child_a.get_height() // 2
|
||||
|
||||
diff_y = child_y_center - cont_y_center
|
||||
diff_y = abs(diff_y)
|
||||
|
||||
# Get the x of diff_y on a circle.
|
||||
|
||||
# If diff_y is out of the circle use the last point of the circle (the radius)
|
||||
if diff_y >= r:
|
||||
x = r
|
||||
else:
|
||||
# Use Pythagoras theorem to get x from radius and y
|
||||
x_sqr = r * r - diff_y * diff_y
|
||||
res = lv.sqrt_res_t()
|
||||
lv.sqrt(x_sqr, res, 0x8000) # Use lvgl's built in sqrt root function
|
||||
x = r - res.i
|
||||
|
||||
# Translate the item by the calculated X coordinate
|
||||
child.set_style_translate_x(x, 0)
|
||||
|
||||
# Use some opacity with larger translations
|
||||
opa = lv.map(x, 0, r, lv.OPA.TRANSP, lv.OPA.COVER)
|
||||
child.set_style_opa(lv.OPA.COVER - opa, 0)
|
||||
|
||||
#
|
||||
# Translate the object as they scroll
|
||||
#
|
||||
|
||||
cont = lv.obj(lv.screen_active())
|
||||
cont.set_size(200, 200)
|
||||
cont.center()
|
||||
cont.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
||||
cont.add_event_cb(scroll_event_cb, lv.EVENT.SCROLL, None)
|
||||
cont.set_style_radius(lv.RADIUS_CIRCLE, 0)
|
||||
cont.set_style_clip_corner(True, 0)
|
||||
cont.set_scroll_dir(lv.DIR.VER)
|
||||
cont.set_scroll_snap_y(lv.SCROLL_SNAP.CENTER)
|
||||
cont.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
|
||||
|
||||
for i in range(20):
|
||||
button = lv.button(cont)
|
||||
button.set_width(lv.pct(100))
|
||||
|
||||
label = lv.label(button)
|
||||
label.set_text("Button " + str(i))
|
||||
|
||||
# Update the buttons position manually for first*
|
||||
cont.send_event(lv.EVENT.SCROLL, None)
|
||||
|
||||
# Be sure the fist button is in the middle
|
||||
#lv.obj.scroll_to_view(cont.get_child(0), lv.ANIM.OFF)
|
||||
cont.get_child(0).scroll_to_view(lv.ANIM.OFF)
|
||||
Reference in New Issue
Block a user