mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 22:02:44 +00:00 
			
		
		
		
	LibGUI: Implement calculated sizes for ValueSlider
This commit is contained in:
		
							parent
							
								
									b6d45f9c1f
								
							
						
					
					
						commit
						caf6dd5680
					
				
					 2 changed files with 27 additions and 2 deletions
				
			
		|  | @ -24,7 +24,7 @@ ValueSlider::ValueSlider(Gfx::Orientation orientation, String suffix) | ||||||
|     // FIXME: Implement vertical mode
 |     // FIXME: Implement vertical mode
 | ||||||
|     VERIFY(orientation == Orientation::Horizontal); |     VERIFY(orientation == Orientation::Horizontal); | ||||||
| 
 | 
 | ||||||
|     set_fixed_height(20); |     set_preferred_size(SpecialDimension::Fit); | ||||||
| 
 | 
 | ||||||
|     m_textbox = add<GUI::TextBox>(); |     m_textbox = add<GUI::TextBox>(); | ||||||
|     m_textbox->set_relative_rect({ 0, 0, 34, 20 }); |     m_textbox->set_relative_rect({ 0, 0, 34, 20 }); | ||||||
|  | @ -119,9 +119,14 @@ Gfx::IntRect ValueSlider::bar_rect() const | ||||||
|     return bar_rect; |     return bar_rect; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | int ValueSlider::knob_length() const | ||||||
|  | { | ||||||
|  |     return m_knob_style == KnobStyle::Wide ? 13 : 7; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| Gfx::IntRect ValueSlider::knob_rect() const | Gfx::IntRect ValueSlider::knob_rect() const | ||||||
| { | { | ||||||
|     int knob_thickness = m_knob_style == KnobStyle::Wide ? 13 : 7; |     int knob_thickness = knob_length(); | ||||||
| 
 | 
 | ||||||
|     Gfx::IntRect knob_rect = bar_rect(); |     Gfx::IntRect knob_rect = bar_rect(); | ||||||
|     knob_rect.set_width(knob_thickness); |     knob_rect.set_width(knob_thickness); | ||||||
|  | @ -202,4 +207,20 @@ void ValueSlider::mouseup_event(MouseEvent& event) | ||||||
|     m_dragging = false; |     m_dragging = false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | Optional<UISize> ValueSlider::calculated_min_size() const | ||||||
|  | { | ||||||
|  |     auto content_min_size = m_textbox->effective_min_size(); | ||||||
|  | 
 | ||||||
|  |     if (orientation() == Gfx::Orientation::Vertical) | ||||||
|  |         return { { content_min_size.width(), content_min_size.height().as_int() + knob_length() } }; | ||||||
|  |     return { { content_min_size.width().as_int() + knob_length(), content_min_size.height() } }; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | Optional<UISize> ValueSlider::calculated_preferred_size() const | ||||||
|  | { | ||||||
|  |     if (orientation() == Gfx::Orientation::Vertical) | ||||||
|  |         return { { SpecialDimension::Shrink, SpecialDimension::OpportunisticGrow } }; | ||||||
|  |     return { { SpecialDimension::OpportunisticGrow, SpecialDimension::Shrink } }; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -43,6 +43,10 @@ private: | ||||||
|     int value_at(Gfx::IntPoint position) const; |     int value_at(Gfx::IntPoint position) const; | ||||||
|     Gfx::IntRect bar_rect() const; |     Gfx::IntRect bar_rect() const; | ||||||
|     Gfx::IntRect knob_rect() const; |     Gfx::IntRect knob_rect() const; | ||||||
|  |     int knob_length() const; | ||||||
|  | 
 | ||||||
|  |     virtual Optional<UISize> calculated_min_size() const override; | ||||||
|  |     virtual Optional<UISize> calculated_preferred_size() const override; | ||||||
| 
 | 
 | ||||||
|     String m_suffix {}; |     String m_suffix {}; | ||||||
|     Orientation m_orientation { Orientation::Horizontal }; |     Orientation m_orientation { Orientation::Horizontal }; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 FrHun
						FrHun