mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:22:44 +00:00 
			
		
		
		
	LibHTML: Add Length and LengthBox classes.
We need a way to represent values that are "auto", so adding a Length class seems like the easiest way to achieve that.
This commit is contained in:
		
							parent
							
								
									a190f67450
								
							
						
					
					
						commit
						33ac0de988
					
				
					 4 changed files with 49 additions and 18 deletions
				
			
		
							
								
								
									
										26
									
								
								LibHTML/CSS/Length.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								LibHTML/CSS/Length.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | |||
| #pragma once | ||||
| 
 | ||||
| class Length { | ||||
| public: | ||||
|     enum class Type { | ||||
|         Auto, | ||||
|         Absolute, | ||||
|     }; | ||||
| 
 | ||||
|     Length() {} | ||||
|     Length(int value, Type type) | ||||
|         : m_type(type) | ||||
|         , m_value(value) | ||||
|     { | ||||
|     } | ||||
|     ~Length() {} | ||||
| 
 | ||||
|     bool is_auto() const { return m_type == Type::Auto; } | ||||
|     bool is_absolute() const { return m_type == Type::Absolute; } | ||||
| 
 | ||||
|     int value() const { return m_value; } | ||||
| 
 | ||||
| private: | ||||
|     Type m_type { Type::Auto }; | ||||
|     int m_value { 0 }; | ||||
| }; | ||||
							
								
								
									
										10
									
								
								LibHTML/CSS/LengthBox.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								LibHTML/CSS/LengthBox.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <LibHTML/CSS/Length.h> | ||||
| 
 | ||||
| struct LengthBox { | ||||
|     Length top; | ||||
|     Length right; | ||||
|     Length bottom; | ||||
|     Length left; | ||||
| }; | ||||
|  | @ -21,10 +21,8 @@ void LayoutBlock::layout() | |||
| 
 | ||||
| void LayoutBlock::compute_width() | ||||
| { | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| void LayoutBlock::compute_height() | ||||
| { | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -1,15 +1,9 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <LibHTML/CSS/LengthBox.h> | ||||
| #include <SharedGraphics/Color.h> | ||||
| #include <SharedGraphics/Size.h> | ||||
| 
 | ||||
| struct Box { | ||||
|     int top { 0 }; | ||||
|     int right { 0 }; | ||||
|     int bottom { 0 }; | ||||
|     int left { 0 }; | ||||
| }; | ||||
| 
 | ||||
| enum FontStyle { | ||||
|     Normal, | ||||
|     Bold, | ||||
|  | @ -23,13 +17,15 @@ public: | |||
|     Color text_color() const { return m_text_color; } | ||||
|     Color background_color() const { return m_background_color; } | ||||
| 
 | ||||
|     Box& offset() { return m_offset; } | ||||
|     Box& margin() { return m_margin; } | ||||
|     Box& padding() { return m_padding; } | ||||
|     LengthBox& offset() { return m_offset; } | ||||
|     LengthBox& margin() { return m_margin; } | ||||
|     LengthBox& padding() { return m_padding; } | ||||
|     LengthBox& border() { return m_border; } | ||||
| 
 | ||||
|     const Box& offset() const { return m_offset; } | ||||
|     const Box& margin() const { return m_margin; } | ||||
|     const Box& padding() const { return m_padding; } | ||||
|     const LengthBox& offset() const { return m_offset; } | ||||
|     const LengthBox& margin() const { return m_margin; } | ||||
|     const LengthBox& padding() const { return m_padding; } | ||||
|     const LengthBox& border() const { return m_border; } | ||||
| 
 | ||||
|     FontStyle font_style() const { return m_font_style; } | ||||
| 
 | ||||
|  | @ -40,9 +36,10 @@ private: | |||
|     Color m_text_color; | ||||
|     Color m_background_color; | ||||
| 
 | ||||
|     Box m_offset; | ||||
|     Box m_margin; | ||||
|     Box m_padding; | ||||
|     LengthBox m_offset; | ||||
|     LengthBox m_margin; | ||||
|     LengthBox m_padding; | ||||
|     LengthBox m_border; | ||||
| 
 | ||||
|     Size m_size; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling