@@ -45,7 +45,7 @@ def __init__(
4545 self .remove_style_all ()
4646 self .set_flex_flow (lv .FLEX_FLOW .ROW )
4747 self .set_flex_align (lv .FLEX_ALIGN .SPACE_AROUND , lv .FLEX_ALIGN .CENTER , lv .FLEX_ALIGN .CENTER )
48- self .set_size (w , h )
48+ super () .set_size (w , h )
4949 self .set_style_pad_gap (5 , 0 )
5050 self .set_pos (x , y )
5151 self .set_style_text_font (font , lv .PART .MAIN | lv .STATE .DEFAULT )
@@ -80,6 +80,124 @@ def __init__(
8080 self ._btn_inc .add_event_cb (self ._increment_event_cb , lv .EVENT .SHORT_CLICKED , None )
8181 self ._btn_inc .add_event_cb (self ._increment_event_cb , lv .EVENT .LONG_PRESSED_REPEAT , None )
8282
83+ def set_state (self , state : int , value : bool ) -> None :
84+ """Set the state of the spinbox. If ``value`` is True, the state is set; if False, the state is unset.
85+
86+ :param int state: The state to set.
87+ :param bool value: If True, the state is set; if False, the state is unset.
88+ :return: None
89+
90+ UiFlow2 Code Block:
91+
92+ |set_state.png|
93+
94+ MicroPython Code Block:
95+
96+ .. code-block:: python
97+
98+ spinbox_0.set_state(lv.STATE.DISABLED, True)
99+ """
100+ if value :
101+ self ._spinbox .add_state (state )
102+ self ._btn_dec .add_state (state )
103+ self ._btn_inc .add_state (state )
104+ else :
105+ self ._spinbox .remove_state (state )
106+ self ._btn_dec .remove_state (state )
107+ self ._btn_inc .remove_state (state )
108+
109+ def toggle_state (self , state : int ) -> None :
110+ """Toggle the state of the spinbox. If the state is set, it is unset; if not set, it is set.
111+
112+ :param int state: The state to toggle.
113+ :return: None
114+
115+ UiFlow2 Code Block:
116+
117+ |toggle_state.png|
118+
119+ MicroPython Code Block:
120+
121+ .. code-block:: python
122+
123+ spinbox_0.toggle_state(lv.STATE.CHECKED)
124+ """
125+ if self ._spinbox .has_state (state ):
126+ self ._spinbox .remove_state (state )
127+ self ._btn_dec .remove_state (state )
128+ self ._btn_inc .remove_state (state )
129+ else :
130+ self ._spinbox .add_state (state )
131+ self ._btn_dec .add_state (state )
132+ self ._btn_inc .add_state (state )
133+ return
134+
135+ def set_size (self , width : int , height : int ) -> None :
136+ """Set the size of the spinbox.
137+
138+ :param int width: The width of the spinbox.
139+ :param int height: The height of the spinbox.
140+ :return: None
141+
142+ UiFlow2 Code Block:
143+
144+ |set_size.png|
145+
146+ MicroPython Code Block:
147+
148+ .. code-block:: python
149+
150+ spinbox_0.set_size(150, 40)
151+ """
152+ super ().set_size (width , height )
153+ self ._btn_dec .set_size (height , height )
154+ self ._btn_inc .set_size (height , height )
155+ self ._spinbox .set_height (height )
156+ self ._spinbox .set_flex_grow (1 )
157+ self .update_layout ()
158+
159+ def set_width (self , width : int ) -> None :
160+ """Set the width of the spinbox.
161+
162+ :param int width: The width of the spinbox.
163+ :return: None
164+
165+ UiFlow2 Code Block:
166+
167+ |set_width.png|
168+
169+ MicroPython Code Block:
170+
171+ .. code-block:: python
172+
173+ spinbox_0.set_width(180)
174+ """
175+ super ().set_width (width )
176+ self ._spinbox .set_flex_grow (1 )
177+ self .update_layout ()
178+
179+ def set_height (self , height : int ) -> None :
180+ """Set the height of the spinbox.
181+
182+ :param int height: The height of the spinbox.
183+ :return: None
184+
185+ UiFlow2 Code Block:
186+
187+ |set_height.png|
188+
189+ MicroPython Code Block:
190+
191+ .. code-block:: python
192+
193+ spinbox_0.set_height(50)
194+ """
195+ super ().set_height (height )
196+ self ._btn_dec .set_size (height , height )
197+ self ._btn_inc .set_size (height , height )
198+ self ._spinbox .set_height (height )
199+ self .update_layout ()
200+
83201 def _check_value (self , value , min_value , max_value , digit_count , prec ):
84202 if value < min_value or value > max_value :
85203 warnings .warn (f"Value must be between { min_value } and { max_value } ." )
@@ -216,12 +334,12 @@ def set_style_radius(self, radius: int, part: int) -> None:
216334
217335 def _increment_event_cb (self , event_struct ):
218336 event = event_struct .code
219- if event in (lv .EVENT .CLICKED , lv . EVENT . SHORT_CLICKED , lv .EVENT .LONG_PRESSED_REPEAT ):
337+ if event in (lv .EVENT .SHORT_CLICKED , lv .EVENT .LONG_PRESSED_REPEAT ):
220338 self ._spinbox .increment ()
221339
222340 def _decrement_event_cb (self , event_struct ):
223341 event = event_struct .code
224- if event in (lv .EVENT .CLICKED , lv . EVENT . SHORT_CLICKED , lv .EVENT .LONG_PRESSED_REPEAT ):
342+ if event in (lv .EVENT .SHORT_CLICKED , lv .EVENT .LONG_PRESSED_REPEAT ):
225343 self ._spinbox .decrement ()
226344
227345 def set_digit_format (self , digit_count : int , sep_pos : int ) -> None :
@@ -325,6 +443,9 @@ def set_step(self, step: float | int) -> None:
325443 spinbox0.set_step(1)
326444 spinbox0.set_step(0.1)
327445 """
446+ if self ._digit_count - self ._sep_pos == 0 :
447+ warnings .warn (f"No decimal places, step { step } converted to { int (step * 10 )} ." )
448+ step = int (step * 10 )
328449 self ._spinbox .set_step (self .value2raw (step , self ._digit_count , self ._sep_pos ))
329450
330451 @staticmethod
@@ -335,7 +456,7 @@ def value2raw(value: float | int, digit_count: int, sep_pos: int) -> int:
335456 :return: The converted integer value.
336457 :rtype: int
337458 """
338- if sep_pos < 0 or sep_pos >= digit_count :
459+ if sep_pos < 0 or sep_pos > digit_count :
339460 raise ValueError ("sep_pos must be between 0 and digit_count." )
340461
341462 dec_pos = digit_count - sep_pos
@@ -351,7 +472,7 @@ def raw2value(raw: int, digit_count: int, sep_pos: int) -> float | int:
351472 :return: The converted float value.
352473 :rtype: float
353474 """
354- if sep_pos < 0 or sep_pos >= digit_count :
475+ if sep_pos < 0 or sep_pos > digit_count :
355476 raise ValueError ("sep_pos must be between 0 and digit_count." )
356477
357478 if sep_pos == 0 :
0 commit comments