mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:52:45 +00:00 
			
		
		
		
	LibGUI: Allow disabling the alpha channel in ColorInput widgets
This commit is contained in:
		
							parent
							
								
									17e76b4760
								
							
						
					
					
						commit
						c7107385ee
					
				
					 2 changed files with 19 additions and 1 deletions
				
			
		|  | @ -70,6 +70,19 @@ void ColorInput::set_color(Color color) | ||||||
|     set_text(color.to_string()); |     set_text(color.to_string()); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | void ColorInput::set_color_has_alpha_channel(bool has_alpha) | ||||||
|  | { | ||||||
|  |     if (m_color_has_alpha_channel == has_alpha) | ||||||
|  |         return; | ||||||
|  | 
 | ||||||
|  |     m_color_has_alpha_channel = has_alpha; | ||||||
|  |     m_color.set_alpha(0xff); | ||||||
|  |     if (!has_alpha) | ||||||
|  |         set_text(m_color.to_string_without_alpha()); | ||||||
|  |     else | ||||||
|  |         set_text(m_color.to_string()); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void ColorInput::mousedown_event(MouseEvent& event) | void ColorInput::mousedown_event(MouseEvent& event) | ||||||
| { | { | ||||||
|     if (event.button() == MouseButton::Left) { |     if (event.button() == MouseButton::Left) { | ||||||
|  |  | ||||||
|  | @ -35,9 +35,11 @@ class ColorInput final : public TextEditor { | ||||||
|     C_OBJECT(ColorInput); |     C_OBJECT(ColorInput); | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|     ColorInput(); |  | ||||||
|     virtual ~ColorInput() override; |     virtual ~ColorInput() override; | ||||||
| 
 | 
 | ||||||
|  |     bool has_alpha_channel() const { return m_color_has_alpha_channel; } | ||||||
|  |     void set_color_has_alpha_channel(bool); | ||||||
|  | 
 | ||||||
|     void set_color(Color); |     void set_color(Color); | ||||||
|     Color color() { return m_color; } |     Color color() { return m_color; } | ||||||
| 
 | 
 | ||||||
|  | @ -52,11 +54,14 @@ protected: | ||||||
|     virtual void paint_event(PaintEvent&) override; |     virtual void paint_event(PaintEvent&) override; | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  |     ColorInput(); | ||||||
|  | 
 | ||||||
|     Gfx::Rect color_rect() const; |     Gfx::Rect color_rect() const; | ||||||
|     void set_color_without_changing_text(Color); |     void set_color_without_changing_text(Color); | ||||||
| 
 | 
 | ||||||
|     Color m_color; |     Color m_color; | ||||||
|     String m_color_picker_title { "Select color" }; |     String m_color_picker_title { "Select color" }; | ||||||
|  |     bool m_color_has_alpha_channel { true }; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling